Skip to content

Commit

Permalink
Store warnings in state
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Aug 28, 2023
1 parent 44b674f commit 2a68ae6
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.CheckDirectDepsMode;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.profiler.SilentCloseable;
Expand Down Expand Up @@ -68,11 +70,16 @@ public SkyValue compute(SkyKey skyKey, Environment env)
}

var state = env.getState(ModuleResolutionComputeState::new);
if (state.selectionResult == null) {
state.selectionResult = discoverAndSelect(env, root);
try {
if (state.selectionResult == null) {
return null;
state.storedEventHandler = new StoredEventHandler();
state.selectionResult = discoverAndSelect(env, root, state.storedEventHandler);
if (state.selectionResult == null) {
return null;
}
}
} finally {
state.storedEventHandler.replayOn(env.getListener());
}

ImmutableSet<RepoSpecKey> repoSpecKeys =
Expand Down Expand Up @@ -107,7 +114,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
}

@Nullable
private static Selection.Result discoverAndSelect(Environment env, RootModuleFileValue root)
private static Selection.Result discoverAndSelect(
Environment env, RootModuleFileValue root, ExtendedEventHandler eventHandler)
throws BazelModuleResolutionFunctionException, InterruptedException {
ImmutableMap<ModuleKey, InterimModule> initialDepGraph;
try (SilentCloseable c = Profiler.instance().profile(ProfilerTask.BZLMOD, "discovery")) {
Expand All @@ -131,15 +139,15 @@ private static Selection.Result discoverAndSelect(Environment env, RootModuleFil
initialDepGraph.get(ModuleKey.ROOT),
resolvedDepGraph.get(ModuleKey.ROOT),
Objects.requireNonNull(CHECK_DIRECT_DEPENDENCIES.get(env)),
env.getListener());
eventHandler);
}

try (SilentCloseable c =
Profiler.instance().profile(ProfilerTask.BZLMOD, "check bazel compatibility")) {
checkBazelCompatibility(
resolvedDepGraph.values(),
Objects.requireNonNull(BAZEL_COMPATIBILITY_MODE.get(env)),
env.getListener());
eventHandler);
}

try (SilentCloseable c =
Expand Down Expand Up @@ -307,6 +315,7 @@ private static ImmutableMap<ModuleKey, Module> computeFinalDepGraph(

private static class ModuleResolutionComputeState implements Environment.SkyKeyComputeState {
Selection.Result selectionResult;
StoredEventHandler storedEventHandler;
}

static class BazelModuleResolutionFunctionException extends SkyFunctionException {
Expand Down

0 comments on commit 2a68ae6

Please sign in to comment.