diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java index 21f29db268b456..3f7a62cb9be383 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java @@ -166,6 +166,69 @@ public Metadata getMetadata() { ) +
+ Platforms may use the flags
attribute to specify a list of flags that will be added
+ to the configuration whenever the platform is used as the target platform (i.e., as the value of
+ the --platforms
flag).
+
+ Flags set from the platform effectively have the highest precedence and overwrite any previous + value for that flag, from the command line, rc file, or transition. +
+ ++platform( + name = "foo", + flags = [ + "--dynamic_mode=fully", + "--//bool_flag", + "--no//package:other_bool_flag", + ], +) ++ +
+ This defines a platform named foo
. When this is the target platform (either because
+ the user specified --platforms//:foo
, because a transition set the
+ //command_line_option:platforms
flag to ["//:foo"]
, or because
+ //:foo
was used as an execution platform), then the given flags will be set in the
+ configuration.
+
+ Some flags will accumulate values when they are repeated, such as --features
,
+ --copt
, any Starlark flag created as config.string(repeatable = True)
.
+ These flags are not compatible with setting the flags from the platform: instead, all previous
+ values will be removed and overwritten with the values from the platform.
+
+ As an example, given the following platform, the invocation build --platforms=//:repeat_demo
+ --features feature_a --features feature_b
will end up with the value of the
+ --feature
flag being ["feature_c", "feature_d"]
, removing the features
+ set on the command line.
+
+platform( + name = "repeat_demo", + flags = [ + "--features=feature_c", + "--features=feature_d", + ], +) ++ +
+ For this reason, it is discouraged to use repeatable flags in the flags
attribute.
+
Platforms may use the parents
attribute to specify another platform that they will