diff options
author | Kristina Chodorow <kchodorow@google.com> | 2015-05-14 18:18:35 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-05-15 09:44:55 +0000 |
commit | 6cad14ed42aadc8269bfcef86cc7fefeb4d82416 (patch) | |
tree | 67bd6e527d2c10d6919ef103e59f0f464f49a1ac /src/main/java | |
parent | b3dece0edf7ad45ef0bfca9c0d50ea7198f43c51 (diff) |
Create a --fetch option to allow fetching during the build command
--
MOS_MIGRATED_REVID=93639664
Diffstat (limited to 'src/main/java')
5 files changed, 29 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java index a4b6910894..bd56910369 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java @@ -37,10 +37,9 @@ import com.google.devtools.build.lib.bazel.rules.workspace.LocalRepositoryRule; import com.google.devtools.build.lib.bazel.rules.workspace.MavenJarRule; import com.google.devtools.build.lib.bazel.rules.workspace.NewHttpArchiveRule; import com.google.devtools.build.lib.bazel.rules.workspace.NewLocalRepositoryRule; +import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeModule; -import com.google.devtools.build.lib.runtime.BlazeRuntime; -import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.util.Clock; import com.google.devtools.build.lib.vfs.Path; @@ -103,13 +102,15 @@ public class BazelRepositoryModule extends BlazeModule { } } + @Override public Iterable<? extends BlazeCommand> getCommands() { return ImmutableList.of(new FetchCommand()); } @Override - public void beforeCommand(BlazeRuntime blazeRuntime, Command command) { - isFetch.set(command.name().equals(FetchCommand.NAME)); + public void handleOptions(OptionsProvider optionsProvider) { + PackageCacheOptions pkgOptions = optionsProvider.getOptions(PackageCacheOptions.class); + isFetch.set(pkgOptions != null && pkgOptions.fetch); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java index c26d7ad756..42280e3490 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java @@ -79,6 +79,12 @@ public final class FetchCommand implements BlazeCommand { return e.getExitCode(); } + PackageCacheOptions pkgOptions = options.getOptions(PackageCacheOptions.class); + if (pkgOptions.fetch == false) { + runtime.getReporter().handle(Event.error(null, "You cannot run fetch with --fetch=false")); + return ExitCode.COMMAND_LINE_ERROR; + } + // Querying for all of the dependencies of the targets has the side-effect of populating the // Skyframe graph for external targets, which requires downloading them. The JDK is required to // build everything but isn't counted as a dep in the build graph so we add it manually. diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java b/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java index f9d3efcb73..6db7cf63ec 100644 --- a/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java +++ b/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java @@ -139,4 +139,10 @@ public class PackageCacheOptions extends OptionsBase { category = "undocumented", help = "Threshold for number of loaded packages before skyframe-m1 cache eviction kicks in") public int minLoadedPkgCountForCtNodeEviction; + + @Option(name = "fetch", + defaultValue = "true", + category = "undocumented", + help = "Allows the command to fetch external dependencies") + public boolean fetch; } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java index 884b0ec96e..8d430191c9 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java @@ -232,6 +232,15 @@ public abstract class BlazeModule { } /** + * Does any handling of options needed by the command. + * + * <p>This method will be called at the beginning of each command (after #beforeCommand). + */ + @SuppressWarnings("unused") + public void handleOptions(OptionsProvider optionsProvider) { + } + + /** * Returns the extra options this module contributes to a specific command. * * <p>This method will be called at the beginning of each command (after #beforeCommand). diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 704cf32ad4..be4a04f811 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -805,6 +805,9 @@ public final class BlazeRuntime { throw new IllegalStateException(e); } } + for (BlazeModule module : blazeModules) { + module.handleOptions(optionsParser); + } eventBus.post(new CommandStartEvent(command.name(), commandId, clientEnv, workingDirectory)); // Initialize exit code to dummy value for afterCommand. |