Skip to content

Commit

Permalink
Rollback of commit 4381a1d.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Breaks all projects using Bazel, see https://ci.bazel.io

*** Original change description ***

Deprecated and removed HOST_CFG and DATA_CFG global variables.

--
MOS_MIGRATED_REVID=133005398
  • Loading branch information
damienmg authored and dslomov committed Sep 14, 2016
1 parent 7a0b518 commit 6022b7b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,6 +170,13 @@ public interface SplitTransition<T> 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 <a href=\"globals.html#DATA_CFG\">DATA_CFG</a> or "
+ "<a href=\"globals.html#HOST_CFG\">HOST_CFG</a>. "
+ "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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_worker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion tools/build_defs/apple/apple_genrule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion tools/build_rules/java_rules_skylark.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 6022b7b

Please sign in to comment.