diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 0e1a8455f977ed..593254acaac395 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -28,6 +28,8 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; import com.google.devtools.build.lib.syntax.ClassObject; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.EvalUtils; @@ -168,6 +170,13 @@ public interface SplitTransition extends Transition { /** * Declaration how the configuration should change when following a label or label list attribute. */ + @SkylarkModule(name = "ConfigurationTransition", + category = SkylarkModuleCategory.NONE, + doc = + "Declares how the configuration should change when following a dependency. " + + "It can be either DATA_CFG or " + + "HOST_CFG. " + + "This type is deprecated, use string \"host\" or \"data\" instead.") public enum ConfigurationTransition implements Transition { /** No transition, i.e., the same configuration as the current. */ NONE, 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 078ab2da0e9d25..2e4bbb6ea784db 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 @@ -259,7 +259,10 @@ && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { if (containsNonNoneKey(arguments, CONFIGURATION_ARG)) { Object trans = arguments.get(CONFIGURATION_ARG); - if (trans.equals("data")) { + 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); 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 0b667f7e8c7958..a88e0966679f18 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 @@ -46,6 +46,7 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.AttributeValueSource; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SkylarkImplicitOutputsFunctionWithCallback; @@ -98,6 +99,24 @@ */ public class SkylarkRuleClassFunctions { + @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 = + "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 // rules to skylark extensions. Using the same instance would require a large refactoring. // If we don't want to support old built-in rules and Skylark simultaneously diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java index aeb989f0865395..4bf2c551025689 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java @@ -31,6 +31,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.util.FileTypeSet; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java index fa8beb150867d3..a1401872901328 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java @@ -417,7 +417,7 @@ public void testExecutableGetsInRunfilesAndFilesToBuild() throws Exception { " return struct(runfiles = rf)", "", "custom_rule = rule(implementation = custom_rule_impl, executable = True,", - " attrs = {'data': attr.label_list(cfg='data', allow_files=True)})"); + " attrs = {'data': attr.label_list(cfg=DATA_CFG, allow_files=True)})"); scratch.file( "test/skylark/BUILD", 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 78e4b4e51d5b8b..3e677be5b934e1 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 @@ -408,6 +408,13 @@ public void testAttrBadKeywordArguments() throws Exception { "unexpected keyword 'bad_keyword' in call to string", "attr.string(bad_keyword = '')"); } + @Test + 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)") @@ -657,8 +664,8 @@ public void testTextMessageInvalidElementInListStructure() throws Exception { public void testTextMessageInvalidStructure() throws Exception { checkErrorContains( "Invalid text format, expected a struct, a string, a bool, or an int " - + "but got a function for struct field 'a'", - "struct(a=rule).to_proto()"); + + "but got a ConfigurationTransition for struct field 'a'", + "struct(a=DATA_CFG).to_proto()"); } private void checkJson(String from, String expected) throws Exception { @@ -704,8 +711,8 @@ public void testJsonNestedListStructure() throws Exception { public void testJsonInvalidStructure() throws Exception { checkErrorContains( "Invalid text format, expected a struct, a string, a bool, or an int but got a " - + "function for struct field 'a'", - "struct(a=rule).to_json()"); + + "ConfigurationTransition for struct field 'a'", + "struct(a=DATA_CFG).to_json()"); } @Test diff --git a/src/test/shell/bazel/bazel_worker_test.sh b/src/test/shell/bazel/bazel_worker_test.sh index defc9ff52b59ec..6fecea28c460cd 100755 --- a/src/test/shell/bazel/bazel_worker_test.sh +++ b/src/test/shell/bazel/bazel_worker_test.sh @@ -106,7 +106,7 @@ def _impl(ctx): work = rule( implementation=_impl, attrs={ - "worker": attr.label(cfg="host", mandatory=True, allow_files=True, executable=True), + "worker": attr.label(cfg=HOST_CFG, mandatory=True, allow_files=True, executable=True), "worker_args": attr.string_list(), "args": attr.string_list(), "srcs": attr.label_list(allow_files=True), diff --git a/tools/build_defs/apple/apple_genrule.bzl b/tools/build_defs/apple/apple_genrule.bzl index 8a0b067b5deb59..b22c4801893773 100644 --- a/tools/build_defs/apple/apple_genrule.bzl +++ b/tools/build_defs/apple/apple_genrule.bzl @@ -75,7 +75,7 @@ _apple_genrule_inner = rule( implementation=_apple_genrule, attrs={ "srcs": attr.label_list(allow_files=True), - "tools": attr.label_list(cfg="host", allow_files=True), + "tools": attr.label_list(cfg=HOST_CFG, allow_files=True), "outs": attr.output_list(mandatory=True), "cmd": attr.string(mandatory=True), "message": attr.string(), diff --git a/tools/build_rules/java_rules_skylark.bzl b/tools/build_rules/java_rules_skylark.bzl index 41676b4ed17e01..8b3666e30a203e 100644 --- a/tools/build_rules/java_rules_skylark.bzl +++ b/tools/build_rules/java_rules_skylark.bzl @@ -182,7 +182,7 @@ java_library_attrs = { "_javac": attr.label(default=Label("//tools/jdk:javac"), single_file=True), "_jar": attr.label(default=Label("//tools/jdk:jar"), single_file=True), "_jdk": attr.label(default=Label("//tools/jdk:jdk"), allow_files=True), - "data": attr.label_list(allow_files=True, cfg="data"), + "data": attr.label_list(allow_files=True, cfg=DATA_CFG), "resources": attr.label_list(allow_files=True), "srcs": attr.label_list(allow_files=java_filetype), "jars": attr.label_list(allow_files=jar_filetype),