Search in sources :

Example 1 with InvocationPolicyEnforcer

use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.

the class BuildViewTestCase method createConfigurations.

protected final BuildConfigurationCollection createConfigurations(String... args) throws Exception {
    optionsParser = OptionsParser.newOptionsParser(Iterables.concat(Arrays.asList(ExecutionOptions.class, BuildRequest.BuildRequestOptions.class), ruleClassProvider.getConfigurationOptions()));
    List<String> allArgs = new ArrayList<>();
    // TODO(dmarting): Add --stamp option only to test that requires it.
    // Stamp is now defaulted to false.
    allArgs.add("--stamp");
    allArgs.add("--experimental_extended_sanity_checks");
    allArgs.add("--features=cc_include_scanning");
    allArgs.addAll(getAnalysisMock().getOptionOverrides());
    optionsParser.parse(allArgs);
    optionsParser.parse(args);
    InvocationPolicyEnforcer optionsPolicyEnforcer = getAnalysisMock().getInvocationPolicyEnforcer();
    optionsPolicyEnforcer.enforce(optionsParser);
    BuildOptions buildOptions = ruleClassProvider.createBuildOptions(optionsParser);
    skyframeExecutor.invalidateConfigurationCollection();
    return skyframeExecutor.createConfigurations(reporter, configurationFactory, buildOptions, ImmutableSet.<String>of(), false);
}
Also used : ExecutionOptions(com.google.devtools.build.lib.exec.ExecutionOptions) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) ArrayList(java.util.ArrayList)

Example 2 with InvocationPolicyEnforcer

use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer 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 3 with InvocationPolicyEnforcer

use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer 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 4 with InvocationPolicyEnforcer

use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.

the class InvocationPolicyEnforcerTest method testSetValueOverridable.

@Test
public void testSetValueOverridable() throws Exception {
    InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
    invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getSetValueBuilder().addFlagValue("policy value").setOverridable(true);
    InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
    parser.parse("--test_string=user value");
    TestOptions testOptions = getTestOptions();
    assertEquals("user value", testOptions.testString);
    enforcer.enforce(parser, "build");
    // Even though the policy sets the value for test_string, the policy is overridable and the
    // user set the value, so it should be the user's value.
    testOptions = getTestOptions();
    assertEquals("user value", testOptions.testString);
}
Also used : InvocationPolicy(com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) Test(org.junit.Test)

Example 5 with InvocationPolicyEnforcer

use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.

the class InvocationPolicyEnforcerTest method testDisallowValuesDisallowsFlagDefaultButNoPolicyDefault.

@Test
public void testDisallowValuesDisallowsFlagDefaultButNoPolicyDefault() throws Exception {
    InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
    invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getDisallowValuesBuilder().addDisallowedValues(STRING_FLAG_DEFAULT);
    InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
    // Option should be the default since the use didn't specify a value.
    TestOptions testOptions = getTestOptions();
    assertEquals(STRING_FLAG_DEFAULT, testOptions.testString);
    try {
        enforcer.enforce(parser, "build");
        fail();
    } catch (OptionsParsingException e) {
    // expected.
    }
}
Also used : InvocationPolicy(com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) Test(org.junit.Test)

Aggregations

InvocationPolicyEnforcer (com.google.devtools.build.lib.flags.InvocationPolicyEnforcer)49 InvocationPolicy (com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy)41 Test (org.junit.Test)41 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)15 OptionsParser (com.google.devtools.common.options.OptionsParser)6 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)4 FragmentOptions (com.google.devtools.build.lib.analysis.config.FragmentOptions)2 ExecutionOptions (com.google.devtools.build.lib.exec.ExecutionOptions)2 OptionsBase (com.google.devtools.common.options.OptionsBase)2 ArrayList (java.util.ArrayList)2 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 BuildConfigurationCollection (com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection)1 BuildRequestOptions (com.google.devtools.build.lib.buildtool.BuildRequest.BuildRequestOptions)1 EventHandler (com.google.devtools.build.lib.events.EventHandler)1 Reporter (com.google.devtools.build.lib.events.Reporter)1 LoadingOptions (com.google.devtools.build.lib.pkgcache.LoadingOptions)1 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)1 BlazeCommand (com.google.devtools.build.lib.runtime.BlazeCommand)1 BlazeRuntime (com.google.devtools.build.lib.runtime.BlazeRuntime)1 AbruptExitException (com.google.devtools.build.lib.util.AbruptExitException)1