Refactor delegator function for clearer understanding
PiperOrigin-RevId: 574440757
Change-Id: Ib37f1024709a5d604913088efdbfbd71d869d308
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 c9f8fb7..d3f9fe3 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
@@ -570,11 +570,11 @@
// That key will be reinjected by the sync command with a universally unique identifier.
// Nevertheless, we need to provide a default value for other commands.
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_CONFIGURING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH_CONFIGURE,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(ModuleFileFunction.REGISTRIES, registries),
PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, ignoreDevDeps.get()),
PrecomputedValue.injected(
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
index 7ea65ed..9f37d1a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
@@ -109,14 +109,13 @@
skyframeExecutor.injectExtraPrecomputedValues(
ImmutableList.of(
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_CONFIGURING,
+ RepositoryDelegatorFunction.FORCE_FETCH_CONFIGURE,
env.getCommandId().toString())));
} else {
skyframeExecutor.injectExtraPrecomputedValues(
ImmutableList.of(
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- env.getCommandId().toString())));
+ RepositoryDelegatorFunction.FORCE_FETCH, env.getCommandId().toString())));
}
// Obtain the key for the top-level WORKSPACE file
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
index 8beb96e..845c8b6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
@@ -15,8 +15,11 @@
package com.google.devtools.build.lib.rules.repository;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.actions.FileValue;
@@ -48,7 +51,6 @@
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
@@ -68,16 +70,16 @@
public static final Precomputed<Map<RepositoryName, PathFragment>> REPOSITORY_OVERRIDES =
new Precomputed<>("repository_overrides");
- public static final Precomputed<String> DEPENDENCY_FOR_UNCONDITIONAL_FETCHING =
- new Precomputed<>("dependency_for_unconditional_repository_fetching");
+ public static final Precomputed<String> FORCE_FETCH =
+ new Precomputed<>("dependency_for_force_fetching_repository");
- public static final Precomputed<String> DEPENDENCY_FOR_UNCONDITIONAL_CONFIGURING =
- new Precomputed<>("dependency_for_unconditional_configuring");
+ public static final Precomputed<String> FORCE_FETCH_CONFIGURE =
+ new Precomputed<>("dependency_for_force_fetching_configure_repositories");
public static final Precomputed<Optional<RootedPath>> RESOLVED_FILE_INSTEAD_OF_WORKSPACE =
new Precomputed<>("resolved_file_instead_of_workspace");
- public static final String DONT_FETCH_UNCONDITIONALLY = "";
+ public static final String FORCE_FETCH_DISABLED = "";
// The marker file version is inject in the rule key digest so the rule key is always different
// when we decide to update the format.
@@ -85,18 +87,13 @@
// Mapping of rule class name to RepositoryFunction.
private final ImmutableMap<String, RepositoryFunction> handlers;
-
// Delegate function to handle Starlark remote repositories
private final RepositoryFunction starlarkHandler;
-
// This is a reference to isFetch in BazelRepositoryModule, which tracks whether the current
// command is a fetch. Remote repository lookups are only allowed during fetches.
private final AtomicBoolean isFetch;
-
private final BlazeDirectories directories;
-
private final ExternalPackageHelper externalPackageHelper;
-
private final Supplier<Map<String, String>> clientEnvironmentSupplier;
public RepositoryDelegatorFunction(
@@ -115,6 +112,247 @@
}
@Nullable
+ @Override
+ public SkyValue compute(SkyKey skyKey, Environment env)
+ throws InterruptedException, RepositoryFunctionException {
+ StarlarkSemantics starlarkSemantics = PrecomputedValue.STARLARK_SEMANTICS.get(env);
+ if (starlarkSemantics == null) {
+ return null;
+ }
+ RepositoryName repositoryName = (RepositoryName) skyKey.argument();
+ if (!repositoryName.isVisible()) {
+ return new NoRepositoryDirectoryValue(
+ String.format(
+ "No repository visible as '@%s' from %s",
+ repositoryName.getName(), repositoryName.getOwnerRepoDisplayString()));
+ }
+
+ Path repoRoot =
+ RepositoryFunction.getExternalRepositoryDirectory(directories)
+ .getRelative(repositoryName.getName());
+ Map<RepositoryName, PathFragment> overrides = REPOSITORY_OVERRIDES.get(env);
+ if (Preconditions.checkNotNull(overrides).containsKey(repositoryName)) {
+ DigestWriter.clearMarkerFile(directories, repositoryName);
+ return setupOverride(overrides.get(repositoryName), env, repoRoot, repositoryName.getName());
+ }
+
+ Rule rule = null;
+ if (starlarkSemantics.getBool(BuildLanguageOptions.ENABLE_BZLMOD)) {
+ // Tries to get a repository rule instance from Bzlmod generated repos.
+ SkyKey key = BzlmodRepoRuleValue.key(repositoryName);
+ BzlmodRepoRuleValue value = (BzlmodRepoRuleValue) env.getValue(key);
+ if (env.valuesMissing()) {
+ return null;
+ }
+ if (value != BzlmodRepoRuleValue.REPO_RULE_NOT_FOUND_VALUE) {
+ rule = value.getRule();
+ }
+ }
+
+ if (rule == null) {
+ // fallback to look up the repository in the WORKSPACE file.
+ try {
+ rule = getRepoRuleFromWorkspace(repositoryName, env);
+ if (env.valuesMissing()) {
+ return null;
+ }
+ } catch (NoSuchRepositoryException e) {
+ return new NoRepositoryDirectoryValue(
+ String.format("Repository '%s' is not defined", repositoryName.getCanonicalForm()));
+ }
+ }
+
+ RepositoryFunction handler = getHandler(rule);
+ if (handler == null) {
+ // If we refer to a non repository rule then the repository does not exist.
+ return new NoRepositoryDirectoryValue(
+ String.format("'%s' is not a repository rule", repositoryName.getCanonicalForm()));
+ }
+
+ DigestWriter digestWriter = new DigestWriter(directories, repositoryName, rule);
+ if (shouldUseCachedRepos(env, handler, repoRoot, rule)) {
+ // Make sure marker file is up-to-date; correctly describes the current repository state
+ byte[] markerHash = digestWriter.areRepositoryAndMarkerFileConsistent(handler, env);
+ if (env.valuesMissing()) {
+ return null;
+ }
+ if (markerHash != null) {
+ return RepositoryDirectoryValue.builder().setPath(repoRoot).setDigest(markerHash).build();
+ }
+ }
+
+ /* At this point: This is a force fetch, a local repository, OR The repository cache is old or
+ didn't exist. In any of those cases, we initiate the fetching process UNLESS this is offline
+ mode (fetching is disabled) */
+ if (isFetch.get()) {
+ // Fetching a repository is a long-running operation that can easily be interrupted. If it is
+ // and the marker file exists on disk, a new call of this method may treat this repository as
+ // valid even though it is in an inconsistent state. Clear the marker file and only recreate
+ // it after fetching is done to prevent this scenario.
+ DigestWriter.clearMarkerFile(directories, repositoryName);
+ RepositoryDirectoryValue.Builder builder =
+ fetchRepository(skyKey, repoRoot, env, digestWriter.getMarkerData(), handler, rule);
+ if (builder == null) {
+ return null;
+ }
+ // No new Skyframe dependencies must be added between calling the repository implementation
+ // and writing the marker file because if they aren't computed, it would cause a Skyframe
+ // restart thus calling the possibly very slow (networking, decompression...) fetch()
+ // operation again. So we write the marker file here immediately.
+ byte[] digest = digestWriter.writeMarkerFile();
+ return builder.setDigest(digest).build();
+ }
+
+ if (!repoRoot.exists()) {
+ // The repository isn't on the file system, there is nothing we can do.
+ throw new RepositoryFunctionException(
+ new IOException(
+ "to fix, run\n\tbazel fetch //...\nExternal repository "
+ + repositoryName.getNameWithAt()
+ + " not found and fetching repositories is disabled."),
+ Transience.TRANSIENT);
+ }
+
+ // Try to build with whatever is on the file system and emit a warning.
+ env.getListener()
+ .handle(Event.warn(rule.getLocation(),
+ String.format(
+ "External repository '%s' is not up-to-date and fetching is disabled. To update, "
+ + "run the build without the '--nofetch' command line option.",
+ rule.getName())));
+
+ return RepositoryDirectoryValue.builder()
+ .setPath(repoRoot)
+ .setFetchingDelayed()
+ .setDigest(new Fingerprint().digestAndReset())
+ .build();
+ }
+
+ @Nullable
+ @Override
+ public String extractTag(SkyKey skyKey) {
+ return null;
+ }
+
+ private RepositoryFunction getHandler(Rule rule) {
+ RepositoryFunction handler;
+ if (rule.getRuleClassObject().isStarlark()) {
+ handler = starlarkHandler;
+ } else {
+ handler = handlers.get(rule.getRuleClass());
+ }
+ if (handler != null) {
+ handler.setClientEnvironment(clientEnvironmentSupplier.get());
+ }
+
+ return handler;
+ }
+
+ /* Determines whether we should use the cached repositories */
+ private boolean shouldUseCachedRepos(
+ Environment env, RepositoryFunction handler, Path repoRoot, Rule rule)
+ throws InterruptedException {
+ boolean forceFetchEnabled = !FORCE_FETCH.get(env).isEmpty();
+ boolean forceFetchConfigureEnabled =
+ handler.isConfigure(rule) && !FORCE_FETCH_CONFIGURE.get(env).isEmpty();
+
+ /* If fetching is enabled & this is a local repo: do NOT use cache!
+ * Local repository are generally fast and do not rely on non-local data, making caching them
+ * across server instances impractical. */
+ if (isFetch.get() && handler.isLocal(rule)) {
+ return false;
+ }
+
+ /* For the non-local repositories, do NOT use cache if:
+ * 1) Force fetch is enabled (bazel sync, or bazel fetch --force), OR
+ * 2) Force fetch configure is enabled (bazel sync --configure), OR
+ * 3) Repository directory does not exist */
+ if (forceFetchEnabled || forceFetchConfigureEnabled || !repoRoot.exists()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Nullable
+ private RepositoryDirectoryValue.Builder fetchRepository(
+ SkyKey skyKey,
+ Path repoRoot,
+ Environment env,
+ Map<String, String> markerData,
+ RepositoryFunction handler,
+ Rule rule)
+ throws InterruptedException, RepositoryFunctionException {
+
+ handler.setupRepoRootBeforeFetching(repoRoot);
+
+ RepositoryName repoName = (RepositoryName) skyKey.argument();
+ env.getListener().post(RepositoryFetchProgress.ongoing(repoName, "starting"));
+
+ RepositoryDirectoryValue.Builder repoBuilder;
+ try {
+ repoBuilder = handler.fetch(rule, repoRoot, directories, env, markerData, skyKey);
+ } catch (RepositoryFunctionException e) {
+ // Upon an exceptional exit, the fetching of that repository is over as well.
+ env.getListener().post(RepositoryFetchProgress.finished(repoName));
+ env.getListener().post(new RepositoryFailedEvent(repoName, e.getMessage()));
+ env.getListener()
+ .handle(
+ Event.error(
+ rule.getLocation(), String.format("fetching %s: %s", rule, e.getMessage())));
+
+ // Rewrap the underlying exception to signal callers not to re-report this error.
+ throw new RepositoryFunctionException(
+ new AlreadyReportedRepositoryAccessException(e.getCause()),
+ e.isTransient() ? Transience.TRANSIENT : Transience.PERSISTENT);
+ }
+
+ if (env.valuesMissing()) {
+ handler.reportSkyframeRestart(env, repoName);
+ return null;
+ }
+ env.getListener().post(RepositoryFetchProgress.finished(repoName));
+ return Preconditions.checkNotNull(repoBuilder);
+ }
+
+ /**
+ * Uses a remote repository name to fetch the corresponding Rule describing how to get it. This
+ * should be called from {@link SkyFunction#compute} functions, which should return null if this
+ * returns null.
+ */
+ @Nullable
+ private Rule getRepoRuleFromWorkspace(RepositoryName repositoryName, Environment env)
+ throws InterruptedException, RepositoryFunctionException, NoSuchRepositoryException {
+ try {
+ return externalPackageHelper.getRuleByName(repositoryName.getName(), env);
+ } catch (ExternalRuleNotFoundException e) {
+ // This is caught and handled immediately in compute().
+ throw new NoSuchRepositoryException();
+ } catch (ExternalPackageException e) {
+ throw new RepositoryFunctionException(e);
+ }
+ }
+
+ @Nullable
+ private RepositoryDirectoryValue setupOverride(
+ PathFragment sourcePath, Environment env, Path repoRoot, String pathAttr)
+ throws RepositoryFunctionException, InterruptedException {
+ RepositoryFunction.setupRepoRoot(repoRoot);
+ RepositoryDirectoryValue.Builder directoryValue =
+ symlinkRepoRoot(
+ directories,
+ repoRoot,
+ directories.getWorkspace().getRelative(sourcePath),
+ pathAttr,
+ env);
+ if (directoryValue == null) {
+ return null;
+ }
+ byte[] digest = new Fingerprint().addPath(sourcePath).digestAndReset();
+ return directoryValue.setDigest(digest).build();
+ }
+
+ @Nullable
public static RepositoryDirectoryValue.Builder symlinkRepoRoot(
BlazeDirectories directories,
Path source,
@@ -216,252 +454,6 @@
return value;
}
- @Nullable
- @Override
- public SkyValue compute(SkyKey skyKey, Environment env)
- throws InterruptedException, RepositoryFunctionException {
- StarlarkSemantics starlarkSemantics = PrecomputedValue.STARLARK_SEMANTICS.get(env);
- if (starlarkSemantics == null) {
- return null;
- }
- RepositoryName repositoryName = (RepositoryName) skyKey.argument();
-
- if (!repositoryName.isVisible()) {
- return new NoRepositoryDirectoryValue(
- String.format(
- "No repository visible as '@%s' from %s",
- repositoryName.getName(), repositoryName.getOwnerRepoDisplayString()));
- }
-
- Map<RepositoryName, PathFragment> overrides = REPOSITORY_OVERRIDES.get(env);
- Path repoRoot =
- RepositoryFunction.getExternalRepositoryDirectory(directories)
- .getRelative(repositoryName.getName());
-
- if (Preconditions.checkNotNull(overrides).containsKey(repositoryName)) {
- DigestWriter.clearMarkerFile(directories, repositoryName);
- return setupOverride(overrides.get(repositoryName), env, repoRoot, repositoryName.getName());
- }
-
- Rule rule = null;
- if (starlarkSemantics.getBool(BuildLanguageOptions.ENABLE_BZLMOD)) {
- // Tries to get a repository rule instance from Bzlmod generated repos.
- SkyKey key = BzlmodRepoRuleValue.key(repositoryName);
- BzlmodRepoRuleValue value = (BzlmodRepoRuleValue) env.getValue(key);
-
- if (env.valuesMissing()) {
- return null;
- }
-
- if (value != BzlmodRepoRuleValue.REPO_RULE_NOT_FOUND_VALUE) {
- rule = value.getRule();
- }
- }
-
- if (rule == null) {
- // fallback to look up the repository in the WORKSPACE file.
- try {
- rule = getRepoRuleFromWorkspace(repositoryName, env);
- if (env.valuesMissing()) {
- return null;
- }
- } catch (NoSuchRepositoryException e) {
- return new NoRepositoryDirectoryValue(
- String.format("Repository '%s' is not defined", repositoryName.getCanonicalForm()));
- }
- }
-
- RepositoryFunction handler = getHandler(rule);
- if (handler == null) {
- // If we refer to a non repository rule then the repository does not exist.
- return new NoRepositoryDirectoryValue(
- String.format("'%s' is not a repository rule", repositoryName.getCanonicalForm()));
- }
-
- boolean needsConfiguring = false;
- if (handler.isConfigure(rule)) {
- needsConfiguring =
- !DONT_FETCH_UNCONDITIONALLY.equals(DEPENDENCY_FOR_UNCONDITIONAL_CONFIGURING.get(env));
- }
- if (env.valuesMissing()) {
- return null;
- }
-
- DigestWriter digestWriter = new DigestWriter(directories, repositoryName, rule);
- boolean doNotFetchUnconditionally =
- DONT_FETCH_UNCONDITIONALLY.equals(DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.get(env));
-
- // Local repositories are fetched regardless of the marker file because the operation is
- // generally fast and they do not depend on non-local data, so it does not make much sense to
- // try to cache them from across server instances.
- boolean fetchLocalRepositoryAlways = isFetch.get() && handler.isLocal(rule);
- if (!fetchLocalRepositoryAlways) {
- // For the non-local repositories, check if they are already up-to-date:
- // 1) unconditional fetching is not enabled, AND
- // 2) unconditional syncing is not enabled or the rule is not a configure rule, AND
- // 3) repository directory exists, AND
- // 4) marker file correctly describes the current repository state
- if (!needsConfiguring && doNotFetchUnconditionally && repoRoot.exists()) {
- byte[] markerHash = digestWriter.areRepositoryAndMarkerFileConsistent(handler, env);
- if (env.valuesMissing()) {
- return null;
- }
- if (markerHash != null) {
- return RepositoryDirectoryValue.builder()
- .setPath(repoRoot)
- .setDigest(markerHash)
- .build();
- }
- }
- }
-
- if (isFetch.get()) {
- // Fetching a repository is a long-running operation that can easily be interrupted. If it is
- // and the marker file exists on disk, a new call of this method may treat this repository as
- // valid even though it is in an inconsistent state. Clear the marker file and only recreate
- // it after fetching is done to prevent this scenario.
- DigestWriter.clearMarkerFile(directories, repositoryName);
- // Fetching enabled, go ahead.
- RepositoryDirectoryValue.Builder builder =
- fetchRepository(skyKey, repoRoot, env, digestWriter.getMarkerData(), handler, rule);
- if (builder == null) {
- return null;
- }
-
- // No new Skyframe dependencies must be added between calling the repository implementation
- // and writing the marker file because if they aren't computed, it would cause a Skyframe
- // restart thus calling the possibly very slow (networking, decompression...) fetch()
- // operation again. So we write the marker file here immediately.
- byte[] digest = digestWriter.writeMarkerFile();
- return builder.setDigest(digest).build();
- }
-
- if (!repoRoot.exists()) {
- // The repository isn't on the file system, there is nothing we can do.
- throw new RepositoryFunctionException(
- new IOException(
- "External repository "
- + repositoryName.getNameWithAt()
- + " not found and fetching repositories is disabled."),
- Transience.TRANSIENT);
- }
-
- // Try to build with whatever is on the file system and emit a warning.
- env.getListener()
- .handle(Event.warn(rule.getLocation(),
- String.format(
- "External repository '%s' is not up-to-date and fetching is disabled. To update, "
- + "run the build without the '--nofetch' command line option.",
- rule.getName())));
-
- return RepositoryDirectoryValue.builder()
- .setPath(repoRoot)
- .setFetchingDelayed()
- .setDigest(new Fingerprint().digestAndReset())
- .build();
- }
-
- private RepositoryFunction getHandler(Rule rule) {
- RepositoryFunction handler;
- if (rule.getRuleClassObject().isStarlark()) {
- handler = starlarkHandler;
- } else {
- handler = handlers.get(rule.getRuleClass());
- }
- if (handler != null) {
- handler.setClientEnvironment(clientEnvironmentSupplier.get());
- }
-
- return handler;
- }
-
- @Nullable
- private RepositoryDirectoryValue.Builder fetchRepository(
- SkyKey skyKey,
- Path repoRoot,
- Environment env,
- Map<String, String> markerData,
- RepositoryFunction handler,
- Rule rule)
- throws InterruptedException, RepositoryFunctionException {
-
- handler.setupRepoRootBeforeFetching(repoRoot);
-
- RepositoryName repoName = (RepositoryName) skyKey.argument();
- env.getListener().post(RepositoryFetchProgress.ongoing(repoName, "starting"));
-
- RepositoryDirectoryValue.Builder repoBuilder;
- try {
- repoBuilder = handler.fetch(rule, repoRoot, directories, env, markerData, skyKey);
- } catch (RepositoryFunctionException e) {
- // Upon an exceptional exit, the fetching of that repository is over as well.
- env.getListener().post(RepositoryFetchProgress.finished(repoName));
- env.getListener().post(new RepositoryFailedEvent(repoName, e.getMessage()));
- env.getListener()
- .handle(
- Event.error(
- rule.getLocation(), String.format("fetching %s: %s", rule, e.getMessage())));
-
- // Rewrap the underlying exception to signal callers not to re-report this error.
- throw new RepositoryFunctionException(
- new AlreadyReportedRepositoryAccessException(e.getCause()),
- e.isTransient() ? Transience.TRANSIENT : Transience.PERSISTENT);
- }
-
- if (env.valuesMissing()) {
- handler.reportSkyframeRestart(env, repoName);
- return null;
- }
- env.getListener().post(RepositoryFetchProgress.finished(repoName));
- return Preconditions.checkNotNull(repoBuilder);
- }
-
- /**
- * Uses a remote repository name to fetch the corresponding Rule describing how to get it. This
- * should be called from {@link SkyFunction#compute} functions, which should return null if this
- * returns null.
- */
- @Nullable
- private Rule getRepoRuleFromWorkspace(RepositoryName repositoryName, Environment env)
- throws InterruptedException, RepositoryFunctionException, NoSuchRepositoryException {
- try {
- return externalPackageHelper.getRuleByName(repositoryName.getName(), env);
- } catch (ExternalRuleNotFoundException e) {
- // This is caught and handled immediately in compute().
- throw new NoSuchRepositoryException();
- } catch (ExternalPackageException e) {
- throw new RepositoryFunctionException(e);
- }
- }
-
- /** Marker exception for the case where a repository is not defined. */
- private static final class NoSuchRepositoryException extends Exception {}
-
- @Nullable
- @Override
- public String extractTag(SkyKey skyKey) {
- return null;
- }
-
- @Nullable
- private RepositoryDirectoryValue setupOverride(
- PathFragment sourcePath, Environment env, Path repoRoot, String pathAttr)
- throws RepositoryFunctionException, InterruptedException {
- RepositoryFunction.setupRepoRoot(repoRoot);
- RepositoryDirectoryValue.Builder directoryValue =
- symlinkRepoRoot(
- directories,
- repoRoot,
- directories.getWorkspace().getRelative(sourcePath),
- pathAttr,
- env);
- if (directoryValue == null) {
- return null;
- }
- byte[] digest = new Fingerprint().addPath(sourcePath).digestAndReset();
- return directoryValue.setDigest(digest).build();
- }
-
// Escape a value for the marker file
@VisibleForTesting
static String escape(String str) {
@@ -521,7 +513,7 @@
}
String content = builder.toString();
try {
- FileSystemUtils.writeContent(markerPath, StandardCharsets.UTF_8, content);
+ FileSystemUtils.writeContent(markerPath, UTF_8, content);
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
@@ -552,7 +544,7 @@
Map<String, String> markerData = new TreeMap<>();
String content;
try {
- content = FileSystemUtils.readContent(markerPath, StandardCharsets.UTF_8);
+ content = FileSystemUtils.readContent(markerPath, UTF_8);
String markerRuleKey = readMarkerFile(content, markerData);
boolean verified = false;
if (Preconditions.checkNotNull(ruleKey).equals(markerRuleKey)) {
@@ -581,7 +573,7 @@
@Nullable
private String readMarkerFile(String content, Map<String, String> markerData) {
String markerRuleKey = null;
- String[] lines = content.split("\n");
+ Iterable<String> lines = Splitter.on('\n').split(content);
boolean firstLine = true;
for (String line : lines) {
@@ -624,4 +616,6 @@
}
}
+ /** Marker exception for the case where a repository is not defined. */
+ private static final class NoSuchRepositoryException extends Exception {}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java b/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java
index 81338f6..7ccddb7 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/BazelPackageLoader.java
@@ -105,12 +105,12 @@
PrecomputedValue.injected(
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE, Optional.empty()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_CONFIGURING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH_CONFIGURE,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(ModuleFileFunction.REGISTRIES, ImmutableList.of()),
PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
PrecomputedValue.injected(
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java
index 1a832dd..e49ea3b 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisMock.java
@@ -192,8 +192,8 @@
PrecomputedValue.injected(
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE, Optional.empty()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(ModuleFileFunction.REGISTRIES, ImmutableList.of()),
PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
PrecomputedValue.injected(ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()),
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
index d09d687..2ef4e35 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
@@ -287,8 +287,8 @@
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(
BuildInfoCollectionFunction.BUILD_INFO_FACTORIES,
ruleClassProvider.getBuildInfoFactoriesAsMap()),
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java
index 1b024e3..7dc52f5 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java
@@ -138,8 +138,8 @@
PrecomputedValue.injected(
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY),
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
PrecomputedValue.injected(
BuildInfoCollectionFunction.BUILD_INFO_FACTORIES,
ruleClassProvider.getBuildInfoFactoriesAsMap())));
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java
index dcd6b49..25cfa1e 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileFunctionTest.java
@@ -211,8 +211,8 @@
differencer, CheckDirectDepsMode.ERROR);
BazelLockFileFunction.LOCKFILE_MODE.set(differencer, LockfileMode.UPDATE);
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java
index 5bd9f56..24b262b 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java
@@ -195,8 +195,8 @@
differencer,
StarlarkSemantics.builder().setBool(BuildLanguageOptions.ENABLE_BZLMOD, true).build());
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, packageLocator.get());
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
differencer, Optional.empty());
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
index a971372..d57f14e 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
@@ -279,8 +279,8 @@
.setBool(BuildLanguageOptions.EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, true)
.build());
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, packageLocator.get());
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
differencer, Optional.empty());
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
index 53f267e..4b68069 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
@@ -164,8 +164,8 @@
differencer,
StarlarkSemantics.builder().setBool(BuildLanguageOptions.ENABLE_BZLMOD, true).build());
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, packageLocator.get());
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
differencer, Optional.empty());
diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java b/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
index cc091df..cf6cf82 100644
--- a/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
@@ -210,8 +210,8 @@
PrecomputedValue.injected(
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY));
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED));
protected EventCollectionApparatus createEvents() {
return new EventCollectionApparatus();
diff --git a/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java b/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java
index a2c3682..f841168 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java
@@ -405,37 +405,27 @@
.setSyscallCache(delegatingSyscallCache)
.build();
skyframeExecutor.injectExtraPrecomputedValues(
- ImmutableList.<PrecomputedValue.Injected>builder()
- .add(
- PrecomputedValue.injected(
- RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE,
- Optional.empty()))
- .add(
- PrecomputedValue.injected(
- RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()))
- .add(PrecomputedValue.injected(ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()))
- .add(
- PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY))
- .add(
- PrecomputedValue.injected(
- ModuleFileFunction.REGISTRIES, ImmutableList.of(registry.getUrl())))
- .add(PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false))
- .add(
- PrecomputedValue.injected(
- BazelModuleResolutionFunction.CHECK_DIRECT_DEPENDENCIES,
- CheckDirectDepsMode.WARNING))
- .add(
- PrecomputedValue.injected(
- YankedVersionsUtil.ALLOWED_YANKED_VERSIONS, ImmutableList.of()))
- .add(
- PrecomputedValue.injected(
- BazelModuleResolutionFunction.BAZEL_COMPATIBILITY_MODE,
- BazelCompatibilityMode.ERROR))
- .add(
- PrecomputedValue.injected(BazelLockFileFunction.LOCKFILE_MODE, LockfileMode.UPDATE))
- .build());
+ ImmutableList.of(
+ PrecomputedValue.injected(
+ RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE, Optional.empty()),
+ PrecomputedValue.injected(
+ RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()),
+ PrecomputedValue.injected(ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()),
+ PrecomputedValue.injected(
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED),
+ PrecomputedValue.injected(
+ ModuleFileFunction.REGISTRIES, ImmutableList.of(registry.getUrl())),
+ PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
+ PrecomputedValue.injected(
+ BazelModuleResolutionFunction.CHECK_DIRECT_DEPENDENCIES,
+ CheckDirectDepsMode.WARNING),
+ PrecomputedValue.injected(
+ YankedVersionsUtil.ALLOWED_YANKED_VERSIONS, ImmutableList.of()),
+ PrecomputedValue.injected(
+ BazelModuleResolutionFunction.BAZEL_COMPATIBILITY_MODE,
+ BazelCompatibilityMode.ERROR),
+ PrecomputedValue.injected(BazelLockFileFunction.LOCKFILE_MODE, LockfileMode.UPDATE)));
SkyframeExecutorTestHelper.process(skyframeExecutor);
return skyframeExecutor;
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
index 44be64f..b4af3fe 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
@@ -266,8 +266,8 @@
overrideDirectory = scratch.dir("/foo");
scratch.file("/foo/WORKSPACE");
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
PrecomputedValue.STARLARK_SEMANTICS.set(
differencer,
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/AbstractCollectPackagesUnderDirectoryTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/AbstractCollectPackagesUnderDirectoryTest.java
index b1b4dce..a128630 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/AbstractCollectPackagesUnderDirectoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/AbstractCollectPackagesUnderDirectoryTest.java
@@ -306,8 +306,8 @@
PrecomputedValue.injected(
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES, ImmutableMap.of()),
PrecomputedValue.injected(
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING,
- RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY)));
+ RepositoryDelegatorFunction.FORCE_FETCH,
+ RepositoryDelegatorFunction.FORCE_FETCH_DISABLED)));
skyframeExecutor.sync(
reporter,
pathPackageLocator,
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java
index 42c9650..01038df 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java
@@ -192,8 +192,8 @@
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
PrecomputedValue.STARLARK_SEMANTICS.set(differencer, StarlarkSemantics.DEFAULT);
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
differencer, Optional.empty());
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
index 863fe21..32ad627 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
@@ -254,8 +254,8 @@
PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator);
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
PrecomputedValue.STARLARK_SEMANTICS.set(differencer, StarlarkSemantics.DEFAULT);
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
differencer, Optional.empty());
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
index a1bd711..7c625e2 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
@@ -204,8 +204,8 @@
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
PrecomputedValue.STARLARK_SEMANTICS.set(differencer, StarlarkSemantics.DEFAULT);
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
- RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
- differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
+ RepositoryDelegatorFunction.FORCE_FETCH.set(
+ differencer, RepositoryDelegatorFunction.FORCE_FETCH_DISABLED);
RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
differencer, Optional.empty());
}