diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java')
-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); |