From 90511e17dcb663076403094b307130a24d698603 Mon Sep 17 00:00:00 2001 From: Luis Fernando Pino Duque Date: Thu, 28 Jan 2016 10:49:58 +0000 Subject: Inject the TOOLS_REPOSITORY constant in the RuleClassProvider instead of using Constants.java It also includes one example on how to use the new mechanism in BazelCppRuleClasses. This is the first phase for the removal of the TOOLS_REPOSITORY constant. -- MOS_MIGRATED_REVID=113244399 --- .../lib/analysis/ConfiguredRuleClassProvider.java | 24 ++++++++++++++++++++++ .../lib/analysis/RuleDefinitionEnvironment.java | 5 +++++ .../lib/bazel/rules/BazelRuleClassProvider.java | 1 + .../lib/bazel/rules/cpp/BazelCppRuleClasses.java | 7 +++---- .../build/lib/packages/RuleClassProvider.java | 5 +++++ 5 files changed, 38 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java index ab0a534622..746eb9e6d7 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java @@ -85,6 +85,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { private final StringBuilder defaultWorkspaceFile = new StringBuilder(); private Label preludeLabel; private String runfilesPrefix; + private String toolsRepository; private final List configurationFragments = new ArrayList<>(); private final List buildInfoFactories = new ArrayList<>(); private final List> configurationOptions = new ArrayList<>(); @@ -129,6 +130,11 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { this.runfilesPrefix = runfilesPrefix; return this; } + + public Builder setToolsRepository(String toolsRepository) { + this.toolsRepository = toolsRepository; + return this; + } public Builder setPrerequisiteValidator(PrerequisiteValidator prerequisiteValidator) { this.prerequisiteValidator = prerequisiteValidator; @@ -246,6 +252,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { return new ConfiguredRuleClassProvider( preludeLabel, runfilesPrefix, + toolsRepository, ImmutableMap.copyOf(ruleClassMap), ImmutableMap.copyOf(ruleDefinitionMap), ImmutableMap.copyOf(aspectFactoryMap), @@ -264,6 +271,11 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { public Label getLabel(String labelValue) { return LABELS.getUnchecked(labelValue); } + + @Override + public String getToolsRepository() { + return toolsRepository; + } } /** @@ -297,6 +309,11 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { * The default runfiles prefix. */ private final String runfilesPrefix; + + /** + * The path to the tools repository. + */ + private final String toolsRepository; /** * Maps rule class name to the metaclass instance for that rule. @@ -345,6 +362,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { private ConfiguredRuleClassProvider( Label preludeLabel, String runfilesPrefix, + String toolsRepository, ImmutableMap ruleClassMap, ImmutableMap> ruleDefinitionMap, ImmutableMap> aspectFactoryMap, @@ -359,6 +377,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { List> buildOptions) { this.preludeLabel = preludeLabel; this.runfilesPrefix = runfilesPrefix; + this.toolsRepository = toolsRepository; this.ruleClassMap = ruleClassMap; this.ruleDefinitionMap = ruleDefinitionMap; this.aspectFactoryMap = aspectFactoryMap; @@ -386,6 +405,11 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { public String getRunfilesPrefix() { return runfilesPrefix; } + + @Override + public String getToolsRepository() { + return toolsRepository; + } @Override public Map getRuleClassMap() { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java index 9a4fb6c293..2eab411747 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java @@ -26,4 +26,9 @@ public interface RuleDefinitionEnvironment { * Label#parseAbsolute}. Throws a {@link IllegalArgumentException} if the parsing fails. */ Label getLabel(String labelValue); + + /** + * Returns the path to the tools repository. It is different for blaze and bazel. + */ + String getToolsRepository(); } 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 953ee04f8a..650c556db1 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 @@ -230,6 +230,7 @@ public class BazelRuleClassProvider { .setConfigurationCollectionFactory(new BazelConfigurationCollection()) .setPrelude("//tools/build_rules:prelude_bazel") .setRunfilesPrefix("") + .setToolsRepository("@bazel_tools") .setPrerequisiteValidator(new BazelPrerequisiteValidator()); builder.addBuildOptions(BUILD_OPTIONS); 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 68bc7b1413..4a91260cae 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,7 +39,6 @@ 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; @@ -264,7 +263,7 @@ public class BazelCppRuleClasses { .add(attr("copts", STRING_LIST)) .add( attr("$stl_default", LABEL) - .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl"))) + .value(env.getLabel(env.getToolsRepository() + "//tools/cpp:stl"))) .add(attr(":stl", LABEL).value(STL)) .build(); } @@ -551,7 +550,7 @@ public class BazelCppRuleClasses { // 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(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl"); + Label stl = env.getLabel(env.getToolsRepository() + "//tools/cpp:stl"); return rule.getLabel().equals(stl) ? null : stl; } })) @@ -586,7 +585,7 @@ public class BazelCppRuleClasses {

*/ .add(attr("malloc", LABEL) - .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:malloc")) + .value(env.getLabel(env.getToolsRepository() + "//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/packages/RuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java index f6918cbb69..f6529a6d82 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClassProvider.java @@ -72,4 +72,9 @@ public interface RuleClassProvider { * overwritten in the WORKSPACE file in the actual workspace. */ String getDefaultWorkspaceFile(); + + /** + * Returns the path to the tools repository + */ + String getToolsRepository(); } -- cgit v1.2.3