use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testDisallowValuesSetsNewValue.
@Test
public void testDisallowValuesSetsNewValue() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getDisallowValuesBuilder().addDisallowedValues("user value").setNewValue("baz");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_string=user value");
TestOptions testOptions = getTestOptions();
assertEquals("user value", testOptions.testString);
enforcer.enforce(parser, "build");
// Should now be "baz" because the policy forces disallowed values to "baz"
testOptions = getTestOptions();
assertEquals("baz", testOptions.testString);
}
use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testDisallowValuesSetsDefaultValue.
@Test
public void testDisallowValuesSetsDefaultValue() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getDisallowValuesBuilder().addDisallowedValues("user value").getUseDefaultBuilder();
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_string=user value");
TestOptions testOptions = getTestOptions();
assertEquals("user value", testOptions.testString);
enforcer.enforce(parser, "build");
testOptions = getTestOptions();
assertEquals(STRING_FLAG_DEFAULT, testOptions.testString);
}
use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testUseDefaultWithExpandedFlags.
@Test
public void testUseDefaultWithExpandedFlags() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_expansion_b").getUseDefaultBuilder();
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_expansion");
// --test_expansion should turn set the values from its expansion
TestOptions testOptions = getTestOptions();
assertFalse(testOptions.testExpansionA);
assertFalse(testOptions.testExpansionB);
assertEquals(42, testOptions.testExpansionC);
assertEquals("bar", testOptions.testExpansionD);
enforcer.enforce(parser, "build");
// After policy enforcement, test_expansion_b should be back to its default (true), but the
// rest should remain the same.
testOptions = getTestOptions();
assertFalse(testOptions.testExpansionA);
assertTrue(testOptions.testExpansionB);
assertEquals(42, testOptions.testExpansionC);
assertEquals("bar", testOptions.testExpansionD);
}
use of com.google.devtools.build.lib.flags.InvocationPolicyEnforcer in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testSetValueHasMultipleValuesButFlagIsNotMultiple.
@Test
public void testSetValueHasMultipleValuesButFlagIsNotMultiple() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName(// Not repeatable flag.
"test_string").getSetValueBuilder().addFlagValue(// Has multiple values.
"policy value 1").addFlagValue("policy value 2");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
// expected.
}
}
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