diff options
author | janakr <janakr@google.com> | 2017-10-23 18:16:39 +0200 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2017-10-23 18:40:07 +0200 |
commit | b80c21a3eee246a1e9c7b9b2b1e19f769f93430a (patch) | |
tree | 5be4805144525ba501e18e0237edb0af675719e2 /src/main/java/com/google/devtools/build | |
parent | 4256ce1915c69bb8a8cee0b5c09a094768b7cd02 (diff) |
Memoize configuration supplier in InfoCommand. Previous implementation never actually assigned to the configuration, so we were redoing Skyframe graph setup each time. We still cached actual loading/analysis work, but unnecessarily injected precomputed values each time.
This meant that in the "edge" case of not keeping edges, we were only succeeding by accident, because we never actually switched the evaluator to not keep edges.
PiperOrigin-RevId: 173124505
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java index 054f5ddff3..ca32232cc0 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.runtime.commands; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.analysis.NoBuildEvent; @@ -106,37 +107,36 @@ public class InfoCommand implements BlazeCommand { Options infoOptions = optionsProvider.getOptions(Options.class); OutErr outErr = env.getReporter().getOutErr(); // Creating a BuildConfiguration is expensive and often unnecessary. Delay the creation until - // it is needed. - Supplier<BuildConfiguration> configurationSupplier = new Supplier<BuildConfiguration>() { - private BuildConfiguration configuration; - @Override - public BuildConfiguration get() { - if (configuration != null) { - return configuration; - } - try { - // In order to be able to answer configuration-specific queries, we need to setup the - // package path. Since info inherits all the build options, all the necessary information - // is available here. - env.setupPackageCache( - optionsProvider, runtime.getDefaultsPackageContent(optionsProvider)); - env.getSkyframeExecutor().setConfigurationFragmentFactories( - runtime.getConfigurationFragmentFactories()); - // TODO(bazel-team): What if there are multiple configurations? [multi-config] - return env.getSkyframeExecutor().getConfiguration( - env.getReporter(), runtime.createBuildOptions(optionsProvider), /*keepGoing=*/true); - } catch (InvalidConfigurationException e) { - env.getReporter().handle(Event.error(e.getMessage())); - throw new ExitCausingRuntimeException(ExitCode.COMMAND_LINE_ERROR); - } catch (AbruptExitException e) { - throw new ExitCausingRuntimeException("unknown error: " + e.getMessage(), - e.getExitCode()); - } catch (InterruptedException e) { - env.getReporter().handle(Event.error("interrupted")); - throw new ExitCausingRuntimeException(ExitCode.INTERRUPTED); - } - } - }; + // it is needed. We memoize so that it's cached intra-command (it's still created freshly on + // every command since the configuration can change across commands). + Supplier<BuildConfiguration> configurationSupplier = + Suppliers.memoize( + () -> { + try { + // In order to be able to answer configuration-specific queries, we need to set up + // the package path. Since info inherits all the build options, all the necessary + // information is available here. + env.setupPackageCache( + optionsProvider, runtime.getDefaultsPackageContent(optionsProvider)); + env.getSkyframeExecutor() + .setConfigurationFragmentFactories(runtime.getConfigurationFragmentFactories()); + // TODO(bazel-team): What if there are multiple configurations? [multi-config] + return env.getSkyframeExecutor() + .getConfiguration( + env.getReporter(), + runtime.createBuildOptions(optionsProvider), + /*keepGoing=*/ true); + } catch (InvalidConfigurationException e) { + env.getReporter().handle(Event.error(e.getMessage())); + throw new ExitCausingRuntimeException(ExitCode.COMMAND_LINE_ERROR); + } catch (AbruptExitException e) { + throw new ExitCausingRuntimeException( + "unknown error: " + e.getMessage(), e.getExitCode()); + } catch (InterruptedException e) { + env.getReporter().handle(Event.error("interrupted")); + throw new ExitCausingRuntimeException(ExitCode.INTERRUPTED); + } + }); Map<String, InfoItem> items = getInfoItemMap(env, optionsProvider); |