aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-07-07 12:06:53 -0400
committerGravatar John Cater <jcater@google.com>2017-07-07 13:37:58 -0400
commit93a84bfacb96d02d2b9027d54f346a8af9aba149 (patch)
treed9ea2d3b44a95d2422a81a04d45c895ccf4270e4 /src/main/java/com/google/devtools/build
parent25ef6a8d73e982951fc1e8e5b748b17abc41960b (diff)
Restrict writing build events to a white-listed set of commands
It is not desirable to have a build-event stream for all invocations of blaze; so restrict the BuildEventServiceModule to be only active if the executed command is in a white list of commands for which having build events is desirable. Change-Id: Id4acf9468f67b1af7fc8ea703785df5229c69258 PiperOrigin-RevId: 161207563
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModule.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java15
2 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModule.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModule.java
index c80f77e58e..0ba8d605eb 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModule.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModule.java
@@ -14,9 +14,11 @@
package com.google.devtools.build.lib.buildeventservice;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
import com.google.devtools.build.lib.buildeventservice.client.BuildEventServiceClient;
import com.google.devtools.build.lib.buildeventservice.client.BuildEventServiceGrpcClient;
+import java.util.Set;
/**
* Bazel's BES module.
@@ -37,4 +39,9 @@ public class BazelBuildEventServiceModule
authAndTLSOptions.tlsAuthorityOverride, authAndTLSOptions.authCredentials,
authAndTLSOptions.authScope);
}
+
+ @Override
+ protected Set<String> whitelistedCommands() {
+ return ImmutableSet.of("build", "test", "run", "query", "coverage", "mobile-install");
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
index ad33471212..60df1913a4 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
@@ -47,6 +47,7 @@ import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsProvider;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;
import javax.annotation.Nullable;
@@ -66,6 +67,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
private CommandEnvironment commandEnvironment;
private SynchronizedOutputStream out;
private SynchronizedOutputStream err;
+ private boolean disabled;
private static class BuildEventRecorder {
private final List<BuildEvent> events = new ArrayList<>();
@@ -90,6 +92,11 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
@Override
public void beforeCommand(CommandEnvironment commandEnvironment)
throws AbruptExitException {
+ disabled = false;
+ if (!whitelistedCommands().contains(commandEnvironment.getCommandName())) {
+ disabled = true;
+ return;
+ }
this.commandEnvironment = commandEnvironment;
this.buildEventRecorder = new BuildEventRecorder();
commandEnvironment.getEventBus().register(buildEventRecorder);
@@ -97,6 +104,9 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
@Override
public void handleOptions(OptionsProvider optionsProvider) {
+ if (disabled) {
+ return;
+ }
checkState(commandEnvironment != null, "Methods called out of order");
BuildEventStreamer streamer =
tryCreateStreamer(
@@ -158,6 +168,9 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
@Override
public OutErr getOutputListener() {
+ if (disabled) {
+ return null;
+ }
this.out = new SynchronizedOutputStream();
this.err = new SynchronizedOutputStream();
return OutErr.create(this.out, this.err);
@@ -266,4 +279,6 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
protected abstract BuildEventServiceClient createBesClient(T besOptions,
AuthAndTLSOptions authAndTLSOptions);
+
+ protected abstract Set<String> whitelistedCommands();
}