diff options
author | Googler <noreply@google.com> | 2018-07-03 09:12:47 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-03 09:14:29 -0700 |
commit | ffc192f0bfb240711ceab874258810f6d3671a23 (patch) | |
tree | f79244702c75c0a3bc3794a7b351e8a96355694d /src/main/java/com/google/devtools/build/lib/bazel | |
parent | 1ee159adf2ef18590872f8c0478af441e24e8268 (diff) |
First cl for verbose workspaces (ability to log certain potentially non-hermetic events that happen as part of repository rules).
In the interest of smaller cls, adding plumbing first with the rest to follow.
Creates and posts a new EventBus message for workspace rule events (only execution for now); conditional on a flag, registers a listener to output those events.
In the future:
- Better structure for the events: will create a proto with appropriate messages and more information per event
- Add more events
- Allowing to specify log file rather than dumping to INFO
- Log levels, full or alerts only
RELNOTES: None
PiperOrigin-RevId: 203132761
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/bazel')
6 files changed, 179 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java b/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java index e96c815036..38a8ae77e1 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/Bazel.java @@ -43,6 +43,7 @@ public final class Bazel { com.google.devtools.build.lib.bazel.BazelWorkspaceStatusModule.class, com.google.devtools.build.lib.bazel.BazelDiffAwarenessModule.class, com.google.devtools.build.lib.bazel.BazelRepositoryModule.class, + com.google.devtools.build.lib.bazel.debug.WorkspaceRuleModule.class, com.google.devtools.build.lib.skylarkdebug.module.SkylarkDebuggerModule.class, com.google.devtools.build.lib.bazel.repository.RepositoryResolvedModule.class, com.google.devtools.build.lib.bazel.SpawnLogModule.class, 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 new file mode 100644 index 0000000000..208d4e1254 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/BUILD @@ -0,0 +1,44 @@ +# Description: +# Debugging helpers and modules +package( + default_visibility = ["//src:__subpackages__"], +) + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = [ + "//src:__pkg__", + "//src/main/java/com/google/devtools/build/lib:__pkg__", + "//src/test/shell/bazel:__pkg__", + ], +) + +java_library( + name = "workspace-rule-event", + srcs = ["WorkspaceRuleEvent.java"], + deps = [ + "//src/main/java/com/google/devtools/build/lib:events", + ], +) + +java_library( + name = "workspace-rule-module", + srcs = ["WorkspaceRuleModule.java"], + deps = [ + ":debugging-options", + ":workspace-rule-event", + "//src/main/java/com/google/devtools/build/lib:events", + "//src/main/java/com/google/devtools/build/lib:runtime", + "//src/main/java/com/google/devtools/common/options", + "//third_party:guava", + ], +) + +java_library( + name = "debugging-options", + srcs = ["DebuggingOptions.java"], + deps = [ + "//src/main/java/com/google/devtools/common/options", + ], +) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/debug/DebuggingOptions.java b/src/main/java/com/google/devtools/build/lib/bazel/debug/DebuggingOptions.java new file mode 100644 index 0000000000..2761b61d6f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/DebuggingOptions.java @@ -0,0 +1,31 @@ +// 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. + +package com.google.devtools.build.lib.bazel.debug; + +import com.google.devtools.common.options.Option; +import com.google.devtools.common.options.OptionDocumentationCategory; +import com.google.devtools.common.options.OptionEffectTag; +import com.google.devtools.common.options.OptionsBase; + +/** Options for debugging and verbosity tools. */ +public final class DebuggingOptions extends OptionsBase { + @Option( + name = "experimental_workspace_rules_logging", + defaultValue = "null", + documentationCategory = OptionDocumentationCategory.LOGGING, + effectTags = {OptionEffectTag.UNKNOWN}, + help = "Log certain Workspace Rules events") + public String workspaceRulesLogging; +} 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 new file mode 100644 index 0000000000..059b08adae --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEvent.java @@ -0,0 +1,40 @@ +// 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. +package com.google.devtools.build.lib.bazel.debug; + +import com.google.devtools.build.lib.events.ExtendedEventHandler.ProgressLike; +import com.google.devtools.build.lib.events.Location; + +/** An event to record events happening during workspace rule resolution */ +public final class WorkspaceRuleEvent implements ProgressLike { + String location; + String description; + + /** + * Creates a new WorkspaceRuleEvent with the given description. + * + * <p>Note: we will add more granular information as needed. + */ + public WorkspaceRuleEvent(Location location, String description) { + this.location = location.print(); + this.description = description; + } + + /* + * @return a message to log for this event + */ + public String logMessage() { + return location + ": " + description; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleModule.java b/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleModule.java new file mode 100644 index 0000000000..bd5406d478 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleModule.java @@ -0,0 +1,55 @@ +// 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. +package com.google.devtools.build.lib.bazel.debug; + +import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; +import com.google.devtools.build.lib.events.Event; +import com.google.devtools.build.lib.events.Reporter; +import com.google.devtools.build.lib.runtime.BlazeModule; +import com.google.devtools.build.lib.runtime.CommandEnvironment; +import com.google.devtools.common.options.OptionsBase; + +/** A module for logging workspace rule events */ +public final class WorkspaceRuleModule extends BlazeModule { + private Reporter reporter; + private EventBus eventBus; + + @Override + public void beforeCommand(CommandEnvironment env) { + + reporter = env.getReporter(); + eventBus = env.getEventBus(); + + if (env.getOptions() == null || env.getOptions().getOptions(DebuggingOptions.class) == null) { + reporter.handle(Event.error("Installation is corrupt: could not retrieve debugging options")); + return; + } + + if (env.getOptions().getOptions(DebuggingOptions.class).workspaceRulesLogging != null) { + eventBus.register(this); + } + } + + @Override + public Iterable<Class<? extends OptionsBase>> getCommonCommandOptions() { + return ImmutableList.<Class<? extends OptionsBase>>of(DebuggingOptions.class); + } + + @Subscribe + public void workspaceRuleEventReceived(WorkspaceRuleEvent event) { + reporter.handle(Event.info(event.logMessage())); + } +} 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 f245e1dc73..476c47c3dd 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 @@ -19,6 +19,7 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.FileValue; +import com.google.devtools.build.lib.bazel.debug.WorkspaceRuleEvent; import com.google.devtools.build.lib.bazel.repository.DecompressorDescriptor; import com.google.devtools.build.lib.bazel.repository.DecompressorValue; import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.KeyType; @@ -230,9 +231,14 @@ public class SkylarkRepositoryContext @Override public SkylarkExecutionResult execute( - SkylarkList<Object> arguments, Integer timeout, SkylarkDict<String, String> environment, - boolean quiet) + SkylarkList<Object> arguments, + Integer timeout, + SkylarkDict<String, String> environment, + boolean quiet, + Location location) throws EvalException, RepositoryFunctionException { + WorkspaceRuleEvent w = new WorkspaceRuleEvent(location, "Executing a command."); + env.getListener().post(w); createDirectory(outputDirectory); return SkylarkExecutionResult.builder(osObject.getEnvironmentVariables()) .addArguments(arguments) |