diff options
author | 2015-05-06 13:41:02 +0000 | |
---|---|---|
committer | 2015-05-07 14:03:43 +0000 | |
commit | 5a449cbb4aafbf3d75ce22966f8be9e761f8ab6d (patch) | |
tree | 875d8394195ef5a7ef39792f391e29958427a332 /src/main/java/com/google/devtools/build/lib/skyframe/RepositoryValue.java | |
parent | 2181bc445fa2d43caf192f4bf0d3513095e34dca (diff) |
Track BUILD file changes on new_ repositories
I noticed, while writing http://bazel.io/docs/cpp.html#including-external-libraries-an-example,
that the BUILD file didn't get reparsed when it changed. This fixes that.
--
MOS_MIGRATED_REVID=92921670
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 | 65 |
1 files changed, 59 insertions, 6 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 8272e6726a..51e3b4cea7 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,6 +15,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.base.Objects; +import com.google.common.base.Optional; import com.google.devtools.build.lib.packages.PackageIdentifier.RepositoryName; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.skyframe.SkyKey; @@ -27,14 +28,56 @@ public class RepositoryValue implements SkyValue { private final Path path; /** - * If path is a symlink, this will keep track of what the symlink actually points to (for - * checking equality). + * This is the FileValue for the [output_base]/external/repo-name directory. + * + * <p>If path is a symlink, this will keep track of what the symlink actually points to (for + * checking equality).</p> */ private final FileValue details; - public RepositoryValue(Path path, FileValue repositoryDirectory) { + /** + * If this repository is using a user-created BUILD file (any of the new_* functions) then that + * FileValue needs to be propagated up to the PackageLookup so it doesn't get pruned. The BUILD + * file symlink will be under external/, thus assumed to be immutable, thus Skyframe will prune + * it. Then user changes will be ignored (in favor of the cached version). + */ + private final Optional<FileValue> overlaidBuildFile; + + private RepositoryValue( + Path path, FileValue repositoryDirectory, Optional<FileValue> overlaidBuildFile) { this.path = path; this.details = repositoryDirectory; + this.overlaidBuildFile = overlaidBuildFile; + } + + /** + * Creates an immutable external repository. + */ + public static RepositoryValue create(FileValue repositoryDirectory) { + return new RepositoryValue( + repositoryDirectory.realRootedPath().asPath(), repositoryDirectory, + Optional.<FileValue>absent()); + } + + /** + * Creates an immutable external repository that's a symlink to elsewhere on the system. + * + * <p>For local repositories, the repository path is something like [output root]/external/repo + * and the repository value resolves that to the actual symlink it points to. We don't want to + * lose the repository path, so this constructor is used.</p> + */ + public static RepositoryValue create(Path repositoryDirectory, FileValue details) { + return new RepositoryValue(repositoryDirectory, details, Optional.<FileValue>absent()); + } + + /** + * Creates an immutable external repository with a mutable BUILD file. + */ + public static RepositoryValue createNew( + FileValue repositoryDirectory, FileValue overlaidBuildFile) { + return new RepositoryValue( + repositoryDirectory.realRootedPath().asPath(), repositoryDirectory, + Optional.of(overlaidBuildFile)); } /** @@ -51,6 +94,10 @@ public class RepositoryValue implements SkyValue { return details; } + public Optional<FileValue> getOverlaidBuildFile() { + return overlaidBuildFile; + } + @Override public boolean equals(Object other) { if (this == other) { @@ -59,14 +106,21 @@ public class RepositoryValue implements SkyValue { if (other instanceof RepositoryValue) { RepositoryValue otherValue = (RepositoryValue) other; - return path.equals(otherValue.path) && details.equals(otherValue.details); + return details.equals(otherValue.details) + && overlaidBuildFile.equals(otherValue.overlaidBuildFile); } return false; } @Override public int hashCode() { - return Objects.hashCode(path, details); + return Objects.hashCode(details, overlaidBuildFile); + } + + @Override + public String toString() { + return details + (overlaidBuildFile.isPresent() + ? " (BUILD file: " + overlaidBuildFile.get() + ")" : ""); } /** @@ -75,5 +129,4 @@ public class RepositoryValue implements SkyValue { public static SkyKey key(RepositoryName repository) { return new SkyKey(SkyFunctions.REPOSITORY, repository); } - } |