|
| 1 | +"Rules for working with transitions." |
| 2 | + |
| 3 | +def _transition_platform_impl(_, attr): |
| 4 | + return {"//command_line_option:platforms": str(attr.target_platform)} |
| 5 | + |
| 6 | +# Transition from any input configuration to one that includes the |
| 7 | +# --platforms command-line flag. |
| 8 | +_transition_platform = transition( |
| 9 | + implementation = _transition_platform_impl, |
| 10 | + inputs = [], |
| 11 | + outputs = ["//command_line_option:platforms"], |
| 12 | +) |
| 13 | + |
| 14 | +def _platform_transition_filegroup_impl(ctx): |
| 15 | + files = [] |
| 16 | + runfiles = ctx.runfiles() |
| 17 | + for src in ctx.attr.srcs: |
| 18 | + files.append(src[DefaultInfo].files) |
| 19 | + |
| 20 | + runfiles = runfiles.merge_all([src[DefaultInfo].default_runfiles for src in ctx.attr.srcs]) |
| 21 | + return [DefaultInfo( |
| 22 | + files = depset(transitive = files), |
| 23 | + runfiles = runfiles, |
| 24 | + )] |
| 25 | + |
| 26 | +platform_transition_filegroup = rule( |
| 27 | + _platform_transition_filegroup_impl, |
| 28 | + attrs = { |
| 29 | + # Required to Opt-in to the transitions feature. |
| 30 | + "_allowlist_function_transition": attr.label( |
| 31 | + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", |
| 32 | + ), |
| 33 | + "target_platform": attr.label( |
| 34 | + doc = "The target platform to transition the srcs.", |
| 35 | + mandatory = True, |
| 36 | + ), |
| 37 | + "srcs": attr.label_list( |
| 38 | + allow_empty = False, |
| 39 | + cfg = _transition_platform, |
| 40 | + doc = "The input to be transitioned to the target platform.", |
| 41 | + ), |
| 42 | + }, |
| 43 | + doc = "Transitions the srcs to use the provided platform. The filegroup will contain artifacts for the target platform.", |
| 44 | +) |
0 commit comments