From f52976220cfb4a94c862df4d8fb0aa30c900b583 Mon Sep 17 00:00:00 2001 From: Greg Estren Date: Thu, 14 Jul 2016 16:32:44 +0000 Subject: Build encyclopedia: mark attributes that don't work with select() as "nonconfigurable", polish up general configurable attributes docs. -- MOS_MIGRATED_REVID=127440164 --- .../build/docgen/RuleDocumentationAttribute.java | 1 + .../docgen/templates/be/common-definitions.vm | 41 ++++++++++++++++++++-- .../build/docgen/templates/be/functions.vm | 10 +++--- 3 files changed, 45 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/google/devtools/build/docgen') diff --git a/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java b/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java index fa53ca80e6..02357ff3f6 100644 --- a/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java +++ b/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java @@ -180,6 +180,7 @@ public class RuleDocumentationAttribute implements ComparableConfigurable attributes

- Most rule attributes can be "configured" so their values depend on Bazel - command-line flags. This can be used, for example, to declare + Most attributes can be "configured" so their values depend on the flags passed + at the command line. This can be used, for example, to declare platform-dependent srcs or custom compiler flags depending on the compilation mode.

+

Example

+ +
+cc_library(
+    name = "multiplatform_lib",
+    srcs = select({
+        ":x86_mode": ["x86_impl.cc"],
+        ":arm_mode": ["arm_impl.cc"]
+    })
+)
+config_setting(
+    name = "x86_mode",
+    values = { "cpu": "x86" }
+)
+config_setting(
+    name = "arm_mode",
+    values = { "cpu": "arm" }
+)
+
+ +

+ An attribute is made configurable by assigning it to a select. + This makes its value depend on which config_setting matches + the build. For example, bazel build :multiplatform_lib --cpu=arm + sets multiplatform_lib's srcs to + ["arm_impl.cc"], while bazel build :multiplatform_lib + --cpu=x86 sets srcs to ["x86_impl.cc"]. +

+ +

+ See the definitions of + select and + config_setting for more details. + Attributes marked nonconfigurable in their documentation cannot + use this feature (usually because Bazel has to know their values before flags + have been parsed). +

Implicit output targets

diff --git a/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm b/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm index 3bea6a4c26..780716cfe1 100644 --- a/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm +++ b/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm @@ -589,10 +589,9 @@ $ bazel query '//foo:all' | sort
select({conditionA: valuesA, conditionB: valuesB, ...})
-

select() is the helper function that makes an - attribute for a - rule configurable. It can - replace the right-hand side of +

select() is the helper function that makes a rule attribute + configurable. + It can replace the right-hand side of almost any attribute assignment so that the attribute's value depends on the @@ -648,7 +647,8 @@ sh_binary( srcs = select({ ":conditionA": ["a.sh"]}) + select({ ":conditionB": ["b.sh"]}) are valid expressions. -

  • select works with most, but not all, attributes. +
  • select works with most, but not all, attributes. Incompatible + attributes are marked nonconfigurable in their documentation.
  • -- cgit v1.2.3