aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--site/docs/skylark/cookbook.md4
-rw-r--r--site/docs/skylark/rules.md6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java19
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java16
5 files changed, 48 insertions, 15 deletions
diff --git a/site/docs/skylark/cookbook.md b/site/docs/skylark/cookbook.md
index 3a5430a29d..e243396b53 100644
--- a/site/docs/skylark/cookbook.md
+++ b/site/docs/skylark/cookbook.md
@@ -438,7 +438,7 @@ def _impl(ctx):
execute = rule(
implementation=_impl,
attrs={
- "binary": attr.label(cfg=HOST_CFG, mandatory=True, allow_files=True,
+ "binary": attr.label(cfg="host", mandatory=True, allow_files=True,
executable=True),
"input_content": attr.string(),
"out": attr.output(mandatory=True),
@@ -497,7 +497,7 @@ execute = rule(
executable=True,
attrs={
"command": attr.string(),
- "data": attr.label_list(cfg=DATA_CFG, allow_files=True),
+ "data": attr.label_list(cfg="data", allow_files=True),
},
)
```
diff --git a/site/docs/skylark/rules.md b/site/docs/skylark/rules.md
index 860dce7ff4..34c9cda336 100644
--- a/site/docs/skylark/rules.md
+++ b/site/docs/skylark/rules.md
@@ -260,11 +260,11 @@ In general, sources, dependent libraries, and executables that will be needed at
runtime can use the same configuration.
Tools that are executed as part of the build (e.g., compilers, code generators)
-should be built for the host configuration. In this case, specify `cfg=HOST_CFG`
+should be built for the host configuration. In this case, specify `cfg="host"`
in the attribute.
-`DATA_CFG` is present for legacy reasons and should be used for `data`
-attributes.
+The configuration `"data"` is present for legacy reasons and should be used for
+the `data` attributes.
## <a name="fragments"></a> Configuration Fragments
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
index 5b0fd57988..b1e627de80 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
@@ -87,7 +87,7 @@ public final class SkylarkAttr {
private static final String CONFIGURATION_ARG = "cfg";
private static final String CONFIGURATION_DOC =
- "configuration of the attribute. For example, use DATA_CFG or HOST_CFG.";
+ "configuration of the attribute. It can be either \"data\" or \"host\".";
private static final String DEFAULT_ARG = "default";
private static final String DEFAULT_DOC = "the default value of the attribute.";
@@ -219,7 +219,17 @@ public final class SkylarkAttr {
}
if (containsNonNoneKey(arguments, CONFIGURATION_ARG)) {
- builder.cfg((ConfigurationTransition) arguments.get(CONFIGURATION_ARG));
+ Object trans = arguments.get(CONFIGURATION_ARG);
+ if (trans instanceof ConfigurationTransition) {
+ // TODO(laurentlb): Deprecated, to be removed in August 2016.
+ builder.cfg((ConfigurationTransition) trans);
+ } else if (trans.equals("data")) {
+ builder.cfg(ConfigurationTransition.DATA);
+ } else if (trans.equals("host")) {
+ builder.cfg(ConfigurationTransition.HOST);
+ } else {
+ throw new EvalException(ast.getLocation(), "cfg must be either 'data' or 'host'.");
+ }
}
return builder;
}
@@ -474,7 +484,7 @@ public final class SkylarkAttr {
),
@Param(
name = CONFIGURATION_ARG,
- type = ConfigurationTransition.class,
+ type = Object.class,
noneable = true,
defaultValue = "None",
named = true,
@@ -691,7 +701,7 @@ public final class SkylarkAttr {
),
@Param(
name = CONFIGURATION_ARG,
- type = ConfigurationTransition.class,
+ type = Object.class,
noneable = true,
defaultValue = "None",
named = true,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
index 400af91b50..c7c8b01586 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
@@ -99,13 +99,22 @@ import java.util.concurrent.ExecutionException;
*/
public class SkylarkRuleClassFunctions {
- //TODO(bazel-team): proper enum support
- @SkylarkSignature(name = "DATA_CFG", returnType = ConfigurationTransition.class,
- doc = "Experimental. Specifies a transition to the data configuration.")
+ @SkylarkSignature(
+ name = "DATA_CFG",
+ returnType = ConfigurationTransition.class,
+ doc =
+ "Deprecated. Use string \"data\" instead. "
+ + "Specifies a transition to the data configuration."
+ )
private static final Object dataTransition = ConfigurationTransition.DATA;
- @SkylarkSignature(name = "HOST_CFG", returnType = ConfigurationTransition.class,
- doc = "Specifies a transition to the host configuration.")
+ @SkylarkSignature(
+ name = "HOST_CFG",
+ returnType = ConfigurationTransition.class,
+ doc =
+ "Deprecated. Use string \"host\" instead. "
+ + "Specifies a transition to the host configuration."
+ )
private static final Object hostTransition = ConfigurationTransition.HOST;
// TODO(bazel-team): Copied from ConfiguredRuleClassProvider for the transition from built-in
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
index 78ced6c804..0716654b14 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
@@ -375,13 +375,27 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
}
@Test
- public void testAttrCfg() throws Exception {
+ public void testAttrCfg_deprecated() throws Exception {
Attribute attr = evalAttributeDefinition("attr.label(cfg = HOST_CFG, allow_files = True)")
.build("a1");
assertEquals(ConfigurationTransition.HOST, attr.getConfigurationTransition());
}
@Test
+ public void testAttrCfg() throws Exception {
+ Attribute attr = evalAttributeDefinition("attr.label(cfg = 'host', allow_files = True)")
+ .build("a1");
+ assertEquals(ConfigurationTransition.HOST, attr.getConfigurationTransition());
+ }
+
+ @Test
+ public void testAttrCfgData() throws Exception {
+ Attribute attr = evalAttributeDefinition("attr.label(cfg = 'data', allow_files = True)")
+ .build("a1");
+ assertEquals(ConfigurationTransition.DATA, attr.getConfigurationTransition());
+ }
+
+ @Test
public void testAttrValues() throws Exception {
Attribute attr = evalAttributeDefinition("attr.string(values = ['ab', 'cd'])").build("a1");
PredicateWithMessage<Object> predicate = attr.getAllowedValues();