aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-12-16 11:25:36 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2015-12-16 11:40:28 +0000
commitde2183d20b39db8e9e21a006b6b2fae761dde8a6 (patch)
tree9715034b643a5f64f4893a35762e69676aa94c8f /src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java
parent60f6cf6f1d7708ac46982d190dfe03f04160e5ac (diff)
Only depend on the WORKSPACE file for external files that are under the external/ directory, i.e. were created by Bazel.
This avoids a cycle that arose when a file is load()ed from the WORKSPACE file that is reached through a symlink to an external directory: * The WORKSPACE file depends on the package lookup node of the .bzl file * The package lookup node (transitively) depends on wherever the symlink points * The target of the symlink is an external file and as such, it depends on the WORKSPACE file This will probably be, erm, interesting to solve when we get as far as to load stuff from external repositories in the WORKSPACE file, but we are just not there yet. -- MOS_MIGRATED_REVID=110344658
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java b/src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java
index 9cd807666a..de553d0dfb 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java
@@ -23,7 +23,6 @@ import java.util.concurrent.atomic.AtomicReference;
/** Common utilities for dealing with files outside the package roots. */
public class ExternalFilesHelper {
-
private final AtomicReference<PathPackageLocator> pkgLocator;
private final ExternalFileAction externalFileAction;
@@ -78,27 +77,31 @@ public class ExternalFilesHelper {
}
externalFileSeen = true;
- if (externalFileAction == ExternalFileAction.DEPEND_ON_EXTERNAL_PKG) {
- // For files outside the package roots, add a dependency on the //external package so that if
- // the WORKSPACE file changes, the File/DirectoryStateValue will be re-evaluated.
- //
- // Note that:
- // - We don't add a dependency on the parent directory at the package root boundary, so
- // the only transitive dependencies from files inside the package roots to external files
- // are through symlinks. So the upwards transitive closure of external files is small.
- // - The only way other than external repositories for external source files to get into the
- // skyframe graph in the first place is through symlinks outside the package roots, which we
- // neither want to encourage nor optimize for since it is not common. So the set of external
- // files is small.
- // TODO(kchodorow): check that the path is under output_base/external before adding the dep.
- PackageValue pkgValue = (PackageValue) env.getValue(PackageValue.key(
- Label.EXTERNAL_PACKAGE_IDENTIFIER));
- if (pkgValue == null) {
- return;
- }
- Preconditions.checkState(!pkgValue.getPackage().containsErrors());
- } else {
+ if (externalFileAction == ExternalFileAction.ERROR_OUT) {
throw new FileOutsidePackageRootsException(rootedPath);
}
+
+ if (!rootedPath.asPath().startsWith(
+ pkgLocator.get().getOutputBase().getRelative(Label.EXTERNAL_PATH_PREFIX))) {
+ return;
+ }
+
+ // For files that are under $OUTPUT_BASE/external, add a dependency on the //external package
+ // so that if the WORKSPACE file changes, the File/DirectoryStateValue will be re-evaluated.
+ //
+ // Note that:
+ // - We don't add a dependency on the parent directory at the package root boundary, so
+ // the only transitive dependencies from files inside the package roots to external files
+ // are through symlinks. So the upwards transitive closure of external files is small.
+ // - The only way other than external repositories for external source files to get into the
+ // skyframe graph in the first place is through symlinks outside the package roots, which we
+ // neither want to encourage nor optimize for since it is not common. So the set of external
+ // files is small.
+ PackageValue pkgValue = (PackageValue) env.getValue(PackageValue.key(
+ Label.EXTERNAL_PACKAGE_IDENTIFIER));
+ if (pkgValue == null) {
+ return;
+ }
+ Preconditions.checkState(!pkgValue.getPackage().containsErrors());
}
}