Remove the ToolchainConstructor class and change uses to be either a
Label or a ToolchainInfo provider.
Part of #2219.
Change-Id: Ia09070717f54eea10e1ab0303253714b58768548
PiperOrigin-RevId: 160995546
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java
index fc903dc..8e3a1d0 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java
@@ -17,31 +17,30 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
-import com.google.devtools.build.lib.packages.ClassObjectConstructor;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.syntax.SkylarkDict;
import java.util.Map;
import javax.annotation.Nullable;
/** Contains toolchain-related information needed for a {@link RuleContext}. */
public class ToolchainContext {
- private final ImmutableList<ClassObjectConstructor.Key> requiredToolchains;
- private final ImmutableMap<ClassObjectConstructor.Key, ToolchainInfo> toolchains;
+ private final ImmutableList<Label> requiredToolchains;
+ private final ImmutableMap<Label, ToolchainInfo> toolchains;
public ToolchainContext(
- ImmutableList<ClassObjectConstructor.Key> requiredToolchains,
- @Nullable Map<ClassObjectConstructor.Key, ToolchainInfo> toolchains) {
+ ImmutableList<Label> requiredToolchains, @Nullable Map<Label, ToolchainInfo> toolchains) {
this.requiredToolchains = requiredToolchains;
this.toolchains =
toolchains == null
- ? ImmutableMap.<ClassObjectConstructor.Key, ToolchainInfo>of()
+ ? ImmutableMap.<Label, ToolchainInfo>of()
: ImmutableMap.copyOf(toolchains);
}
- public ImmutableList<ClassObjectConstructor.Key> getRequiredToolchains() {
+ public ImmutableList<Label> getRequiredToolchains() {
return requiredToolchains;
}
- public SkylarkDict<ClassObjectConstructor.Key, ToolchainInfo> collectToolchains() {
- return SkylarkDict.<ClassObjectConstructor.Key, ToolchainInfo>copyOf(null, toolchains);
+ public SkylarkDict<Label, ToolchainInfo> collectToolchains() {
+ return SkylarkDict.<Label, ToolchainInfo>copyOf(null, toolchains);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
index 860e3dff..4b8750d 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
@@ -60,7 +60,7 @@
private final RequiredProviders requiredProviders;
private final RequiredProviders requiredProvidersForAspects;
private final ImmutableMap<String, Attribute> attributes;
- private final ImmutableList<ClassObjectConstructor.Key> requiredToolchains;
+ private final ImmutableList<Label> requiredToolchains;
/**
* Which attributes aspect should propagate along:
@@ -83,7 +83,7 @@
RequiredProviders requiredProviders,
RequiredProviders requiredAspectProviders,
ImmutableMap<String, Attribute> attributes,
- ImmutableList<ClassObjectConstructor.Key> requiredToolchains,
+ ImmutableList<Label> requiredToolchains,
@Nullable ImmutableSet<String> restrictToAttributes,
@Nullable ConfigurationFragmentPolicy configurationFragmentPolicy,
boolean applyToFiles) {
@@ -117,7 +117,7 @@
}
/** Returns the required toolchains declared by this aspect. */
- public ImmutableList<ClassObjectConstructor.Key> getRequiredToolchains() {
+ public ImmutableList<Label> getRequiredToolchains() {
return requiredToolchains;
}
@@ -265,7 +265,7 @@
private final ConfigurationFragmentPolicy.Builder configurationFragmentPolicy =
new ConfigurationFragmentPolicy.Builder();
private boolean applyToFiles = false;
- private final List<ClassObjectConstructor.Key> requiredToolchains = new ArrayList<>();
+ private final List<Label> requiredToolchains = new ArrayList<>();
public Builder(AspectClass aspectClass) {
this.aspectClass = aspectClass;
@@ -467,7 +467,7 @@
}
/** Adds the given toolchains as requirements for this aspect. */
- public Builder addRequiredToolchains(List<ClassObjectConstructor.Key> requiredToolchains) {
+ public Builder addRequiredToolchains(List<Label> requiredToolchains) {
this.requiredToolchains.addAll(requiredToolchains);
return this;
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index cef8c16..29a7fd9 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
@@ -508,7 +509,7 @@
private boolean supportsConstraintChecking = true;
private final Map<String, Attribute> attributes = new LinkedHashMap<>();
- private final List<ClassObjectConstructor.Key> requiredToolchains = new ArrayList<>();
+ private final List<Label> requiredToolchains = new ArrayList<>();
/**
* Constructs a new {@code RuleClassBuilder} using all attributes from all
@@ -1000,8 +1001,8 @@
return this;
}
- public Builder addRequiredToolchain(ClassObjectConstructor.Key toolchain) {
- this.requiredToolchains.add(toolchain);
+ public Builder addRequiredToolchains(Iterable<Label> toolchainLabels) {
+ Iterables.addAll(this.requiredToolchains, toolchainLabels);
return this;
}
@@ -1125,7 +1126,7 @@
*/
private final boolean supportsConstraintChecking;
- private final ImmutableList<ClassObjectConstructor.Key> requiredToolchains;
+ private final ImmutableList<Label> requiredToolchains;
/**
* Constructs an instance of RuleClass whose name is 'name', attributes are 'attributes'. The
@@ -1173,7 +1174,7 @@
String ruleDefinitionEnvironmentHashCode,
ConfigurationFragmentPolicy configurationFragmentPolicy,
boolean supportsConstraintChecking,
- List<ClassObjectConstructor.Key> requiredToolchains,
+ List<Label> requiredToolchains,
Attribute... attributes) {
this.name = name;
this.isSkylark = isSkylark;
@@ -2012,7 +2013,7 @@
return outputsDefaultExecutable;
}
- public ImmutableList<ClassObjectConstructor.Key> getRequiredToolchains() {
+ public ImmutableList<Label> getRequiredToolchains() {
return requiredToolchains;
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java
index 3a544c7..7c2408b 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java
@@ -46,7 +46,7 @@
private final ImmutableSet<String> paramAttributes;
private final ImmutableSet<String> fragments;
private final ImmutableSet<String> hostFragments;
- private final ImmutableList<ClassObjectConstructor.Key> requiredToolchains;
+ private final ImmutableList<Label> requiredToolchains;
private final Environment funcallEnv;
private SkylarkAspectClass aspectClass;
@@ -60,7 +60,7 @@
ImmutableSet<String> paramAttributes,
ImmutableSet<String> fragments,
ImmutableSet<String> hostFragments,
- ImmutableList<ClassObjectConstructor.Key> requiredToolchains,
+ ImmutableList<Label> requiredToolchains,
Environment funcallEnv) {
this.implementation = implementation;
this.attributeAspects = attributeAspects;
@@ -196,7 +196,7 @@
};
}
- public ImmutableList<ClassObjectConstructor.Key> getRequiredToolchains() {
+ public ImmutableList<Label> getRequiredToolchains() {
return requiredToolchains;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ToolchainConstructor.java b/src/main/java/com/google/devtools/build/lib/packages/ToolchainConstructor.java
deleted file mode 100644
index 13a965e..0000000
--- a/src/main/java/com/google/devtools/build/lib/packages/ToolchainConstructor.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.packages;
-
-import com.google.devtools.build.lib.packages.ClassObjectConstructor.Key;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
-
-/**
- * Constructor that can be used to generate toolchains. The key returned by {@link #getKey()} is a
- * serializable representation of the constructor and serves to identify toolchains of the same
- * type.
- */
-public interface ToolchainConstructor extends SkylarkValue {
-
- Key getKey();
-}
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 03e423d..5cbe59b 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
@@ -71,7 +71,6 @@
import com.google.devtools.build.lib.packages.SkylarkExportable;
import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.packages.TestSize;
-import com.google.devtools.build.lib.packages.ToolchainConstructor;
import com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor;
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature;
@@ -384,7 +383,7 @@
@Param(
name = "toolchains",
type = SkylarkList.class,
- generic1 = ToolchainConstructor.class,
+ generic1 = String.class,
defaultValue = "[]",
doc =
"<i>(Experimental)</i><br/><br/>"
@@ -410,7 +409,7 @@
SkylarkList fragments,
SkylarkList hostFragments,
Boolean skylarkTestable,
- SkylarkList<ToolchainConstructor> toolchains,
+ SkylarkList<String> toolchains,
FuncallExpression ast,
Environment funcallEnv)
throws EvalException, ConversionException {
@@ -469,10 +468,7 @@
hostFragments.getContents(String.class, "host_fragments"));
builder.setConfiguredTargetFunction(implementation);
builder.setRuleDefinitionEnvironment(funcallEnv);
-
- for (ToolchainConstructor toolchain : toolchains) {
- builder.addRequiredToolchain(toolchain.getKey());
- }
+ builder.addRequiredToolchains(collectToolchainLabels(toolchains, ast));
return new RuleFunction(builder, type, attributes, ast.getLocation());
}
@@ -503,6 +499,24 @@
}
}
+ private static ImmutableList<Label> collectToolchainLabels(
+ Iterable<String> rawLabels, FuncallExpression ast) throws EvalException {
+ ImmutableList.Builder<Label> requiredToolchains = new ImmutableList.Builder<>();
+ for (String rawLabel : rawLabels) {
+ try {
+ Label toolchainLabel = Label.parseAbsolute(rawLabel);
+ requiredToolchains.add(toolchainLabel);
+ } catch (LabelSyntaxException e) {
+ throw new EvalException(
+ ast.getLocation(),
+ String.format("Unable to parse toolchain %s: %s", rawLabel, e.getMessage()),
+ e);
+ }
+ }
+
+ return requiredToolchains.build();
+ }
+
@SkylarkSignature(
name = "aspect",
doc =
@@ -583,7 +597,7 @@
@Param(
name = "toolchains",
type = SkylarkList.class,
- generic1 = ToolchainConstructor.class,
+ generic1 = String.class,
defaultValue = "[]",
doc =
"<i>(Experimental)</i><br/><br/>"
@@ -605,7 +619,7 @@
SkylarkList providesArg,
SkylarkList fragments,
SkylarkList hostFragments,
- SkylarkList<ToolchainConstructor> toolchains,
+ SkylarkList<String> toolchains,
FuncallExpression ast,
Environment funcallEnv)
throws EvalException {
@@ -684,14 +698,6 @@
}
}
- // Collect the required toolchain keys.
- ImmutableList.Builder<ClassObjectConstructor.Key> requiredToolchains =
- new ImmutableList.Builder<>();
- for (ToolchainConstructor toolchain :
- toolchains.getContents(ToolchainConstructor.class, "toolchains")) {
- requiredToolchains.add(toolchain.getKey());
- }
-
return new SkylarkAspect(
implementation,
attrAspects.build(),
@@ -702,7 +708,7 @@
requiredParams.build(),
ImmutableSet.copyOf(fragments.getContents(String.class, "fragments")),
ImmutableSet.copyOf(hostFragments.getContents(String.class, "host_fragments")),
- requiredToolchains.build(),
+ collectToolchainLabels(toolchains, ast),
funcallEnv);
}
};
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
index 075ba50..4aabe2d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
@@ -184,7 +184,7 @@
private SkylarkRuleAttributesCollection attributesCollection;
private SkylarkRuleAttributesCollection ruleAttributesCollection;
private SkylarkClassObject splitAttributes;
- private SkylarkDict<ClassObjectConstructor.Key, ToolchainInfo> toolchains;
+ private SkylarkDict<Label, ToolchainInfo> toolchains;
// TODO(bazel-team): we only need this because of the css_binary rule.
private ImmutableMap<Artifact, Label> artifactsLabelMap;
@@ -290,7 +290,7 @@
makeVariables = ruleContext.getConfigurationMakeVariableContext().collectMakeVariables();
toolchains =
ruleContext.getToolchainContext() == null
- ? SkylarkDict.<ClassObjectConstructor.Key, ToolchainInfo>of(null)
+ ? SkylarkDict.<Label, ToolchainInfo>of(null)
: ruleContext.getToolchainContext().collectToolchains();
}
@@ -835,7 +835,7 @@
}
@SkylarkCallable(structField = true, doc = "Toolchains required for this rule.")
- public SkylarkDict<ClassObjectConstructor.Key, ToolchainInfo> toolchains() throws EvalException {
+ public SkylarkDict<Label, ToolchainInfo> toolchains() throws EvalException {
checkMutable("toolchains");
if (ruleAttributesCollection != null) {
// TODO(katre): Support toolchains on aspects.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/NativeToolchainConstructor.java b/src/main/java/com/google/devtools/build/lib/rules/platform/NativeToolchainConstructor.java
deleted file mode 100644
index 6d62b25..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/NativeToolchainConstructor.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.rules.platform;
-
-import com.google.devtools.build.lib.packages.NativeClassObjectConstructor;
-import com.google.devtools.build.lib.packages.ToolchainConstructor;
-import com.google.devtools.build.lib.syntax.Environment;
-import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.FuncallExpression;
-import javax.annotation.Nullable;
-
-/** Native value that can be used to create toolchains. */
-public class NativeToolchainConstructor extends NativeClassObjectConstructor
- implements ToolchainConstructor {
-
- protected NativeToolchainConstructor(String name) {
- super(name);
- }
-
- // TODO(katre): Implement this.
- @Override
- protected Object call(Object[] args, @Nullable FuncallExpression ast, @Nullable Environment env)
- throws EvalException, InterruptedException {
- throw new IllegalStateException("Native toolchains not yet implemented.");
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
index 1504253..48e9057 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
@@ -18,15 +18,9 @@
import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
-import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.ClassObjectConstructor;
-import com.google.devtools.build.lib.packages.ToolchainConstructor;
-import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature;
-import com.google.devtools.build.lib.syntax.BuiltinFunction;
-import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
/** Skylark namespace used to interact with the platform APIs. */
@@ -81,28 +75,6 @@
return ToolchainInfo.SKYLARK_CONSTRUCTOR;
}
- @SkylarkSignature(
- name = "toolchain_type",
- doc =
- "Creates a new ToolchainConstructor instance, which can be used to create new "
- + "ToolchainInfo instances. The constructor takes a list of execution constraints, a "
- + "list of target constraints, and then other data which may be used by a rule author.",
- documented = false,
- objectType = PlatformCommon.class,
- returnType = ToolchainConstructor.class,
- parameters = {
- @Param(name = "self", type = PlatformCommon.class, doc = "the platform_rules instance"),
- },
- useLocation = true
- )
- private static final BuiltinFunction createToolchainType =
- new BuiltinFunction("toolchain_type") {
- @SuppressWarnings("unchecked")
- public ToolchainConstructor invoke(PlatformCommon self, Location loc) throws EvalException {
- return new SkylarkToolchainConstructor(loc);
- }
- };
-
static {
SkylarkSignatureProcessor.configureSkylarkFunctions(PlatformCommon.class);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/SkylarkToolchainConstructor.java b/src/main/java/com/google/devtools/build/lib/rules/platform/SkylarkToolchainConstructor.java
deleted file mode 100644
index b8d27eb..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/SkylarkToolchainConstructor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.rules.platform;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
-import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor;
-import com.google.devtools.build.lib.packages.ToolchainConstructor;
-import com.google.devtools.build.lib.syntax.Environment;
-import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.FuncallExpression;
-import com.google.devtools.build.lib.syntax.FunctionSignature;
-import com.google.devtools.build.lib.syntax.SkylarkList;
-import com.google.devtools.build.lib.syntax.SkylarkType;
-import javax.annotation.Nullable;
-
-/** Skylark value that can be used to create toolchains. */
-// TODO(katre): Remove this entirely.
-public class SkylarkToolchainConstructor extends SkylarkClassObjectConstructor
- implements ToolchainConstructor {
-
- private static final String EXEC_COMPATIBLE_WITH = "exec_compatible_with";
- private static final String TARGET_COMPATIBLE_WITH = "target_compatible_with";
- private static final String TOOLCHAIN_DATA = "toolchain_data";
-
- private static final FunctionSignature.WithValues<Object, SkylarkType> SIGNATURE =
- FunctionSignature.WithValues.create(
- FunctionSignature.of(
- /*numMandatoryPositionals=*/ 0,
- /*numOptionalPositionals=*/ 0,
- /*numMandatoryNamedOnly*/ 0,
- /*starArg=*/ false,
- /*kwArg=*/ true,
- /*names=*/ EXEC_COMPATIBLE_WITH,
- TARGET_COMPATIBLE_WITH,
- TOOLCHAIN_DATA),
- /*defaultValues=*/ ImmutableList.<Object>of(
- SkylarkList.MutableList.EMPTY, SkylarkList.MutableList.EMPTY),
- /*types=*/ ImmutableList.<SkylarkType>of(
- SkylarkType.Combination.of(
- SkylarkType.LIST, SkylarkType.Simple.of(TransitiveInfoCollection.class)),
- SkylarkType.Combination.of(
- SkylarkType.LIST, SkylarkType.Simple.of(TransitiveInfoCollection.class)),
- SkylarkType.DICT));
-
- public SkylarkToolchainConstructor(Location location) {
- super(
- "<no name>", // name is set on export.
- SIGNATURE,
- location);
- }
-
- @Override
- @Nullable
- protected Object call(Object[] args, @Nullable FuncallExpression ast, @Nullable Environment env)
- throws EvalException, InterruptedException {
-
- return null;
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
index c6b89f1..51290ba 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
@@ -899,7 +899,7 @@
.setMissingFragmentPolicy(missingFragmentPolicy)
.build(),
supportsConstraintChecking,
- /*requiredToolchains=*/ ImmutableList.<ClassObjectConstructor.Key>of(),
+ /*requiredToolchains=*/ ImmutableList.<Label>of(),
attributes);
}
@@ -1041,13 +1041,15 @@
.factory(DUMMY_CONFIGURED_TARGET_FACTORY)
.add(attr("tags", STRING_LIST));
- ClassObjectConstructor.Key toolchain1 = new ClassObjectConstructor.Key() {};
- ClassObjectConstructor.Key toolchain2 = new ClassObjectConstructor.Key() {};
- ruleClassBuilder.addRequiredToolchain(toolchain1);
- ruleClassBuilder.addRequiredToolchain(toolchain2);
+ ruleClassBuilder.addRequiredToolchains(
+ ImmutableList.of(
+ Label.parseAbsolute("//toolchain:tc1"), Label.parseAbsolute("//toolchain:tc2")));
RuleClass ruleClass = ruleClassBuilder.build();
- assertThat(ruleClass.getRequiredToolchains()).containsExactly(toolchain1, toolchain2).inOrder();
+ assertThat(ruleClass.getRequiredToolchains())
+ .containsExactly(
+ Label.parseAbsolute("//toolchain:tc1"), Label.parseAbsolute("//toolchain:tc2"))
+ .inOrder();
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java
deleted file mode 100644
index e26389a..0000000
--- a/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformCommonTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.rules.platform;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
-import com.google.devtools.build.lib.skylark.util.SkylarkTestCase;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for {@link PlatformCommon}. */
-@RunWith(JUnit4.class)
-public class PlatformCommonTest extends SkylarkTestCase {
-
- @Test
- @Ignore("Remove this test")
- public void testCreateToolchainType() throws Exception {
- scratch.file(
- "test/toolchain_type.bzl",
- "test_toolchain_type = platform_common.toolchain_type()",
- "def _impl(ctx):",
- " toolchain = test_toolchain_type(",
- " exec_compatible_with = ctx.attr.exec_compatible_with,",
- " target_compatible_with = ctx.attr.target_compatible_with,",
- " extra_label = ctx.attr.extra_label,",
- " extra_str = ctx.attr.extra_str,",
- " )",
- " return [toolchain]",
- "test_toolchain = rule(",
- " implementation = _impl,",
- " attrs = {",
- " 'exec_compatible_with': attr.label_list(",
- " providers = [platform_common.ConstraintValueInfo]),",
- " 'target_compatible_with': attr.label_list(",
- " providers = [platform_common.ConstraintValueInfo]),",
- " 'extra_label': attr.label(),",
- " 'extra_str': attr.string(),",
- " }",
- ")");
- scratch.file(
- "test/BUILD",
- "load(':toolchain_type.bzl', 'test_toolchain')",
- "constraint_setting(name = 'os')",
- "constraint_value(name = 'linux',",
- " constraint_setting = ':os')",
- "constraint_value(name = 'mac',",
- " constraint_setting = ':os')",
- "filegroup(name = 'dep_rule')",
- "test_toolchain(",
- " name = 'linux_toolchain',",
- " exec_compatible_with = [",
- " ':linux',",
- " ],",
- " target_compatible_with = [",
- " ':mac',",
- " ],",
- " extra_label = ':dep_rule',",
- " extra_str = 'bar',",
- ")");
-
- ConfiguredTarget configuredTarget = getConfiguredTarget("//test:linux_toolchain");
- ToolchainInfo toolchainInfo =
- (ToolchainInfo) configuredTarget.get(ToolchainInfo.SKYLARK_IDENTIFIER);
- assertThat(toolchainInfo).isNotNull();
- }
-}
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 aef0e11..4fa16cd 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
@@ -39,7 +39,6 @@
import com.google.devtools.build.lib.packages.SkylarkClassObject;
import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor;
import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier;
-import com.google.devtools.build.lib.packages.ToolchainConstructor;
import com.google.devtools.build.lib.rules.SkylarkAttr;
import com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor;
import com.google.devtools.build.lib.rules.SkylarkFileType;
@@ -410,6 +409,15 @@
}
@Test
+ public void testAspectAddToolchain() throws Exception {
+ scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')");
+ evalAndExport(
+ "def _impl(ctx): pass", "a1 = aspect(_impl, toolchains=['//test:my_toolchain_type'])");
+ SkylarkAspect a = (SkylarkAspect) lookup("a1");
+ assertThat(a.getRequiredToolchains()).containsExactly(makeLabel("//test:my_toolchain_type"));
+ }
+
+ @Test
public void testNonLabelAttrWithProviders() throws Exception {
checkErrorContains(
"unexpected keyword 'providers' in call to string", "attr.string(providers = ['a'])");
@@ -1420,13 +1428,11 @@
@Test
public void testRuleAddToolchain() throws Exception {
+ scratch.file("test/BUILD", "toolchain_type(name = 'my_toolchain_type')");
evalAndExport(
- "my_toolchain_type = platform_common.toolchain_type()",
- "def impl(ctx): return None",
- "r1 = rule(impl, toolchains=[my_toolchain_type])");
- ToolchainConstructor toolchain = (ToolchainConstructor) lookup("my_toolchain_type");
+ "def impl(ctx): return None", "r1 = rule(impl, toolchains=['//test:my_toolchain_type'])");
RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
- assertThat(c.getRequiredToolchains()).containsExactly(toolchain.getKey());
+ assertThat(c.getRequiredToolchains()).containsExactly(makeLabel("//test:my_toolchain_type"));
}
@Test