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);
}
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));
}
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));
}
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);
}
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.
}
}
Aggregations