diff options
author | 2017-07-07 20:55:55 +0200 | |
---|---|---|
committer | 2017-07-10 09:16:07 +0200 | |
commit | 739d80ccbd795bac7727a6d89bbb92f5436675cf (patch) | |
tree | c8e639f557b0adf44b0f90d0157c64f750f3fd95 /src/main/java/com | |
parent | c6bd5166d1c558fb8f619b53eb4c56fa7cee8b93 (diff) |
Update the default values for the C++ and Java late-bound attributes to the correct //tools/cpp:toolchain and //tools/jdk:jdk.
PiperOrigin-RevId: 161227981
Diffstat (limited to 'src/main/java/com')
16 files changed, 112 insertions, 87 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 54ff50615c..6a5c3d2b1d 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -78,6 +78,7 @@ import com.google.devtools.build.lib.bazel.rules.workspace.NewGitRepositoryRule; import com.google.devtools.build.lib.bazel.rules.workspace.NewHttpArchiveRule; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.ideinfo.AndroidStudioInfoAspect; +import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.rules.Alias.AliasRule; import com.google.devtools.build.lib.rules.android.AarImportBaseRule; import com.google.devtools.build.lib.rules.android.AndroidBinaryOnlyRule; @@ -118,6 +119,7 @@ import com.google.devtools.build.lib.rules.java.JavaImportBaseRule; import com.google.devtools.build.lib.rules.java.JavaOptions; import com.google.devtools.build.lib.rules.java.JavaRuntimeRule; import com.google.devtools.build.lib.rules.java.JavaRuntimeSuiteRule; +import com.google.devtools.build.lib.rules.java.JavaSemantics; import com.google.devtools.build.lib.rules.java.JavaSkylarkCommon; import com.google.devtools.build.lib.rules.java.JavaToolchainRule; import com.google.devtools.build.lib.rules.java.JvmConfigurationLoader; @@ -413,7 +415,7 @@ public class BazelRuleClassProvider { new RuleSet() { @Override public void init(Builder builder) { - CcProtoAspect ccProtoAspect = new BazelCcProtoAspect(BazelCppSemantics.INSTANCE); + CcProtoAspect ccProtoAspect = new BazelCcProtoAspect(BazelCppSemantics.INSTANCE, builder); builder.addNativeAspectClass(ccProtoAspect); builder.addRuleDefinition(new CcProtoLibraryRule(ccProtoAspect)); } @@ -470,8 +472,11 @@ public class BazelRuleClassProvider { new RuleSet() { @Override public void init(Builder builder) { - BazelJavaProtoAspect bazelJavaProtoAspect = new BazelJavaProtoAspect(); - BazelJavaLiteProtoAspect bazelJavaLiteProtoAspect = new BazelJavaLiteProtoAspect(); + LateBoundLabel<BuildConfiguration> hostJdkAttribute = + JavaSemantics.hostJdkAttribute(builder); + BazelJavaProtoAspect bazelJavaProtoAspect = new BazelJavaProtoAspect(hostJdkAttribute); + BazelJavaLiteProtoAspect bazelJavaLiteProtoAspect = + new BazelJavaLiteProtoAspect(hostJdkAttribute); builder.addNativeAspectClass(bazelJavaProtoAspect); builder.addNativeAspectClass(bazelJavaLiteProtoAspect); builder.addRuleDefinition(new BazelJavaProtoLibraryRule(bazelJavaProtoAspect)); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java index 1e50255f5b..457f068ade 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java @@ -57,7 +57,7 @@ public class BazelAndroidBinaryRule implements RuleDefinition { .add( attr(":cc_toolchain_split", BuildType.LABEL) .cfg(AndroidRuleClasses.ANDROID_SPLIT_TRANSITION) - .value(CppRuleClasses.CC_TOOLCHAIN)) + .value(CppRuleClasses.ccToolchainAttribute(environment))) /* <!-- #BLAZE_RULE(android_binary).IMPLICIT_OUTPUTS --> <ul> <li><code><var>name</var>.apk</code>: An Android application diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java index 63ade12607..8685322ba5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java @@ -35,7 +35,7 @@ public final class BazelCcIncLibraryRule implements RuleDefinition { .requiresConfigurationFragments(CppConfiguration.class) .add( attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL) - .value(CppRuleClasses.CC_TOOLCHAIN)) + .value(CppRuleClasses.ccToolchainAttribute(env))) .add(attr(":stl", LABEL).value(BazelCppRuleClasses.STL)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java index d352b94d43..dec9d7c761 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java @@ -161,7 +161,7 @@ public class BazelCppRuleClasses { return builder .add( attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL) - .value(CppRuleClasses.CC_TOOLCHAIN)) + .value(CppRuleClasses.ccToolchainAttribute(env))) .setPreferredDependencyPredicate(Predicates.<String>or(CPP_SOURCE, C_SOURCE, CPP_HEADER)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java index 9538ea0925..f2b2cef1cc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java @@ -14,8 +14,9 @@ package com.google.devtools.build.lib.bazel.rules.cpp.proto; -import static com.google.devtools.build.lib.rules.cpp.CppRuleClasses.CC_TOOLCHAIN; +import static com.google.devtools.build.lib.rules.cpp.CppRuleClasses.ccToolchainAttribute; +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.rules.cpp.CppSemantics; import com.google.devtools.build.lib.rules.cpp.proto.CcProtoAspect; @@ -25,7 +26,7 @@ import com.google.devtools.build.lib.rules.cpp.proto.CcProtoAspect; * <p>This class is used to inject Bazel-specific constants into CcProtoAspect. */ public class BazelCcProtoAspect extends CcProtoAspect { - public BazelCcProtoAspect(CppSemantics cppSemantics) { - super(cppSemantics, CC_TOOLCHAIN); + public BazelCcProtoAspect(CppSemantics cppSemantics, RuleDefinitionEnvironment env) { + super(cppSemantics, ccToolchainAttribute(env)); } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java index fa3ba8e810..7130e87e18 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java @@ -50,8 +50,8 @@ public final class BazelGenRuleRule implements RuleDefinition { .add(attr("stamp", BOOLEAN).value(false)) .add( attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL) - .value(GenRuleBaseRule.CC_TOOLCHAIN)) - .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK)) + .value(GenRuleBaseRule.ccToolchainAttribute(env))) + .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.hostJdkAttribute(env))) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java index e8f200474a..ff657489a5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java @@ -129,8 +129,8 @@ public class BazelJavaRuleClasses { @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder - .add(attr(":jvm", LABEL).value(JavaSemantics.JVM).useOutputLicenses()) - .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK)) + .add(attr(":jvm", LABEL).value(JavaSemantics.jvmAttribute(env)).useOutputLicenses()) + .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.hostJdkAttribute(env))) .add(attr("$jacoco_instrumentation", LABEL).cfg(HOST)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java index f628e396b1..041956afe6 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaLiteProtoAspect.java @@ -14,7 +14,9 @@ package com.google.devtools.build.lib.bazel.rules.java.proto; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; +import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.rules.java.proto.JavaLiteProtoAspect; /** An Aspect which BazelJavaLiteProtoLibrary injects to build Java Lite protos. */ @@ -23,7 +25,11 @@ public class BazelJavaLiteProtoAspect extends JavaLiteProtoAspect { public static final String DEFAULT_PROTO_TOOLCHAIN_LABEL = "@com_google_protobuf_javalite//:javalite_toolchain"; - public BazelJavaLiteProtoAspect() { - super(BazelJavaSemantics.INSTANCE, null /* jacocoLabel */, DEFAULT_PROTO_TOOLCHAIN_LABEL); + public BazelJavaLiteProtoAspect(LateBoundLabel<BuildConfiguration> hostJdkAttribute) { + super( + BazelJavaSemantics.INSTANCE, + null /* jacocoLabel */, + DEFAULT_PROTO_TOOLCHAIN_LABEL, + hostJdkAttribute); } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java index e1f15c064e..8698ce8805 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoAspect.java @@ -19,11 +19,13 @@ import static com.google.devtools.build.lib.collect.nestedset.Order.STABLE_ORDER import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.packages.AspectDefinition; import com.google.devtools.build.lib.packages.AspectParameters; +import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.rules.java.JavaLibraryHelper; import com.google.devtools.build.lib.rules.java.proto.JavaProtoAspect; import com.google.devtools.build.lib.rules.java.proto.RpcSupport; @@ -33,12 +35,13 @@ import java.util.List; /** An Aspect which BazelJavaProtoLibrary injects to build Java SPEED protos. */ public class BazelJavaProtoAspect extends JavaProtoAspect { - public BazelJavaProtoAspect() { + public BazelJavaProtoAspect(LateBoundLabel<BuildConfiguration> hostJdkAttribute) { super( BazelJavaSemantics.INSTANCE, null, /* jacocoAttr */ new NoopRpcSupport(), - "@com_google_protobuf_java//:java_toolchain"); + "@com_google_protobuf_java//:java_toolchain", + hostJdkAttribute); } private static class NoopRpcSupport diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index a8b2f3ed35..6da2c12e49 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -32,6 +32,7 @@ import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.VERSIONED_SHA import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.analysis.LanguageDependentFragment.LibraryLanguage; +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.PatchTransition; import com.google.devtools.build.lib.cmdline.Label; @@ -121,7 +122,7 @@ public class CppRuleClasses { * Label of a pseudo-filegroup that contains all crosstool and libcfiles for all configurations, * as specified on the command-line. */ - public static final String CROSSTOOL_LABEL = "//tools/defaults:crosstool"; + public static final String CROSSTOOL_LABEL = "//tools/cpp:toolchain"; public static final LateBoundLabel<BuildConfiguration> DEFAULT_MALLOC = new LateBoundLabel<BuildConfiguration>() { @@ -131,13 +132,16 @@ public class CppRuleClasses { } }; - public static final LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN = - new LateBoundLabel<BuildConfiguration>(CROSSTOOL_LABEL, CppConfiguration.class) { - @Override - public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { - return configuration.getFragment(CppConfiguration.class).getCcToolchainRuleLabel(); - } - }; + public static LateBoundLabel<BuildConfiguration> ccToolchainAttribute( + RuleDefinitionEnvironment env) { + return new LateBoundLabel<BuildConfiguration>( + env.getToolsLabel(CROSSTOOL_LABEL), CppConfiguration.class) { + @Override + public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { + return configuration.getFragment(CppConfiguration.class).getCcToolchainRuleLabel(); + } + }; + } // Artifacts of these types are discarded from the 'hdrs' attribute in cc rules static final FileTypeSet DISALLOWED_HDRS_FILES = FileTypeSet.of( diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java index 544a03df21..2e9bbf3f31 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.Rule; @@ -46,22 +47,23 @@ import com.google.devtools.build.lib.util.FileTypeSet; * as a setup script target. */ public class GenRuleBaseRule implements RuleDefinition { - /** * Late-bound dependency on the C++ toolchain <i>iff</i> the genrule has make variables that need * that toolchain. */ - public static final Attribute.LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN = - new Attribute.LateBoundLabel<BuildConfiguration>( - CppRuleClasses.CROSSTOOL_LABEL, CppConfiguration.class) { - @Override - public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { - return attributes != null - && GenRuleBase.requiresCrosstool(attributes.get("cmd", Type.STRING)) - ? CppRuleClasses.CC_TOOLCHAIN.resolve(rule, attributes, configuration) - : null; - } - }; + public static Attribute.LateBoundLabel<BuildConfiguration> ccToolchainAttribute( + RuleDefinitionEnvironment env) { + return new LateBoundLabel<BuildConfiguration>( + env.getToolsLabel(CppRuleClasses.CROSSTOOL_LABEL), CppConfiguration.class) { + @Override + public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { + return attributes != null + && GenRuleBase.requiresCrosstool(attributes.get("cmd", Type.STRING)) + ? CppRuleClasses.ccToolchainAttribute(env).resolve(rule, attributes, configuration) + : null; + } + }; + } @Override public RuleClass build( diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImplicitAttributes.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImplicitAttributes.java index 40b0d06342..758c88b698 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImplicitAttributes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImplicitAttributes.java @@ -19,9 +19,8 @@ package com.google.devtools.build.lib.rules.java; */ public class JavaImplicitAttributes { /** - * Label of a pseudo-filegroup that contains all jdk files for all - * configurations, as specified on the command-line. + * Label of a pseudo-filegroup that contains all jdk files for all configurations, as specified on + * the command-line. */ - public static final String JDK_LABEL = "//tools/defaults:jdk"; - + public static final String JDK_LABEL = "//tools/jdk:jdk"; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java index af726b8030..4c09e53e69 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java @@ -38,22 +38,19 @@ public class JavaImportBaseRule implements RuleDefinition { public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) { return builder .requiresConfigurationFragments(JavaConfiguration.class, CppConfiguration.class) - .add(attr(":host_jdk", LABEL) - .cfg(HOST) - .value(JavaSemantics.HOST_JDK)) + .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.hostJdkAttribute(environment))) /* <!-- #BLAZE_RULE($java_import_base).ATTRIBUTE(jars) --> The list of JAR files provided to Java targets that depend on this target. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ - .add(attr("jars", LABEL_LIST) - .mandatory() - .allowedFileTypes(JavaSemantics.JAR)) + .add(attr("jars", LABEL_LIST).mandatory().allowedFileTypes(JavaSemantics.JAR)) /* <!-- #BLAZE_RULE($java_import_base).ATTRIBUTE(srcjar) --> A JAR file that contains source code for the compiled JAR files. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ - .add(attr("srcjar", LABEL) - .allowedFileTypes(JavaSemantics.SOURCE_JAR, JavaSemantics.JAR) - .direct_compile_time_input()) - .removeAttribute("deps") // only exports are allowed; nothing is compiled + .add( + attr("srcjar", LABEL) + .allowedFileTypes(JavaSemantics.SOURCE_JAR, JavaSemantics.JAR) + .direct_compile_time_input()) + .removeAttribute("deps") // only exports are allowed; nothing is compiled /* <!-- #BLAZE_RULE($java_import_base).ATTRIBUTE(neverlink) --> Only use this library for compilation and not at runtime. Useful if the library will be provided by the runtime environment @@ -65,9 +62,11 @@ public class JavaImportBaseRule implements RuleDefinition { /* <!-- #BLAZE_RULE($java_import_base).ATTRIBUTE(constraints) --> Extra constraints imposed on this rule as a Java library. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ - .add(attr("constraints", STRING_LIST) - .orderIndependent() - .nonconfigurable("used in Attribute.validityPredicate implementations (loading time)")) + .add( + attr("constraints", STRING_LIST) + .orderIndependent() + .nonconfigurable( + "used in Attribute.validityPredicate implementations (loading time)")) .advertiseProvider(JavaSourceInfoProvider.class) .advertiseProvider(JavaCompilationArgsProvider.class) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java index b0a23312a6..571d5170c5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.analysis.LanguageDependentFragment.LibraryL import com.google.devtools.build.lib.analysis.OutputGroupProvider; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.analysis.Runfiles; import com.google.devtools.build.lib.analysis.Runfiles.Builder; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; @@ -129,35 +130,32 @@ public interface JavaSemantics { String GENERATED_JARS_OUTPUT_GROUP = OutputGroupProvider.HIDDEN_OUTPUT_GROUP_PREFIX + "gen_jars"; - - /** - * Implementation for the :jvm attribute. - */ - LateBoundLabel<BuildConfiguration> JVM = - new LateBoundLabel<BuildConfiguration>(JavaImplicitAttributes.JDK_LABEL, Jvm.class) { - @Override - public Label resolve(Rule rule, AttributeMap attributes, - BuildConfiguration configuration) { - return configuration.getFragment(Jvm.class).getJvmLabel(); - } - }; - - /** - * Implementation for the :host_jdk attribute. - */ - LateBoundLabel<BuildConfiguration> HOST_JDK = - new LateBoundLabel<BuildConfiguration>(JavaImplicitAttributes.JDK_LABEL, Jvm.class) { - @Override - public boolean useHostConfiguration() { - return true; - } - - @Override - public Label resolve(Rule rule, AttributeMap attributes, - BuildConfiguration configuration) { - return configuration.getFragment(Jvm.class).getJvmLabel(); - } - }; + /** Implementation for the :jvm attribute. */ + static LateBoundLabel<BuildConfiguration> jvmAttribute(RuleDefinitionEnvironment env) { + return new LateBoundLabel<BuildConfiguration>( + env.getToolsLabel(JavaImplicitAttributes.JDK_LABEL), Jvm.class) { + @Override + public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { + return configuration.getFragment(Jvm.class).getJvmLabel(); + } + }; + } + + /** Implementation for the :host_jdk attribute. */ + static LateBoundLabel<BuildConfiguration> hostJdkAttribute(RuleDefinitionEnvironment env) { + return new LateBoundLabel<BuildConfiguration>( + env.getToolsLabel(JavaImplicitAttributes.JDK_LABEL), Jvm.class) { + @Override + public boolean useHostConfiguration() { + return true; + } + + @Override + public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { + return configuration.getFragment(Jvm.class).getJvmLabel(); + } + }; + } /** * Implementation for the :java_launcher attribute. Note that the Java launcher is disabled by diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java index 4fdcce662b..07ddb04b5c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java @@ -43,6 +43,7 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.AspectDefinition; import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.NativeAspectClass; import com.google.devtools.build.lib.packages.Rule; @@ -84,14 +85,17 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured @Nullable private final String jacocoLabel; private final String defaultProtoToolchainLabel; + private final LateBoundLabel<BuildConfiguration> hostJdkAttribute; public JavaLiteProtoAspect( JavaSemantics javaSemantics, @Nullable String jacocoLabel, - String defaultProtoToolchainLabel) { + String defaultProtoToolchainLabel, + LateBoundLabel<BuildConfiguration> hostJdkAttribute) { this.javaSemantics = javaSemantics; this.jacocoLabel = jacocoLabel; this.defaultProtoToolchainLabel = defaultProtoToolchainLabel; + this.hostJdkAttribute = hostJdkAttribute; } @Override @@ -125,7 +129,7 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured ImmutableList.<Class<? extends TransitiveInfoProvider>>of( ProtoLangToolchainProvider.class)) .value(getProtoToolchainLabel(defaultProtoToolchainLabel))) - .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK)) + .add(attr(":host_jdk", LABEL).cfg(HOST).value(hostJdkAttribute)) .add( attr(":java_toolchain", LABEL) .useOutputLicenses() diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java index 2e50fca863..398494c737 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java @@ -42,6 +42,7 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.AspectDefinition; import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.packages.Attribute; +import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.NativeAspectClass; import com.google.devtools.build.lib.packages.Rule; @@ -68,6 +69,7 @@ import javax.annotation.Nullable; public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspectFactory { private static final String SPEED_PROTO_TOOLCHAIN_ATTR = ":aspect_java_proto_toolchain"; + private final LateBoundLabel<BuildConfiguration> hostJdkAttribute; private static Attribute.LateBoundLabel<BuildConfiguration> getSpeedProtoToolchainLabel( String defaultValue) { @@ -90,11 +92,13 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe JavaSemantics javaSemantics, @Nullable String jacocoLabel, RpcSupport rpcSupport, - String defaultSpeedProtoToolchainLabel) { + String defaultSpeedProtoToolchainLabel, + LateBoundLabel<BuildConfiguration> hostJdkAttribute) { this.javaSemantics = javaSemantics; this.jacocoLabel = jacocoLabel; this.rpcSupport = rpcSupport; this.defaultSpeedProtoToolchainLabel = defaultSpeedProtoToolchainLabel; + this.hostJdkAttribute = hostJdkAttribute; } @Override @@ -134,7 +138,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe // once it's in a Bazel release. .legacyAllowAnyFileType() .value(getSpeedProtoToolchainLabel(defaultSpeedProtoToolchainLabel))) - .add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK)) + .add(attr(":host_jdk", LABEL).cfg(HOST).value(hostJdkAttribute)) .add( attr(":java_toolchain", LABEL) .useOutputLicenses() |