diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java | 26 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java | 9 |
2 files changed, 27 insertions, 8 deletions
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 62d42c9ae4..d061dea901 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 @@ -23,6 +23,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.BuildOptions; @@ -50,6 +51,7 @@ import com.google.devtools.common.options.OptionsClassProvider; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -61,10 +63,11 @@ import java.util.Map; * and configuration options is guarantees not to change over the life time of the Blaze server. */ public class ConfiguredRuleClassProvider implements RuleClassProvider { + /** * Custom dependency validation logic. */ - public static interface PrerequisiteValidator { + public interface PrerequisiteValidator { /** * Checks whether the rule in {@code contextBuilder} is allowed to depend on * {@code prerequisite} through the attribute {@code attribute}. @@ -101,6 +104,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { private Class<? extends BuildConfiguration.Fragment> universalFragment; private PrerequisiteValidator prerequisiteValidator; private ImmutableMap<String, SkylarkType> skylarkAccessibleJavaClasses = ImmutableMap.of(); + private final List<Class<? extends FragmentOptions>> buildOptions = Lists.newArrayList(); public void addWorkspaceFile(String contents) { defaultWorkspaceFile.append(contents); @@ -117,6 +121,11 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { return this; } + public Builder addBuildOptions(Collection<Class<? extends FragmentOptions>> optionsClasses) { + buildOptions.addAll(optionsClasses); + return this; + } + public Builder setRunfilesPrefix(String runfilesPrefix) { this.runfilesPrefix = runfilesPrefix; return this; @@ -248,7 +257,8 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { configurationCollectionFactory, universalFragment, prerequisiteValidator, - skylarkAccessibleJavaClasses); + skylarkAccessibleJavaClasses, + buildOptions); } @Override @@ -331,7 +341,9 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { private final Environment.Frame globals; - public ConfiguredRuleClassProvider( + private final List<Class<? extends FragmentOptions>> buildOptions; + + private ConfiguredRuleClassProvider( Label preludeLabel, String runfilesPrefix, ImmutableMap<String, RuleClass> ruleClassMap, @@ -344,7 +356,8 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { ConfigurationCollectionFactory configurationCollectionFactory, Class<? extends BuildConfiguration.Fragment> universalFragment, PrerequisiteValidator prerequisiteValidator, - ImmutableMap<String, SkylarkType> skylarkAccessibleJavaClasses) { + ImmutableMap<String, SkylarkType> skylarkAccessibleJavaClasses, + List<Class<? extends FragmentOptions>> buildOptions) { this.preludeLabel = preludeLabel; this.runfilesPrefix = runfilesPrefix; this.ruleClassMap = ruleClassMap; @@ -358,6 +371,7 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { this.universalFragment = universalFragment; this.prerequisiteValidator = prerequisiteValidator; this.globals = createGlobals(skylarkAccessibleJavaClasses); + this.buildOptions = buildOptions; } public PrerequisiteValidator getPrerequisiteValidator() { @@ -442,6 +456,10 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { BuildOptions.of(configurationOptions, optionsProvider)); } + public ImmutableList<Class<? extends FragmentOptions>> getOptionFragments() { + return ImmutableList.copyOf(buildOptions); + } + /** * Creates a BuildOptions class for the given options taken from an optionsProvider. */ 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 c10c410a7e..03ff07be0d 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 @@ -204,13 +204,12 @@ public class BazelRuleClassProvider { } /** - * List of all build option classes in Blaze. + * List of all build option classes in Bazel. */ - // TODO(bazel-team): make this private, remove from tests, then BuildOptions.of can be merged - // into RuleClassProvider. + // TODO(bazel-team): merge BuildOptions.of into RuleClassProvider. @VisibleForTesting @SuppressWarnings("unchecked") - public static final ImmutableList<Class<? extends FragmentOptions>> BUILD_OPTIONS = + private static final ImmutableList<Class<? extends FragmentOptions>> BUILD_OPTIONS = ImmutableList.of( BuildConfiguration.Options.class, CppOptions.class, @@ -233,6 +232,8 @@ public class BazelRuleClassProvider { .setRunfilesPrefix("") .setPrerequisiteValidator(new BazelPrerequisiteValidator()); + builder.addBuildOptions(BUILD_OPTIONS); + for (Class<? extends FragmentOptions> fragmentOptions : BUILD_OPTIONS) { builder.addConfigurationOptions(fragmentOptions); } |