Search in sources :

Example 1 with FragmentOptions

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));
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 2 with FragmentOptions

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));
}
Also used : FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 3 with FragmentOptions

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;
}
Also used : FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConfigurationFragmentFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory) Fragment(com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment) LinkedHashMap(java.util.LinkedHashMap) Field(java.lang.reflect.Field)

Example 4 with FragmentOptions

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);
        }
    }
}
Also used : FragmentOptions(com.google.devtools.build.lib.analysis.config.FragmentOptions) RuleClass(com.google.devtools.build.lib.packages.RuleClass) ConfigurationFragmentFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Aggregations

FragmentOptions (com.google.devtools.build.lib.analysis.config.FragmentOptions)4 ConfigurationFragmentFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory)2 InvocationPolicyEnforcer (com.google.devtools.build.lib.flags.InvocationPolicyEnforcer)2 OptionsParser (com.google.devtools.common.options.OptionsParser)2 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 Fragment (com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment)1 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)1 RuleClass (com.google.devtools.build.lib.packages.RuleClass)1 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1