aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2015-05-14 18:18:35 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-05-15 09:44:55 +0000
commit6cad14ed42aadc8269bfcef86cc7fefeb4d82416 (patch)
tree67bd6e527d2c10d6919ef103e59f0f464f49a1ac /src
parentb3dece0edf7ad45ef0bfca9c0d50ea7198f43c51 (diff)
Create a --fetch option to allow fetching during the build command
-- MOS_MIGRATED_REVID=93639664
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeModule.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java3
-rwxr-xr-xsrc/test/shell/bazel/external_integration_test.sh3
6 files changed, 31 insertions, 5 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.
diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh
index 6e24c013b6..db2b174edf 100755
--- a/src/test/shell/bazel/external_integration_test.sh
+++ b/src/test/shell/bazel/external_integration_test.sh
@@ -449,7 +449,8 @@ EOF
# But it is required after a clean.
bazel clean --expunge
- bazel build //zoo:ball-pit >& $TEST_log && fail "Expected build to fail"
+ # TODO(kchodorow): remove the --fetch=false option once that's the default.
+ bazel build --fetch=false //zoo:ball-pit >& $TEST_log && fail "Expected build to fail"
expect_log "bazel fetch //..."
}