diff options
author | 2016-04-29 22:46:16 +0000 | |
---|---|---|
committer | 2016-05-02 09:10:14 +0000 | |
commit | e9cd0f315750a4b313768165b0b80ea1e81416d5 (patch) | |
tree | 8fa3819b9cff642e2c9e29f6ef71ecca6dc863e9 /src/test/java | |
parent | dd61520f48cb5fcc28df374e8f7c4c05f68f18a0 (diff) |
In InvocationPolicyEnforcer#enforce, instead of just checking the direct command to see if a flag policy applies, check whether the flag applies by seeing if its list of commands matches one of the commands in the hierarchy.
This avoids the tedious and brittle specification of all commands that may use a flag, while providing better filtering out of inapplicable flags.
RELNOTES: A FlagPolicy specified via the --invocation_policy flag will now match the current command if any of its commands matches any of the commands the current command inherits from, as opposed to just the current command.
--
MOS_MIGRATED_REVID=121159131
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java | 2 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/runtime/InvocationPolicyEnforcerTest.java | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java index f65452aabe..22fe2574de 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java @@ -284,7 +284,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { InvocationPolicyEnforcer optionsPolicyEnforcer = new InvocationPolicyEnforcer(TestConstants.TEST_INVOCATION_POLICY); - optionsPolicyEnforcer.enforce(optionsParser, ""); + optionsPolicyEnforcer.enforce(optionsParser); BuildOptions buildOptions = ruleClassProvider.createBuildOptions(optionsParser); ensureTargetsVisited(buildOptions.getAllLabels().values()); diff --git a/src/test/java/com/google/devtools/build/lib/runtime/InvocationPolicyEnforcerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/InvocationPolicyEnforcerTest.java index a783100e38..25b026f7d7 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/InvocationPolicyEnforcerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/InvocationPolicyEnforcerTest.java @@ -20,7 +20,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.common.collect.ImmutableSet; import com.google.common.io.BaseEncoding; +import com.google.devtools.build.lib.flags.CommandNameCache; import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer; import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; import com.google.devtools.common.options.Option; @@ -29,6 +31,7 @@ import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsParsingException; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -124,6 +127,17 @@ public class InvocationPolicyEnforcerTest { parser = OptionsParser.newOptionsParser(TestOptions.class); } + @BeforeClass + public static void setCommandNameCache() throws Exception { + CommandNameCache.CommandNameCacheInstance.INSTANCE.setCommandNameCache( + new CommandNameCache() { + @Override + public ImmutableSet<String> get(String commandName) { + return ImmutableSet.of(commandName); + } + }); + } + private TestOptions getTestOptions() { return parser.getOptions(TestOptions.class); } |