use of com.google.devtools.build.lib.analysis.config.FragmentOptions in project bazel by bazelbuild.
the class DefaultsPackageUtil method getDefaultsPackageForOptions.
public static String getDefaultsPackageForOptions(Class<? extends FragmentOptions> optionsClass, String... options) throws OptionsParsingException {
OptionsParser parser = OptionsParser.newOptionsParser(ImmutableList.<Class<? extends OptionsBase>>of(BuildConfiguration.Options.class, optionsClass));
parser.parse(options);
InvocationPolicyEnforcer enforcer = AnalysisMock.get().getInvocationPolicyEnforcer();
enforcer.enforce(parser);
return DefaultsPackage.getDefaultsPackageContent(BuildOptions.of(ImmutableList.<Class<? extends FragmentOptions>>of(BuildConfiguration.Options.class, optionsClass), parser));
}
use of com.google.devtools.build.lib.analysis.config.FragmentOptions in project bazel by bazelbuild.
the class CrosstoolConfigurationLoaderTest method createBuildOptionsForTest.
private BuildOptions createBuildOptionsForTest(String... args) {
ImmutableList<Class<? extends FragmentOptions>> testFragments = TestRuleClassProvider.getRuleClassProvider().getConfigurationOptions();
OptionsParser optionsParser = OptionsParser.newOptionsParser(testFragments);
try {
optionsParser.parse(args);
InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
optionsPolicyEnforcer.enforce(optionsParser);
} catch (OptionsParsingException e) {
throw new IllegalStateException(e);
}
return BuildOptions.applyStaticConfigOverride(BuildOptions.of(testFragments, optionsParser));
}
use of com.google.devtools.build.lib.analysis.config.FragmentOptions in project bazel by bazelbuild.
the class TransitiveTargetFunction method computeOptionsToFragmentMap.
/**
* Computes the option name --> config fragments map. Note that this mapping is technically
* one-to-many: a single option may be required by multiple fragments (e.g. Java options are
* used by both JavaConfiguration and Jvm). In such cases, we arbitrarily choose one fragment
* since that's all that's needed to satisfy the config_setting.
*/
private static Map<String, Class<? extends Fragment>> computeOptionsToFragmentMap(ConfiguredRuleClassProvider ruleClassProvider) {
Map<String, Class<? extends Fragment>> result = new LinkedHashMap<>();
Map<Class<? extends FragmentOptions>, Integer> visitedOptionsClasses = new HashMap<>();
for (ConfigurationFragmentFactory factory : ruleClassProvider.getConfigurationFragments()) {
Set<Class<? extends FragmentOptions>> requiredOpts = factory.requiredOptions();
for (Class<? extends FragmentOptions> optionsClass : requiredOpts) {
Integer previousBest = visitedOptionsClasses.get(optionsClass);
if (previousBest != null && previousBest <= requiredOpts.size()) {
// on as few options classes as possible (not necessarily unique).
continue;
}
visitedOptionsClasses.put(optionsClass, requiredOpts.size());
for (Field field : optionsClass.getFields()) {
if (field.isAnnotationPresent(Option.class)) {
result.put(field.getAnnotation(Option.class).name(), factory.creates());
}
}
}
}
return result;
}
use of com.google.devtools.build.lib.analysis.config.FragmentOptions in project bazel by bazelbuild.
the class BazelRuleClassProviderTest method checkConfigConsistency.
private void checkConfigConsistency(ConfiguredRuleClassProvider provider) {
// Check that every fragment required by a rule is present.
Set<Class<? extends BuildConfiguration.Fragment>> configurationFragments = provider.getAllFragments();
for (RuleClass ruleClass : provider.getRuleClassMap().values()) {
for (Class<?> fragment : ruleClass.getConfigurationFragmentPolicy().getRequiredConfigurationFragments()) {
assertWithMessage(ruleClass.toString()).that(configurationFragments).contains(fragment);
}
}
List<Class<? extends FragmentOptions>> configOptions = provider.getConfigurationOptions();
for (ConfigurationFragmentFactory fragmentFactory : provider.getConfigurationFragments()) {
// Check that every created fragment is present.
assertThat(configurationFragments).contains(fragmentFactory.creates());
// Check that every options class required for fragment creation is provided.
for (Class<? extends FragmentOptions> options : fragmentFactory.requiredOptions()) {
assertThat(configOptions).contains(options);
}
}
}
Aggregations