-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: platform_transition_filegroup #55
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- Generated with Stardoc: http://skydoc.bazel.build --> | ||
|
||
Rules for working with transitions. | ||
|
||
<a id="#platform_transition_filegroup"></a> | ||
|
||
## platform_transition_filegroup | ||
|
||
<pre> | ||
platform_transition_filegroup(<a href="#platform_transition_filegroup-name">name</a>, <a href="#platform_transition_filegroup-srcs">srcs</a>, <a href="#platform_transition_filegroup-target_platform">target_platform</a>) | ||
</pre> | ||
|
||
Transitions the srcs to use the provided platform. The filegroup will contain artifacts for the target platform. | ||
|
||
**ATTRIBUTES** | ||
|
||
|
||
| Name | Description | Type | Mandatory | Default | | ||
| :------------- | :------------- | :------------- | :------------- | :------------- | | ||
| <a id="platform_transition_filegroup-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | | | ||
| <a id="platform_transition_filegroup-srcs"></a>srcs | The input to be transitioned to the target platform. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | | ||
| <a id="platform_transition_filegroup-target_platform"></a>target_platform | The target platform to transition the srcs. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"Rules for working with transitions." | ||
|
||
def _transition_platform_impl(_, attr): | ||
return {"//command_line_option:platforms": str(attr.target_platform)} | ||
|
||
# Transition from any input configuration to one that includes the | ||
# --platforms command-line flag. | ||
_transition_platform = transition( | ||
implementation = _transition_platform_impl, | ||
inputs = [], | ||
outputs = ["//command_line_option:platforms"], | ||
) | ||
|
||
def _platform_transition_filegroup_impl(ctx): | ||
files = [] | ||
runfiles = ctx.runfiles() | ||
for src in ctx.attr.srcs: | ||
files.append(src[DefaultInfo].files) | ||
|
||
runfiles = runfiles.merge_all([src[DefaultInfo].default_runfiles for src in ctx.attr.srcs]) | ||
return [DefaultInfo( | ||
files = depset(transitive = files), | ||
runfiles = runfiles, | ||
)] | ||
|
||
platform_transition_filegroup = rule( | ||
_platform_transition_filegroup_impl, | ||
attrs = { | ||
# Required to Opt-in to the transitions feature. | ||
"_allowlist_function_transition": attr.label( | ||
default = "@bazel_tools//tools/allowlists/function_transition_allowlist", | ||
), | ||
"target_platform": attr.label( | ||
doc = "The target platform to transition the srcs.", | ||
mandatory = True, | ||
), | ||
"srcs": attr.label_list( | ||
allow_empty = False, | ||
cfg = _transition_platform, | ||
doc = "The input to be transitioned to the target platform.", | ||
), | ||
}, | ||
doc = "Transitions the srcs to use the provided platform. The filegroup will contain artifacts for the target platform.", | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this comment for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without it, running Gazelle in this repo removes the file.
Gazelle seems to have some (new?) heuristics for avoiding "test code" being included, so files ending with "_test.bzl" are a problem. I had to totally revert the changes Gazelle makes to the lib/private/BUILD.bazel file where it removes a bunch...