diff options
author | Lukacs Berki <lberki@google.com> | 2015-10-05 12:30:56 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-10-05 15:16:43 +0000 |
commit | 3fbcc611533ba19f283afa3e01240456de9e788e (patch) | |
tree | 436809460e138df65e0840d61a8554e2650f307d /src/main/java/com/google/devtools | |
parent | ab141f8d1035eb30bbb9dc09d89ea6a3ba83cc0f (diff) |
Add a Constants.TOOLS_PREFIX constant that will serve to redirect the Bazel tools repository.
This is a no-op refactoring CL. The actual switch will be made once everything passes with the new setup.
As a side cleanup, change the awkward realAndroidSdk() / realAndroidCrosstoolTop() mechanism to a converter.
--
MOS_MIGRATED_REVID=104649067
Diffstat (limited to 'src/main/java/com/google/devtools')
26 files changed, 300 insertions, 143 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/Constants.java b/src/main/java/com/google/devtools/build/lib/Constants.java index 176a9f4786..d4d643662f 100644 --- a/src/main/java/com/google/devtools/build/lib/Constants.java +++ b/src/main/java/com/google/devtools/build/lib/Constants.java @@ -38,6 +38,7 @@ public class Constants { public static final ImmutableList<String> ANDROID_DEFAULT_FAT_APK_CPUS = ImmutableList.<String>of("armeabi-v7a"); public static final String ANDROID_DEP_PREFIX = "//external:android/".toString(); + public static final String TOOLS_REPOSITORY = "".toString(); /** * Whether C++ include scanning should be disabled no matter what the --cc_include_scanning flag diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java index 1ab037c167..154c41f595 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java @@ -28,6 +28,7 @@ import static com.google.devtools.build.lib.syntax.Type.STRING; import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.RunUnder; import com.google.devtools.build.lib.analysis.constraints.EnvironmentRule; @@ -55,7 +56,7 @@ public class BaseRuleClasses { * for running tests in coverage mode. */ private static final Label COVERAGE_SUPPORT_LABEL = - Label.parseAbsoluteUnchecked("//tools/defaults:coverage"); + Label.parseAbsoluteUnchecked(Constants.TOOLS_REPOSITORY + "//tools/defaults:coverage"); private static final Attribute.ComputedDefault testonlyDefault = new Attribute.ComputedDefault() { @@ -162,7 +163,7 @@ public class BaseRuleClasses { .add(attr("args", STRING_LIST) .nonconfigurable("policy decision: should be consistent across configurations")) .add(attr("$test_runtime", LABEL_LIST).cfg(HOST).value(ImmutableList.of( - env.getLabel("//tools/test:runtime")))) + env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/test:runtime")))) // TODO(bazel-team): TestActions may need to be run with coverage, so all tests // implicitly depend on crosstool, which provides gcov. We could add gcov to diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java index 52276512a8..c460e3dd84 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java @@ -280,23 +280,50 @@ public final class BuildConfiguration { } } + private static final Label convertLabel(String input) throws OptionsParsingException { + try { + // Check if the input starts with '/'. We don't check for "//" so that + // we get a better error message if the user accidentally tries to use + // an absolute path (starting with '/') for a label. + if (!input.startsWith("/") && !input.startsWith("@")) { + input = "//" + input; + } + return Label.parseAbsolute(input); + } catch (LabelSyntaxException e) { + throw new OptionsParsingException(e.getMessage()); + } + } + /** * A converter from strings to Labels. */ public static class LabelConverter implements Converter<Label> { @Override public Label convert(String input) throws OptionsParsingException { - try { - // Check if the input starts with '/'. We don't check for "//" so that - // we get a better error message if the user accidentally tries to use - // an absolute path (starting with '/') for a label. - if (!input.startsWith("/") && !input.startsWith("@")) { - input = "//" + input; - } - return Label.parseAbsolute(input); - } catch (LabelSyntaxException e) { - throw new OptionsParsingException(e.getMessage()); - } + return convertLabel(input); + } + + @Override + public String getTypeDescription() { + return "a build target label"; + } + } + + /** + * A label converter that returns a default value if the input string is empty. + */ + public static class DefaultLabelConverter implements Converter<Label> { + private final Label defaultValue; + + protected DefaultLabelConverter(String defaultValue) { + this.defaultValue = defaultValue.equals("null") + ? null + : Label.parseAbsoluteUnchecked(defaultValue); + } + + @Override + public Label convert(String input) throws OptionsParsingException { + return input.isEmpty() ? defaultValue : convertLabel(input); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java index 1974a24085..c4a5dca0ef 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java @@ -93,7 +93,8 @@ public final class FetchCommand implements BlazeCommand { JavaOptions javaOptions = options.getOptions(JavaOptions.class); ImmutableList.Builder<String> labelsToLoad = new ImmutableList.Builder<String>() .addAll(options.getResidue()); - if (String.valueOf(javaOptions.javaLangtoolsJar).equals(JavaOptions.DEFAULT_LANGTOOLS)) { + if (String.valueOf(javaOptions.javaLangtoolsJar).equals( + Constants.TOOLS_REPOSITORY + JavaOptions.DEFAULT_LANGTOOLS)) { labelsToLoad.add(javaOptions.javaBase); } else { // TODO(kchodroow): Remove this when OS X isn't as hacky about finding the JVM. Our test diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java index 732c48626c..582a5b14eb 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java @@ -62,8 +62,8 @@ public class AndroidRepositoryRules { public Map<String, Label> apply(Rule rule) { ImmutableMap.Builder<String, Label> result = ImmutableMap.builder(); for (String tool : TOOLS) { - result.put("android/" + tool, - Label.parseAbsoluteUnchecked("@" + rule.getName() + "//tools/android:" + tool)); + result.put("android/" + tool, Label.parseAbsoluteUnchecked( + "@" + rule.getName() + "//tools/android:" + tool)); } return result.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 aa8bfead1f..60618ff18d 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 @@ -39,6 +39,7 @@ import static com.google.devtools.build.lib.syntax.Type.STRING; import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.base.Predicates; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -152,7 +153,8 @@ public class BazelCppRuleClasses { * 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 = + Constants.TOOLS_REPOSITORY + "//tools/defaults:crosstool"; public static final LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN = new LateBoundLabel<BuildConfiguration>(CROSSTOOL_LABEL) { @@ -258,7 +260,8 @@ public class BazelCppRuleClasses { so be careful about header files included elsewhere.</p> <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add(attr("copts", STRING_LIST)) - .add(attr("$stl", LABEL).value(env.getLabel("//tools/cpp:stl"))) + .add(attr("$stl", LABEL).value( + env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl"))) .add(attr(":stl", LABEL).value(STL)) .build(); } @@ -565,7 +568,7 @@ public class BazelCppRuleClasses { // Every cc_rule depends implicitly on STL to make // sure that the correct headers are used for inclusion. The only exception is // STL itself to avoid cycles in the dependency graph. - Label stl = env.getLabel("//tools/cpp:stl"); + Label stl = env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl"); return rule.getLabel().equals(stl) ? null : stl; } })) @@ -600,7 +603,7 @@ public class BazelCppRuleClasses { </p> <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add(attr("malloc", LABEL) - .value(env.getLabel("//tools/cpp:malloc")) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:malloc")) .allowedFileTypes() .allowedRuleClasses("cc_library")) .add(attr(":default_malloc", LABEL).value(DEFAULT_MALLOC)) 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 3d6f3ea0fe..820d5d75b5 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 @@ -22,6 +22,7 @@ import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST; import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; import static com.google.devtools.build.lib.syntax.Type.STRING; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -35,7 +36,8 @@ import com.google.devtools.build.lib.packages.RuleClass.Builder; * Rule definition for the genrule rule. */ public final class BazelGenRuleRule implements RuleDefinition { - public static final String GENRULE_SETUP_LABEL = "//tools/genrule:genrule-setup.sh"; + public static final String GENRULE_SETUP_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/genrule:genrule-setup.sh"; @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { 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 46048876da..5cd576f567 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 @@ -25,6 +25,7 @@ import static com.google.devtools.build.lib.syntax.Type.STRING; import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -69,7 +70,8 @@ public class BazelJavaRuleClasses { @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder - .add(attr("$ijar", LABEL).cfg(HOST).exec().value(env.getLabel("//tools/defaults:ijar"))) + .add(attr("$ijar", LABEL).cfg(HOST).exec().value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/defaults:ijar"))) .setPreferredDependencyPredicate(JavaSemantics.JAVA_SOURCE) .build(); } @@ -97,7 +99,7 @@ public class BazelJavaRuleClasses { .add(attr("$javac_extdir", LABEL).cfg(HOST) .value(env.getLabel(JavaSemantics.JAVAC_EXTDIR_LABEL))) .add(attr("$java_langtools", LABEL).cfg(HOST) - .value(env.getLabel("//tools/defaults:java_langtools"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/defaults:java_langtools"))) .add(attr("$javac_bootclasspath", LABEL).cfg(HOST) .value(env.getLabel(JavaSemantics.JAVAC_BOOTCLASSPATH_LABEL))) .add(attr("$javabuilder", LABEL).cfg(HOST) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java index f263cf4318..0182a5370e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java @@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -64,7 +65,8 @@ public final class BazelIosTestRule implements RuleDefinition { attr(IosTest.TARGET_DEVICE, LABEL) .allowedFileTypes() .allowedRuleClasses("ios_device") - .value(env.getLabel("//tools/objc/sim_devices:default"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc/sim_devices:default"))) /* <!-- #BLAZE_RULE(ios_test).ATTRIBUTE(ios_test_target_device) --> The device against how to run the test. If this attribute is defined, the test will run on the lab device. Otherwise, the test will run on simulator. @@ -87,8 +89,10 @@ public final class BazelIosTestRule implements RuleDefinition { <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add(attr("plugins", LABEL_LIST).allowedFileTypes(FileType.of("_deploy.jar"))) .add(attr("$test_template", LABEL) - .value(env.getLabel("//tools/objc:ios_test.sh.bazel_template"))) - .add(attr("$test_runner", LABEL).value(env.getLabel("//tools/objc:testrunner"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:ios_test.sh.bazel_template"))) + .add(attr("$test_runner", LABEL) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:testrunner"))) .override(attr(":gcov", LABEL_LIST).cfg(HOST) .value(new LateBoundLabelList<BuildConfiguration>() { @Override diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java index f3889fbaea..7c1e06ecc5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java @@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; import static com.google.devtools.build.lib.packages.BuildType.TRISTATE; import static com.google.devtools.build.lib.syntax.Type.STRING; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -84,7 +85,7 @@ public final class BazelPyRuleClasses { // do not depend on lib2to3:2to3 rule, because it creates circular dependencies // 2to3 is itself written in Python and depends on many libraries. .add(attr("$python2to3", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/python:2to3"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/python:2to3"))) .setPreferredDependencyPredicate(PyRuleClasses.PYTHON_SOURCE) .build(); } 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 b083cbf835..87b570318c 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 @@ -35,6 +35,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.RunUnder; @@ -167,7 +168,7 @@ public class SkylarkRuleClassFunctions { .add(attr("args", STRING_LIST) .nonconfigurable("policy decision: should be consistent across configurations")) .add(attr("$test_runtime", LABEL_LIST).cfg(HOST).value(ImmutableList.of( - labelCache.getUnchecked("//tools/test:runtime")))) + labelCache.getUnchecked(Constants.TOOLS_REPOSITORY + "//tools/test:runtime")))) .add(attr(":run_under", LABEL).cfg(DATA).value(RUN_UNDER)) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java index 7f63829480..79bf08a98e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration.DefaultLabelConverter; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelConverter; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsConverter; @@ -40,6 +41,21 @@ import java.util.List; * Configuration fragment for Android rules. */ public class AndroidConfiguration extends BuildConfiguration.Fragment { + + /** Converter for --android_crosstool_top. */ + public static class AndroidCrosstoolTopConverter extends DefaultLabelConverter { + public AndroidCrosstoolTopConverter() { + super(Constants.ANDROID_DEFAULT_CROSSTOOL); + } + } + + /** Converter for --android_sdk. */ + public static class AndroidSdkConverter extends DefaultLabelConverter { + public AndroidSdkConverter() { + super(Constants.ANDROID_DEFAULT_SDK); + } + } + /** * Value used to avoid multiple configurations from conflicting. * @@ -92,9 +108,9 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { public boolean incrementalNativeLibs; @Option(name = "android_crosstool_top", - defaultValue = "null", + defaultValue = "", category = "semantics", - converter = LabelConverter.class, + converter = AndroidCrosstoolTopConverter.class, help = "The location of the C++ compiler used for Android builds.") public Label androidCrosstoolTop; @@ -116,9 +132,9 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { // Label of filegroup combining all Android tools used as implicit dependencies of // android_* rules @Option(name = "android_sdk", - defaultValue = "null", + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = AndroidSdkConverter.class, help = "Specifies Android SDK/platform that is used to build Android applications.") public Label sdk; @@ -177,37 +193,16 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { labelMap.put("android_proguard", proguard); } - if (realAndroidCrosstoolTop() != null) { - labelMap.put("android_crosstool_top", realAndroidCrosstoolTop()); - } - - labelMap.put("android_sdk", realSdk()); - } - - // This method is here because Constants.ANDROID_DEFAULT_SDK cannot be a constant, because we - // replace the class file in the .jar after compilation. However, that means that we cannot use - // it as an attribute value in an annotation. - private Label realSdk() { - return sdk == null - ? Label.parseAbsoluteUnchecked(Constants.ANDROID_DEFAULT_SDK) - : sdk; - } - - // This method is here because Constants.ANDROID_DEFAULT_CROSSTOOL cannot be a constant, because - // we replace the class file in the .jar after compilation. However, that means that we cannot - // use it as an attribute value in an annotation. - public Label realAndroidCrosstoolTop() { if (androidCrosstoolTop != null) { - return androidCrosstoolTop; - } - - if (Constants.ANDROID_DEFAULT_CROSSTOOL.equals("null")) { - return null; + labelMap.put("android_crosstool_top", androidCrosstoolTop); } - return Label.parseAbsoluteUnchecked(Constants.ANDROID_DEFAULT_CROSSTOOL); + labelMap.put("android_sdk", sdk); } + // This method is here because Constants.ANDROID_DEFAULT_FAT_APK_CPUS cannot be a constant + // because we replace the class file in the .jar after compilation. However, that means that we + // cannot use it as an attribute value in an annotation. public List<String> realFatApkCpus() { if (fatApkCpus.isEmpty()) { return Constants.ANDROID_DEFAULT_FAT_APK_CPUS; @@ -260,7 +255,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final boolean jackSanityChecks; AndroidConfiguration(Options options) { - this.sdk = options.realSdk(); + this.sdk = options.sdk; this.incrementalNativeLibs = options.incrementalNativeLibs; this.strictDeps = options.strictDeps; this.legacyNativeSupport = options.legacyNativeSupport; diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java index c1e14989a3..3a1a376f02 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java @@ -180,12 +180,12 @@ public final class AndroidRuleClasses { output.get(AndroidConfiguration.Options.class); CppOptions cppOptions = output.get(CppOptions.class); - if (inputAndroidOptions.realAndroidCrosstoolTop() != null - && !cppOptions.crosstoolTop.equals(inputAndroidOptions.realAndroidCrosstoolTop())) { + if (inputAndroidOptions.androidCrosstoolTop != null + && !cppOptions.crosstoolTop().equals(inputAndroidOptions.androidCrosstoolTop)) { if (cppOptions.hostCrosstoolTop == null) { cppOptions.hostCrosstoolTop = cppOptions.crosstoolTop; } - cppOptions.crosstoolTop = inputAndroidOptions.realAndroidCrosstoolTop(); + cppOptions.crosstoolTop = inputAndroidOptions.androidCrosstoolTop; } outputAndroidOptions.configurationDistinguisher = ConfigurationDistinguisher.ANDROID; @@ -196,9 +196,10 @@ public final class AndroidRuleClasses { AndroidConfiguration.Options androidOptions = buildOptions.get(AndroidConfiguration.Options.class); CppOptions cppOptions = buildOptions.get(CppOptions.class); - Label androidCrosstoolTop = androidOptions.realAndroidCrosstoolTop(); + Label androidCrosstoolTop = androidOptions.androidCrosstoolTop; if (androidOptions.realFatApkCpus().isEmpty() - && (androidCrosstoolTop == null || androidCrosstoolTop.equals(cppOptions.crosstoolTop))) { + && (androidCrosstoolTop == null + || androidCrosstoolTop.equals(cppOptions.crosstoolTop()))) { return ImmutableList.of(); } @@ -330,7 +331,8 @@ public final class AndroidRuleClasses { .allowedFileTypes(ANY_FILE) // TODO(bazel-team): Remove defaults and make mandatory when android_sdk targets // have been updated to include manually specified Jack attributes. - .value(environment.getLabel("//tools/android/jack:android_jack"))) + .value(environment.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/android/jack:android_jack"))) .add(attr("annotations_jar", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE)) .add(attr("main_dex_classes", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE)) .add(attr("apkbuilder", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec()) @@ -340,19 +342,22 @@ public final class AndroidRuleClasses { .cfg(HOST) .allowedFileTypes(ANY_FILE) .exec() - .value(environment.getLabel("//tools/android/jack:jack"))) + .value(environment.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/android/jack:jack"))) .add( attr("jill", LABEL) .cfg(HOST) .allowedFileTypes(ANY_FILE) .exec() - .value(environment.getLabel("//tools/android/jack:jill"))) + .value(environment.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/android/jack:jill"))) .add( attr("resource_extractor", LABEL) .cfg(HOST) .allowedFileTypes(ANY_FILE) .exec() - .value(environment.getLabel("//tools/android/jack:resource_extractor"))) + .value(environment.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/android/jack:resource_extractor"))) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java index a68b800bd4..3604f58115 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java @@ -119,7 +119,7 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory { return null; } Label crosstoolTopLabel = RedirectChaser.followRedirects(env, - options.get(CppOptions.class).crosstoolTop, "crosstool_top"); + options.get(CppOptions.class).crosstoolTop(), "crosstool_top"); if (crosstoolTopLabel == null) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java index 6c550d0f9c..e76fb265bb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelConverter; import com.google.devtools.build.lib.analysis.config.CompilationMode; @@ -170,7 +171,7 @@ public class CppOptions extends FragmentOptions { public boolean lipoCollector; @Option(name = "crosstool_top", - defaultValue = CppOptions.DEFAULT_CROSSTOOL_TARGET, + defaultValue = "null", category = "version", converter = LabelConverter.class, help = "The label of the crosstool package to be used for compiling C++ code.") @@ -502,6 +503,12 @@ public class CppOptions extends FragmentOptions { + "will be shared among different targets") public boolean shareNativeDeps; + public Label crosstoolTop() { + return crosstoolTop == null + ? Label.parseAbsoluteUnchecked(Constants.TOOLS_REPOSITORY + DEFAULT_CROSSTOOL_TARGET) + : crosstoolTop; + } + @Override public FragmentOptions getHost(boolean fallback) { CppOptions host = (CppOptions) getDefault(); @@ -544,7 +551,7 @@ public class CppOptions extends FragmentOptions { @Override public void addAllLabels(Multimap<String, Label> labelMap) { - labelMap.put("crosstool", crosstoolTop); + labelMap.put("crosstool", crosstoolTop()); if (hostCrosstoolTop != null) { labelMap.put("crosstool", hostCrosstoolTop); } @@ -573,7 +580,7 @@ public class CppOptions extends FragmentOptions { @Override public Map<String, Set<Label>> getDefaultsLabels(BuildConfiguration.Options commonOptions) { Set<Label> crosstoolLabels = new LinkedHashSet<>(); - crosstoolLabels.add(crosstoolTop); + crosstoolLabels.add(crosstoolTop()); if (hostCrosstoolTop != null) { crosstoolLabels.add(hostCrosstoolTop); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java index 361e95f505..633439d4d5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java @@ -16,7 +16,9 @@ package com.google.devtools.build.lib.rules.java; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration.DefaultLabelConverter; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelConverter; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsConverter; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsMode; @@ -25,9 +27,11 @@ import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaClasspathMode; +import com.google.devtools.common.options.Converter; import com.google.devtools.common.options.Converters.StringSetConverter; import com.google.devtools.common.options.EnumConverter; import com.google.devtools.common.options.Option; +import com.google.devtools.common.options.OptionsParsingException; import com.google.devtools.common.options.TriState; import java.util.HashMap; @@ -40,16 +44,77 @@ import java.util.Set; * Command-line options for building Java targets */ public class JavaOptions extends FragmentOptions { - // Defaults value for options public static final String DEFAULT_LANGTOOLS = "//tools/jdk:langtools"; - static final String DEFAULT_LANGTOOLS_BOOTCLASSPATH = "//tools/jdk:bootclasspath"; - static final String DEFAULT_LANGTOOLS_EXTDIR = "//tools/jdk:extdir"; - static final String DEFAULT_JAVABUILDER = "//tools/jdk:JavaBuilder_deploy.jar"; - static final String DEFAULT_SINGLEJAR = "//tools/jdk:SingleJar_deploy.jar"; - static final String DEFAULT_GENCLASS = "//tools/jdk:GenClass_deploy.jar"; - static final String DEFAULT_JAVABASE = "//tools/jdk:jdk"; - static final String DEFAULT_IJAR = "//tools/jdk:ijar"; - static final String DEFAULT_TOOLCHAIN = "//tools/jdk:toolchain"; + + /** Converter for --javabase and --host_javabase. */ + public static class JavabaseConverter implements Converter<String> { + @Override + public String convert(String input) throws OptionsParsingException { + return input.isEmpty() ? Constants.TOOLS_REPOSITORY + "//tools/jdk:jdk" : input; + } + + @Override + public String getTypeDescription() { + return "a string"; + } + } + + /** Converter for --java_langtools. */ + public static class LangtoolsConverter extends DefaultLabelConverter { + public LangtoolsConverter() { + super(Constants.TOOLS_REPOSITORY + DEFAULT_LANGTOOLS); + } + } + + /** Converter for --javac_bootclasspath. */ + public static class BootclasspathConverter extends DefaultLabelConverter { + public BootclasspathConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:bootclasspath"); + } + } + + /** Converter for --javac_extdir. */ + public static class ExtdirConverter extends DefaultLabelConverter { + public ExtdirConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:extdir"); + } + } + + /** Converter for --javabuilder_top. */ + public static class JavaBuilderConverter extends DefaultLabelConverter { + public JavaBuilderConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:JavaBuilder_deploy.jar"); + } + } + + + /** Converter for --singlejar_top. */ + public static class SingleJarConverter extends DefaultLabelConverter { + public SingleJarConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:SingleJar_deploy.jar"); + } + } + + /** Converter for --genclass_top. */ + public static class GenClassConverter extends DefaultLabelConverter { + public GenClassConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:GenClass_deploy.jar"); + } + } + + /** Converter for --ijar_top. */ + public static class IjarConverter extends DefaultLabelConverter { + public IjarConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:ijar"); + } + } + + /** Converter for --java_toolchain. */ + public static class JavaToolchainConverter extends DefaultLabelConverter { + public JavaToolchainConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/jdk:toolchain"); + } + } /** * Converter for the --javawarn option. @@ -98,7 +163,8 @@ public class JavaOptions extends FragmentOptions { } @Option(name = "javabase", - defaultValue = DEFAULT_JAVABASE, + defaultValue = "", + converter = JavabaseConverter.class, category = "version", help = "JAVABASE used for the JDK invoked by Blaze. This is the " + "JAVABASE which will be used to execute external Java " @@ -106,17 +172,18 @@ public class JavaOptions extends FragmentOptions { public String javaBase; @Option(name = "java_toolchain", - defaultValue = DEFAULT_TOOLCHAIN, + defaultValue = "", category = "version", - converter = LabelConverter.class, - help = "The name of the toolchain rule for Java. Default is " + DEFAULT_TOOLCHAIN) + converter = JavaToolchainConverter.class, + help = "The name of the toolchain rule for Java.") public Label javaToolchain; @Option(name = "host_javabase", - defaultValue = DEFAULT_JAVABASE, - category = "version", - help = "JAVABASE used for the host JDK. This is the JAVABASE which is used to execute " - + " tools during a build.") + defaultValue = "", + converter = JavabaseConverter.class, + category = "version", + help = "JAVABASE used for the host JDK. This is the JAVABASE which is used to execute " + + " tools during a build.") public String hostJavaBase; @Option(name = "javacopt", @@ -206,9 +273,9 @@ public class JavaOptions extends FragmentOptions { public StrictDepsMode strictJavaDeps; @Option(name = "javabuilder_top", - defaultValue = DEFAULT_JAVABUILDER, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = JavaBuilderConverter.class, help = "Label of the filegroup that contains the JavaBuilder jar.") public Label javaBuilderTop; @@ -220,44 +287,44 @@ public class JavaOptions extends FragmentOptions { public List<String> javaBuilderJvmOpts; @Option(name = "singlejar_top", - defaultValue = DEFAULT_SINGLEJAR, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = SingleJarConverter.class, help = "Label of the filegroup that contains the SingleJar jar.") public Label singleJarTop; @Option(name = "genclass_top", - defaultValue = DEFAULT_GENCLASS, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = GenClassConverter.class, help = "Label of the filegroup that contains the GenClass jar.") public Label genClassTop; @Option(name = "ijar_top", - defaultValue = DEFAULT_IJAR, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = IjarConverter.class, help = "Label of the filegroup that contains the ijar binary.") public Label iJarTop; @Option(name = "java_langtools", - defaultValue = DEFAULT_LANGTOOLS, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = LangtoolsConverter.class, help = "Label of the rule that produces the Java langtools jar.") public Label javaLangtoolsJar; @Option(name = "javac_bootclasspath", - defaultValue = DEFAULT_LANGTOOLS_BOOTCLASSPATH, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = BootclasspathConverter.class, help = "Label of the rule that produces the bootclasspath jars for javac to use.") public Label javacBootclasspath; @Option(name = "javac_extdir", - defaultValue = DEFAULT_LANGTOOLS_EXTDIR, + defaultValue = "", category = "version", - converter = LabelConverter.class, + converter = ExtdirConverter.class, help = "Label of the rule that produces the extdir for javac to use.") public Label javacExtdir; 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 d616d2af66..a75b414ef1 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 @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fro import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.LanguageDependentFragment.LibraryLanguage; import com.google.devtools.build.lib.analysis.OutputGroupProvider; @@ -79,7 +80,8 @@ public interface JavaSemantics { /** * Label to the Java Toolchain rule. It is resolved from a label given in the java options. */ - static final String JAVA_TOOLCHAIN_LABEL = "//tools/defaults:java_toolchain"; + static final String JAVA_TOOLCHAIN_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/defaults:java_toolchain"; public static final LateBoundLabel<BuildConfiguration> JAVA_TOOLCHAIN = new LateBoundLabel<BuildConfiguration>(JAVA_TOOLCHAIN_LABEL, JavaConfiguration.class) { @@ -106,33 +108,39 @@ public interface JavaSemantics { * 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 = + Constants.TOOLS_REPOSITORY + "//tools/defaults:jdk"; /** * Label of a pseudo-filegroup that contains the boot-classpath entries. */ - public static final String JAVAC_BOOTCLASSPATH_LABEL = "//tools/defaults:javac_bootclasspath"; + public static final String JAVAC_BOOTCLASSPATH_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/defaults:javac_bootclasspath"; /** * Label of the javac extdir used for compiling Java source code. */ - public static final String JAVAC_EXTDIR_LABEL = "//tools/defaults:javac_extdir"; + public static final String JAVAC_EXTDIR_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/defaults:javac_extdir"; /** * Label of the JavaBuilder JAR used for compiling Java source code. */ - public static final String JAVABUILDER_LABEL = "//tools/defaults:javabuilder"; + public static final String JAVABUILDER_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/defaults:javabuilder"; /** * Label of the SingleJar JAR used for creating deploy jars. */ - public static final String SINGLEJAR_LABEL = "//tools/defaults:singlejar"; + public static final String SINGLEJAR_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/defaults:singlejar"; /** * Label of the GenClass JAR used for creating the jar for classes from sources generated from * annotation processors. */ - public static final String GENCLASS_LABEL = "//tools/defaults:genclass"; + public static final String GENCLASS_LABEL = + Constants.TOOLS_REPOSITORY + "//tools/defaults:genclass"; /** * Label of pseudo-cc_binary that tells Blaze a java target's JAVABIN is never to be replaced by @@ -188,7 +196,7 @@ public interface JavaSemantics { } }; - public static final String IJAR_LABEL = "//tools/defaults:ijar"; + public static final String IJAR_LABEL = Constants.TOOLS_REPOSITORY + "//tools/defaults:ijar"; /** * Verifies if the rule contains and errors. diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java index 8d692e562c..2da029c7ad 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcProtoAspect.java @@ -19,6 +19,7 @@ import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; @@ -42,11 +43,11 @@ public class BazelJ2ObjcProtoAspect extends AbstractJ2ObjcProtoAspect { .add(attr("$protoc_darwin", LABEL) .cfg(HOST) .exec() - .value(parseLabel("//tools/objc:compile_protos"))) + .value(parseLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:compile_protos"))) .add(attr("$protoc_support_darwin", LABEL) .cfg(HOST) .exec() - .value(parseLabel("//tools/objc:proto_support"))) + .value(parseLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:proto_support"))) .add(attr("$j2objc_plugin", LABEL) .cfg(HOST) .exec() diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java index a7b81dcc07..1769a9c05b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java @@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -62,7 +63,8 @@ public final class ExperimentalIosTestRule implements RuleDefinition { attr(IosTest.TARGET_DEVICE, LABEL) .allowedFileTypes() .allowedRuleClasses("ios_device") - .value(env.getLabel("//tools/objc/sim_devices:default"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc/sim_devices:default"))) /* <!-- #BLAZE_RULE(experimental_ios_test).ATTRIBUTE(ios_test_target_device) --> The device against how to run the test. If this attribute is defined, the test will run on the lab device. Otherwise, the test will run on simulator. @@ -85,8 +87,10 @@ public final class ExperimentalIosTestRule implements RuleDefinition { <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ .add(attr("plugins", LABEL_LIST).allowedFileTypes(FileType.of("_deploy.jar"))) .add(attr("$test_template", LABEL) - .value(env.getLabel("//tools/objc:ios_test.sh.bazel_template"))) - .add(attr("$test_runner", LABEL).value(env.getLabel("//tools/objc:testrunner"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:ios_test.sh.bazel_template"))) + .add(attr("$test_runner", LABEL).value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:testrunner"))) .override(attr(":gcov", LABEL_LIST).cfg(HOST) .value(new LateBoundLabelList<BuildConfiguration>() { @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java index 363219f0f8..f25d457176 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java @@ -20,6 +20,7 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL; import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -65,7 +66,8 @@ public class IosApplicationRule implements RuleDefinition { .allowedFileTypes() .direct_compile_time_input()) .add(attr("$runner_script_template", LABEL).cfg(HOST) - .value(env.getLabel("//tools/objc:ios_runner.sh.mac_template"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:ios_runner.sh.mac_template"))) .add(attr("$is_executable", BOOLEAN).value(true) .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java index 4a6a7f182f..f6a527bde6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java @@ -21,6 +21,7 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ParameterFile; import com.google.devtools.build.lib.analysis.Aspect; @@ -70,13 +71,13 @@ public class J2ObjcAspect implements ConfiguredAspectFactory { .requireProvider(JavaSourceInfoProvider.class) .requireProvider(JavaCompilationArgsProvider.class) .add(attr("$j2objc", LABEL).cfg(HOST).exec() - .value(parseLabel("//tools/j2objc:j2objc_deploy.jar"))) + .value(parseLabel(Constants.TOOLS_REPOSITORY + "//tools/j2objc:j2objc_deploy.jar"))) .add(attr("$j2objc_wrapper", LABEL) .allowedFileTypes(FileType.of(".py")) .cfg(HOST) .exec() .singleArtifact() - .value(parseLabel("//tools/j2objc:j2objc_wrapper"))) + .value(parseLabel(Constants.TOOLS_REPOSITORY + "//tools/j2objc:j2objc_wrapper"))) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java index bb34419929..deeb5aca5f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java @@ -19,6 +19,7 @@ import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -49,7 +50,8 @@ public class ObjcBinaryRule implements RuleDefinition { ImplicitOutputsFunction.fromFunctions(ReleaseBundlingSupport.IPA, XcodeSupport.PBXPROJ)) // TODO(bazel-team): Remove these when this rule no longer produces a bundle. .add(attr("$runner_script_template", LABEL).cfg(HOST) - .value(env.getLabel("//tools/objc:ios_runner.sh.mac_template"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:ios_runner.sh.mac_template"))) .add(attr("$is_executable", BOOLEAN).value(true) .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java index f88ce4fbdb..d30cc92cdb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java @@ -17,7 +17,8 @@ package com.google.devtools.build.lib.rules.objc; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelConverter; +import com.google.devtools.build.lib.Constants; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration.DefaultLabelConverter; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.cmdline.Label; @@ -33,6 +34,20 @@ import java.util.List; * Command-line options for building Objective-C targets. */ public class ObjcCommandLineOptions extends FragmentOptions { + /** Converter for --objc_dump_syms_binary. */ + public static class DumpSymsConverter extends DefaultLabelConverter { + public DumpSymsConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/objc:dump_syms"); + } + } + + /** Converter for --default_ios_provisioning_profile. */ + public static class DefaultProvisioningProfileConverter extends DefaultLabelConverter { + public DefaultProvisioningProfileConverter() { + super(Constants.TOOLS_REPOSITORY + "//tools/objc:default_provisioning_profile"); + } + } + // TODO(cparsons): Validate version flag value. @Option(name = "xcode_version", defaultValue = "", @@ -114,15 +129,15 @@ public class ObjcCommandLineOptions extends FragmentOptions { public String iosSplitCpu; @Option(name = "objc_dump_syms_binary", - defaultValue = "//tools/objc:dump_syms", + defaultValue = "", category = "undocumented", - converter = LabelConverter.class) + converter = DumpSymsConverter.class) public Label dumpSyms; @Option(name = "default_ios_provisiong_profile", - defaultValue = "//tools/objc:default_provisioning_profile", + defaultValue = "", category = "undocumented", - converter = LabelConverter.class) + converter = DefaultProvisioningProfileConverter.class) public Label defaultProvisioningProfile; @Option(name = "objc_per_proto_includes", @@ -206,6 +221,7 @@ public class ObjcCommandLineOptions extends FragmentOptions { IosApplication.SPLIT_ARCH_TRANSITION, IosExtension.MINIMUM_OS_AND_SPLIT_ARCH_TRANSITION); } + /** Converter for the iOS configuration distinguisher. */ public static final class ConfigurationDistinguisherConverter extends EnumConverter<ConfigurationDistinguisher> { public ConfigurationDistinguisherConverter() { diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java index 1374c35d79..03ea73d953 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java @@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL; import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; @@ -81,11 +82,11 @@ public class ObjcProtoLibraryRule implements RuleDefinition { .allowedFileTypes(FileType.of(".py")) .cfg(HOST) .singleArtifact() - .value(env.getLabel("//tools/objc:compile_protos"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:compile_protos"))) .add(attr(PROTO_SUPPORT_ATTR, LABEL) .legacyAllowAnyFileType() .cfg(HOST) - .value(env.getLabel("//tools/objc:proto_support"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:proto_support"))) .add(attr(USE_OBJC_HEADER_NAMES_ATTR, BOOLEAN).value(false)) .add(attr(LIBPROTOBUF_ATTR, LABEL).allowedRuleClasses("objc_library") .value(new ComputedDefault(OUTPUT_CPP_ATTR) { @@ -97,7 +98,7 @@ public class ObjcProtoLibraryRule implements RuleDefinition { } })) .add(attr("$xcodegen", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:xcodegen"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:xcodegen"))) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java index e21a9755d5..082603d5a9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java @@ -26,6 +26,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; @@ -497,15 +498,15 @@ public class ObjcRuleClasses { public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder .add(attr("$plmerge", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:plmerge"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:plmerge"))) .add(attr("$actoolwrapper", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:actoolwrapper"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:actoolwrapper"))) .add(attr("$ibtoolwrapper", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:ibtoolwrapper"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:ibtoolwrapper"))) // TODO(dmaclach): Adding realpath here should not be required once // https://github.com/bazelbuild/bazel/issues/285 is fixed. .add(attr("$realpath", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:realpath"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:realpath"))) .build(); } @Override @@ -525,9 +526,9 @@ public class ObjcRuleClasses { public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder .add(attr("$xcodegen", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:xcodegen"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:xcodegen"))) .add(attr("$dummy_source", LABEL) - .value(env.getLabel("//tools/objc:dummy.c"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:dummy.c"))) .build(); } @Override @@ -771,7 +772,8 @@ public class ObjcRuleClasses { .cfg(HOST) .exec() .singleArtifact() - .value(env.getLabel("//tools/objc:j2objc_dead_code_pruner"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:j2objc_dead_code_pruner"))) .build(); } @Override @@ -818,7 +820,7 @@ public class ObjcRuleClasses { @Override public Object getDefault(AttributeMap rule) { return rule.get(IosTest.IS_XCTEST, Type.BOOLEAN) - ? env.getLabel("//tools/objc:xctest_app") + ? env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:xctest_app") : null; } }) @@ -832,7 +834,8 @@ public class ObjcRuleClasses { @Override public Object getDefault(AttributeMap rule) { return rule.get(IosTest.IS_XCTEST, Type.BOOLEAN) - ? env.getLabel("//tools/objc:xctest_infoplist") + ? env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:xctest_infoplist") : null; } }) @@ -890,9 +893,10 @@ public class ObjcRuleClasses { .add(attr("families", STRING_LIST) .value(ImmutableList.of(TargetDeviceFamily.IPHONE.getNameInRule()))) .add(attr("$momcwrapper", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:momcwrapper"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:momcwrapper"))) .add(attr("$swiftstdlibtoolwrapper", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:swiftstdlibtoolwrapper"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:swiftstdlibtoolwrapper"))) .build(); } @Override @@ -997,9 +1001,10 @@ public class ObjcRuleClasses { } })) .add(attr("$bundlemerge", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:bundlemerge"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:bundlemerge"))) .add(attr("$environment_plist_sh", LABEL).cfg(HOST) - .value(env.getLabel("//tools/objc:environment_plist.sh"))) + .value(env.getLabel( + Constants.TOOLS_REPOSITORY + "//tools/objc:environment_plist.sh"))) .build(); } @Override @@ -1023,7 +1028,7 @@ public class ObjcRuleClasses { .add(attr("$iossim", LABEL).cfg(HOST).exec() .value(env.getLabel("//third_party/iossim:iossim"))) .add(attr("$std_redirect_dylib", LABEL).cfg(HOST).exec() - .value(env.getLabel("//tools/objc:StdRedirect.dylib"))) + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:StdRedirect.dylib"))) .build(); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java index 2599cb139d..917576d879 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java @@ -67,7 +67,7 @@ public class PythonConfigurationLoader implements ConfigurationFragmentFactory { } CrosstoolConfig.CToolchain toolchain = getToolchain( - env, buildOptions, buildOptions.get(CppOptions.class).crosstoolTop); + env, buildOptions, buildOptions.get(CppOptions.class).crosstoolTop()); if (toolchain == null) { return null; } |