use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testUseDefault.
/*************************************************************************************************
* Tests for UseDefault
************************************************************************************************/
@Test
public void testUseDefault() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getUseDefaultBuilder();
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_string=user value");
// Options should be the user specified value before enforcing policy.
TestOptions testOptions = getTestOptions();
assertEquals("user value", testOptions.testString);
enforcer.enforce(parser, "build");
// Get the options again after policy enforcement: The flag should now be back to its default
// value
testOptions = getTestOptions();
assertEquals(STRING_FLAG_DEFAULT, testOptions.testString);
}
use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class ConfigurationTestCase method createCollection.
protected BuildConfigurationCollection createCollection(String... args) throws Exception {
OptionsParser parser = OptionsParser.newOptionsParser(ImmutableList.<Class<? extends OptionsBase>>builder().addAll(buildOptionClasses).add(TestOptions.class).build());
parser.parse(args);
InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
optionsPolicyEnforcer.enforce(parser);
ImmutableSortedSet<String> multiCpu = ImmutableSortedSet.copyOf(parser.getOptions(TestOptions.class).multiCpus);
BuildOptions buildOptions = BuildOptions.applyStaticConfigOverride(BuildOptions.of(buildOptionClasses, parser));
skyframeExecutor.handleDiffs(reporter);
BuildConfigurationCollection collection = skyframeExecutor.createConfigurations(reporter, configurationFactory, buildOptions, multiCpu, false);
return collection;
}
use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class PackageCacheTest method parsePackageCacheOptions.
private PackageCacheOptions parsePackageCacheOptions(String... options) throws Exception {
OptionsParser parser = OptionsParser.newOptionsParser(PackageCacheOptions.class);
parser.parse(new String[] { "--default_visibility=public" });
parser.parse(options);
InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
try {
optionsPolicyEnforcer.enforce(parser);
} catch (OptionsParsingException e) {
throw new IllegalStateException(e);
}
return parser.getOptions(PackageCacheOptions.class);
}
use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class AnalysisTestCase method useConfiguration.
/**
* Sets host and target configuration using the specified options, falling back to the default
* options for unspecified ones, and recreates the build view.
*/
protected final void useConfiguration(String... args) throws Exception {
optionsParser = OptionsParser.newOptionsParser(Iterables.concat(Arrays.asList(ExecutionOptions.class, PackageCacheOptions.class, BuildRequestOptions.class, BuildView.Options.class), ruleClassProvider.getConfigurationOptions()));
optionsParser.parse(new String[] { "--default_visibility=public" });
optionsParser.parse(args);
if (defaultFlags().contains(Flag.DYNAMIC_CONFIGURATIONS)) {
optionsParser.parse("--experimental_dynamic_configs=on");
} else if (defaultFlags().contains(Flag.DYNAMIC_CONFIGURATIONS_NOTRIM)) {
optionsParser.parse("--experimental_dynamic_configs=notrim");
}
InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
optionsPolicyEnforcer.enforce(optionsParser);
}
Aggregations