aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2016-04-29 22:46:16 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-05-02 09:10:14 +0000
commite9cd0f315750a4b313768165b0b80ea1e81416d5 (patch)
tree8fa3819b9cff642e2c9e29f6ef71ecca6dc863e9 /src/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java
parentdd61520f48cb5fcc28df374e8f7c4c05f68f18a0 (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/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java b/src/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java
new file mode 100644
index 0000000000..9c3b90aca0
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/flags/CommandNameCache.java
@@ -0,0 +1,41 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.package com.google.devtools.build.lib.flags;
+package com.google.devtools.build.lib.flags;
+
+import com.google.common.collect.ImmutableSet;
+
+/** Cache mapping a command to the names of all commands it inherits from, including itself. */
+public interface CommandNameCache {
+ /** Class that exists only to expose a static instance variable that can be set and retrieved. */
+ class CommandNameCacheInstance implements CommandNameCache {
+ public static final CommandNameCacheInstance INSTANCE = new CommandNameCacheInstance();
+ private CommandNameCache delegate;
+
+ private CommandNameCacheInstance() {}
+
+ /** Only for use by {@code BlazeRuntime}. */
+ public void setCommandNameCache(CommandNameCache cache) {
+ // Can be set multiple times in tests.
+ this.delegate = cache;
+ }
+
+ @Override
+ public ImmutableSet<String> get(String commandName) {
+ return delegate.get(commandName);
+ }
+ }
+
+ /** Returns the names of all commands {@code commandName} inherits from, including itself. */
+ ImmutableSet<String> get(String commandName);
+}