aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-07-16 08:48:39 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-16 08:50:01 -0700
commit7e703eca32b834edc677a926c2d440e49ffdadc2 (patch)
tree743caca03845e3b68f61ecc7632bcb0ed6912072 /src/main/java/com/google/devtools/build
parentd69b1c752587149269e9b0d1e7563bc5eb66be6a (diff)
Second cl for verbose workspaces (ability to log certain potentially non-hermetic events that happen as part of repository rules).
Defining representation for Execute events for workspace logging. In the future: - Add more events - Allowing to specify log file rather than dumping to INFO - Log levels, full or alerts only RELNOTES: None PiperOrigin-RevId: 204748436
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/debug/BUILD24
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEvent.java56
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/debug/workspace_log.proto51
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java11
4 files changed, 134 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/debug/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/debug/BUILD
index 208d4e1254..ad9343c99f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/debug/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/BUILD
@@ -4,6 +4,8 @@ package(
default_visibility = ["//src:__subpackages__"],
)
+load("//tools/build_rules:utilities.bzl", "java_library_srcs")
+
filegroup(
name = "srcs",
srcs = glob(["**"]),
@@ -14,10 +16,32 @@ filegroup(
],
)
+proto_library(
+ name = "workspace_log_proto",
+ srcs = ["workspace_log.proto"],
+ deps = [],
+)
+
+java_proto_library(
+ name = "workspace_log_java_proto",
+ deps = [":workspace_log_proto"],
+)
+
+java_library_srcs(
+ name = "workspace_log_java_proto_srcs",
+ deps = [":workspace_log_java_proto"],
+)
+
+filegroup(
+ name = "dist_jars",
+ srcs = [":workspace_log_java_proto_srcs"],
+)
+
java_library(
name = "workspace-rule-event",
srcs = ["WorkspaceRuleEvent.java"],
deps = [
+ ":workspace_log_java_proto",
"//src/main/java/com/google/devtools/build/lib:events",
],
)
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEvent.java
index 059b08adae..38c9da3e7c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEvent.java
@@ -13,28 +13,70 @@
// limitations under the License.
package com.google.devtools.build.lib.bazel.debug;
+import com.google.devtools.build.lib.bazel.debug.proto.WorkspaceLogProtos;
import com.google.devtools.build.lib.events.ExtendedEventHandler.ProgressLike;
import com.google.devtools.build.lib.events.Location;
+import java.util.Map;
/** An event to record events happening during workspace rule resolution */
public final class WorkspaceRuleEvent implements ProgressLike {
- String location;
- String description;
+ WorkspaceLogProtos.WorkspaceEvent event;
+
+ public WorkspaceLogProtos.WorkspaceEvent getLogEvent() {
+ return event;
+ }
+
+ private WorkspaceRuleEvent(WorkspaceLogProtos.WorkspaceEvent event) {
+ this.event = event;
+ }
/**
- * Creates a new WorkspaceRuleEvent with the given description.
+ * Creates a new WorkspaceRuleEvent for an execution event.
*
* <p>Note: we will add more granular information as needed.
*/
- public WorkspaceRuleEvent(Location location, String description) {
- this.location = location.print();
- this.description = description;
+ public static WorkspaceRuleEvent newExecuteEvent(
+ Iterable<Object> args,
+ Integer timeout,
+ Map<String, String> commonEnvironment,
+ Map<String, String> customEnvironment,
+ String outputDirectory,
+ boolean quiet,
+ String ruleLabel,
+ Location location) {
+
+ WorkspaceLogProtos.ExecuteEvent.Builder e =
+ WorkspaceLogProtos.ExecuteEvent.newBuilder()
+ .setTimeoutSeconds(timeout.intValue())
+ .setOutputDirectory(outputDirectory)
+ .setQuiet(quiet);
+ if (commonEnvironment != null) {
+ e = e.putAllEnvironment(commonEnvironment);
+ }
+ if (customEnvironment != null) {
+ e = e.putAllEnvironment(customEnvironment);
+ }
+
+ for (Object a : args) {
+ e.addArguments(a.toString());
+ }
+
+ WorkspaceLogProtos.WorkspaceEvent.Builder result =
+ WorkspaceLogProtos.WorkspaceEvent.newBuilder();
+ result = result.setExecuteEvent(e.build());
+ if (location != null) {
+ result = result.setLocation(location.print());
+ }
+ if (ruleLabel != null) {
+ result = result.setRule(ruleLabel);
+ }
+ return new WorkspaceRuleEvent(result.build());
}
/*
* @return a message to log for this event
*/
public String logMessage() {
- return location + ": " + description;
+ return event.toString();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/debug/workspace_log.proto b/src/main/java/com/google/devtools/build/lib/bazel/debug/workspace_log.proto
new file mode 100644
index 0000000000..1dea56af9c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/workspace_log.proto
@@ -0,0 +1,51 @@
+// Copyright 2018 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.
+syntax = "proto3";
+
+package workspace_log;
+
+option java_package = "com.google.devtools.build.lib.bazel.debug.proto";
+option java_outer_classname = "WorkspaceLogProtos";
+
+// Information on "Execute" event in repository_ctx.
+message ExecuteEvent {
+ // Command line arguments, with the first one being the command to execute.
+ repeated string arguments = 2;
+
+ // Timeout used for the command
+ int32 timeout_seconds = 3;
+
+ // Environment variables set for the execution. Note that this includes
+ // variables specified by the user (as an input to Execute command),
+ // as well as variables set indirectly through the rule environment
+ map<string, string> environment = 4;
+
+ // True if quiet execution was requested.
+ bool quiet = 5;
+
+ // Directory that would contain the output of the command.
+ string output_directory = 6;
+}
+
+message WorkspaceEvent {
+ // Location in the code (.bzl file) where the event originates.
+ string location = 1;
+
+ // Label of the rule whose evaluation caused this event.
+ string rule = 2;
+
+ oneof event {
+ ExecuteEvent execute_event = 3;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
index 476c47c3dd..d52388c595 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
@@ -237,7 +237,16 @@ public class SkylarkRepositoryContext
boolean quiet,
Location location)
throws EvalException, RepositoryFunctionException {
- WorkspaceRuleEvent w = new WorkspaceRuleEvent(location, "Executing a command.");
+ WorkspaceRuleEvent w =
+ WorkspaceRuleEvent.newExecuteEvent(
+ arguments,
+ timeout,
+ osObject.getEnvironmentVariables(),
+ environment,
+ outputDirectory.getPathString(),
+ quiet,
+ rule.getLabel().toString(),
+ location);
env.getListener().post(w);
createDirectory(outputDirectory);
return SkylarkExecutionResult.builder(osObject.getEnvironmentVariables())