diff options
author | ulfjack <ulfjack@google.com> | 2017-04-20 13:45:25 +0200 |
---|---|---|
committer | Klaus Aehlig <aehlig@google.com> | 2017-04-20 15:39:11 +0200 |
commit | 8989e19ab957a18f4937531dd55b5c30b207e6df (patch) | |
tree | aa9c24c56059ae4b33fb484b7499b68d16127eaa /src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java | |
parent | de48d7d8cf0fe3d87e348e74e10506d160495428 (diff) |
Rewrite repository lookup to return a failed value rather than throw
We need to lookup repositories as part of converting exec paths to artifacts,
which in turn is needed for action cache lookups. These lookups should not
cause a Skyframe exit, so we must not throw an exception here, unless the
error makes it impossible to continue. Instead, we need to leave the decision
whether to error out or not to the caller.
Note that we may unnecessarily fetch a remote repository in order to do the
action cache lookup, even if the action no longer depends on the input file,
although this should only be possible for C++ compile actions. It's possible
that there's another bug in the C++ compile action key computation that also
contributes.
This change also makes it so that the post-resolution action cache code
ignores any errors wrt. repository lookup rather than throwing. If any of the
paths could not be found, then the action cache lookup fails and we re-execute
the corresponding action, which is exactly what should happen.
Fixes #2759.
PiperOrigin-RevId: 153696243
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java | 118 |
1 files changed, 88 insertions, 30 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java index cc055ab512..575c2a2d86 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java @@ -15,51 +15,109 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; -/** - * A repository's name and directory. - */ -public class RepositoryValue implements SkyValue { - private final RepositoryName repositoryName; - private final RepositoryDirectoryValue repositoryDirectory; - - /** - * Creates a repository with a given name in a certain directory. - */ - public RepositoryValue(RepositoryName repositoryName, RepositoryDirectoryValue repository) { - this.repositoryName = repositoryName; - this.repositoryDirectory = repository; - } +/** A repository's name and directory. */ +public abstract class RepositoryValue implements SkyValue { + public abstract boolean repositoryExists(); - /** - * Returns the path to the repository. - */ - public Path getPath() { - return repositoryDirectory.getPath(); - } + /** Returns the path to the repository. */ + public abstract Path getPath(); - @Override - public boolean equals(Object other) { - if (this == other) { + /** Successful lookup value. */ + public static final class SuccessfulRepositoryValue extends RepositoryValue { + private final RepositoryName repositoryName; + private final RepositoryDirectoryValue repositoryDirectory; + + /** Creates a repository with a given name in a certain directory. */ + public SuccessfulRepositoryValue( + RepositoryName repositoryName, RepositoryDirectoryValue repository) { + Preconditions.checkArgument(repository.repositoryExists()); + this.repositoryName = repositoryName; + this.repositoryDirectory = repository; + } + + @Override + public boolean repositoryExists() { return true; } - if (other == null || getClass() != other.getClass()) { + + @Override + public Path getPath() { + return repositoryDirectory.getPath(); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other == null || getClass() != other.getClass()) { + return false; + } + + SuccessfulRepositoryValue that = (SuccessfulRepositoryValue) other; + return Objects.equal(repositoryName, that.repositoryName) + && Objects.equal(repositoryDirectory, that.repositoryDirectory); + } + + @Override + public int hashCode() { + return Objects.hashCode(repositoryName, repositoryDirectory); + } + } + + /** Repository could not be resolved. */ + public static final class NoRepositoryValue extends RepositoryValue { + private final RepositoryName repositoryName; + + private NoRepositoryValue(RepositoryName repositoryName) { + this.repositoryName = repositoryName; + } + + @Override + public boolean repositoryExists() { return false; } - RepositoryValue that = (RepositoryValue) other; - return Objects.equal(repositoryName, that.repositoryName) - && Objects.equal(repositoryDirectory, that.repositoryDirectory); + @Override + public Path getPath() { + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other == null || getClass() != other.getClass()) { + return false; + } + + NoRepositoryValue that = (NoRepositoryValue) other; + return Objects.equal(repositoryName, that.repositoryName); + } + + @Override + public int hashCode() { + return repositoryName.hashCode(); + } + } + + public static RepositoryValue success( + RepositoryName repositoryName, RepositoryDirectoryValue repository) { + return new SuccessfulRepositoryValue(repositoryName, repository); } - @Override - public int hashCode() { - return Objects.hashCode(repositoryName, repositoryDirectory); + public static RepositoryValue notFound(RepositoryName repositoryName) { + // TODO(ulfjack): Store the cause here? The two possible causes are that the external package + // contains errors, or that the repository with the given name does not exist. + return new NoRepositoryValue(repositoryName); } public static SkyKey key(RepositoryName repositoryName) { |