Skip to content

Commit

Permalink
Report the structured Bazel command line via the BEP.
Browse files Browse the repository at this point in the history
This is part of the effort outlined in https://bazel.build/designs/2017/07/13/improved-command-line-reporting.html. The refactoring of the options parser is not yet complete, so we still do not have complete & correct information about the canonical command line. Where the information is blatantly incorrect, a best approximation was made, with comments and tests documenting the deficiencies.

Change the names of the initial CommandLine fields in the BEP to be explicitly identified as unstructured.

RELNOTES: None.
PiperOrigin-RevId: 171625377
  • Loading branch information
cvcal authored and hlopko committed Oct 10, 2017
1 parent 43edc92 commit ceb1013
Show file tree
Hide file tree
Showing 18 changed files with 946 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,12 @@ java_library(
"//src/main/protobuf:action_cache_java_proto",
"//src/main/protobuf:bazel_flags_java_proto",
"//src/main/protobuf:build_java_proto",
"//src/main/protobuf:command_line_java_proto",
"//src/main/protobuf:command_server_java_grpc",
"//src/main/protobuf:command_server_java_proto",
"//src/main/protobuf:extra_actions_base_java_proto",
"//src/main/protobuf:invocation_policy_java_proto",
"//src/main/protobuf:option_filters_java_proto",
"//src/main/protobuf:test_status_java_proto",
"//third_party:guava",
"//third_party:jsr305",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,24 @@ public static BuildEventId buildStartedId() {
BuildEventStreamProtos.BuildEventId.newBuilder().setStarted(startedId).build());
}

public static BuildEventId commandlineId() {
BuildEventStreamProtos.BuildEventId.CommandLineId commandLineId =
BuildEventStreamProtos.BuildEventId.CommandLineId.getDefaultInstance();
public static BuildEventId unstructuredCommandlineId() {
BuildEventStreamProtos.BuildEventId.UnstructuredCommandLineId commandLineId =
BuildEventStreamProtos.BuildEventId.UnstructuredCommandLineId.getDefaultInstance();
return new BuildEventId(
BuildEventStreamProtos.BuildEventId.newBuilder().setCommandLine(commandLineId).build());
BuildEventStreamProtos.BuildEventId.newBuilder()
.setUnstructuredCommandLine(commandLineId)
.build());
}

public static BuildEventId structuredCommandlineId(String commandLineLabel) {
BuildEventStreamProtos.BuildEventId.StructuredCommandLineId commandLineId =
BuildEventStreamProtos.BuildEventId.StructuredCommandLineId.newBuilder()
.setCommandLineLabel(commandLineLabel)
.build();
return new BuildEventId(
BuildEventStreamProtos.BuildEventId.newBuilder()
.setStructuredCommandLine(commandLineId)
.build());
}

public static BuildEventId optionsParsedId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ proto_library(
name = "build_event_stream_proto",
srcs = ["build_event_stream.proto"],
deps = [
"//src/main/protobuf:command_line_proto",
"//src/main/protobuf:invocation_policy_proto",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option java_package = "com.google.devtools.build.lib.buildeventstream";
option java_outer_classname = "BuildEventStreamProtos";

import "src/main/protobuf/invocation_policy.proto";
import "src/main/protobuf/command_line.proto";

// Identifier for a build event. It is deliberately structured to also provide
// information about which build target etc the event is related to.
Expand Down Expand Up @@ -53,7 +54,16 @@ message BuildEventId {

// Identifier on an event indicating the original commandline received by
// the bazel server.
message CommandLineId {
message UnstructuredCommandLineId {
}

// Identifier on an event describing the commandline received by Bazel.
message StructuredCommandLineId {
// A title for this command line value, as there may be multiple.
// For example, a single invocation may wish to report both the literal and
// canonical command lines, and this label would be used to differentiate
// between both versions.
string command_line_label = 1;
}

// Identifier of an event indicating the workspace status.
Expand Down Expand Up @@ -159,7 +169,8 @@ message BuildEventId {
UnknownBuildEventId unknown = 1;
ProgressId progress = 2;
BuildStartedId started = 3;
CommandLineId command_line = 11;
UnstructuredCommandLineId unstructured_command_line = 11;
StructuredCommandLineId structured_command_line = 18;
WorkspaceStatusId workspace_status = 14;
OptionsParsedId options_parsed = 12;
FetchId fetch = 17;
Expand Down Expand Up @@ -260,7 +271,7 @@ message BuildStarted {
// like name and relevant entries of rc-files and client environment variables.
// However, it does contain enough information to reproduce the build
// invocation.
message CommandLine {
message UnstructuredCommandLine {
repeated string args = 1;
}

Expand Down Expand Up @@ -531,7 +542,8 @@ message BuildEvent {
Progress progress = 3;
Aborted aborted = 4;
BuildStarted started = 5;
CommandLine command_line = 12;
UnstructuredCommandLine unstructured_command_line = 12;
command_line.CommandLine structured_command_line = 22;
OptionsParsed options_parsed = 13;
WorkspaceStatus workspace_status = 16;
Fetch fetch = 21;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public BuildEventId getEventId() {
public Collection<BuildEventId> getChildrenEvents() {
return ImmutableList.of(
ProgressEvent.INITIAL_PROGRESS_UPDATE,
BuildEventId.commandlineId(),
BuildEventId.unstructuredCommandlineId(),
BuildEventId.optionsParsedId(),
BuildEventId.workspaceStatusId(),
BuildEventId.targetPatternExpanded(request.getTargets()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ private void parseArgsAndConfigs(Path workspaceDirectory, Path workingDirectory,

parseOptionsForCommand(rcfileNotes, commandAnnotation, optionsParser, optionsMap, null, null);
if (commandAnnotation.builds()) {
// splits project files from targets in the traditional sense
ProjectFileSupport.handleProjectFiles(
eventHandler, runtime.getProjectFileProvider(), workspaceDirectory, workingDirectory,
optionsParser, commandAnnotation.name());
eventHandler,
runtime.getProjectFileProvider(),
workspaceDirectory,
workingDirectory,
optionsParser,
commandAnnotation.name());
}

// Fix-point iteration until all configs are loaded.
Expand Down Expand Up @@ -276,7 +281,8 @@ int exec(
long firstContactTime,
Optional<List<Pair<String, String>>> startupOptionsTaggedWithBazelRc)
throws ShutdownBlazeServerException, InterruptedException {
OriginalCommandLineEvent originalCommandLine = new OriginalCommandLineEvent(args);
OriginalUnstructuredCommandLineEvent originalCommandLine =
new OriginalUnstructuredCommandLineEvent(args);
Preconditions.checkNotNull(clientDescription);
if (args.isEmpty()) { // Default to help command if no arguments specified.
args = HELP_COMMAND;
Expand Down Expand Up @@ -370,7 +376,7 @@ int exec(
}

private int execExclusively(
OriginalCommandLineEvent originalCommandLine,
OriginalUnstructuredCommandLineEvent unstructuredServerCommandLineEvent,
InvocationPolicy invocationPolicy,
List<String> args,
OutErr outErr,
Expand All @@ -395,7 +401,11 @@ private int execExclusively(
eventHandler, workspace, command, commandAnnotation, commandName, invocationPolicy, args,
optionsResult, rcfileNotes);
OptionsProvider options = optionsResult.get();

CommandLineEvent originalCommandLineEvent =
new CommandLineEvent.OriginalCommandLineEvent(
runtime, commandName, options, startupOptionsTaggedWithBazelRc);
CommandLineEvent canonicalCommandLineEvent =
new CommandLineEvent.CanonicalCommandLineEvent(runtime, commandName, options);
// The initCommand call also records the start time for the timestamp granularity monitor.
CommandEnvironment env = workspace.initCommand(commandAnnotation, options);
// Record the command's starting time for use by the commands themselves.
Expand Down Expand Up @@ -591,7 +601,11 @@ private int execExclusively(
return e.getExitCode().getNumericExitCode();
}

env.getEventBus().post(originalCommandLine);
// Log the command line now that the modules have all had a change to register their listeners
// to the event bus.
env.getEventBus().post(unstructuredServerCommandLineEvent);
env.getEventBus().post(originalCommandLineEvent);
env.getEventBus().post(canonicalCommandLineEvent);

for (BlazeModule module : runtime.getBlazeModules()) {
env.getSkyframeExecutor().injectExtraPrecomputedValues(module.getPrecomputedValues());
Expand Down
Loading

0 comments on commit ceb1013

Please sign in to comment.