diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ExternalFilesHelper.java | 13 | ||||
-rwxr-xr-x | src/test/shell/bazel/workspace_test.sh | 43 |
2 files changed, 53 insertions, 3 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 9363111e7b..745df2874b 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 @@ -14,7 +14,9 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.packages.ExternalPackage; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.RootedPath; @@ -60,7 +62,7 @@ class ExternalFilesHelper { // A file inside the package roots. INTERNAL_FILE, - // A file outside the package roots that we may pretend is immutable. + // A file outside the package roots that users of ExternalFilesHelper may pretend is immutable. EXTERNAL_IMMUTABLE_FILE, // A file outside the package roots about which we may make no other assumptions. @@ -92,8 +94,10 @@ class ExternalFilesHelper { * Potentially adds a dependency on build_id to env if this instance is configured * with errorOnExternalFiles=false and rootedPath is an external mutable file. * If errorOnExternalFiles=true and rootedPath is an external mutable file then - * a FileOutsidePackageRootsException is thrown. This method is a no-op for any - * rootedPaths that fall within the known package roots. + * a FileOutsidePackageRootsException is thrown. If the file is an external file that is + * referenced by the WORKSPACE, it gets a dependency on the //external package (and, thus, + * WORKSPACE file changes). This method is a no-op for any rootedPaths that fall within the known + * package roots. * * @param rootedPath * @param env @@ -127,6 +131,9 @@ class ExternalFilesHelper { } else { throw new FileOutsidePackageRootsException(rootedPath); } + } else if (getFileType(rootedPath) == FileType.EXTERNAL_IMMUTABLE_FILE) { + Preconditions.checkNotNull( + env.getValue(PackageValue.key(ExternalPackage.PACKAGE_IDENTIFIER))); } } } diff --git a/src/test/shell/bazel/workspace_test.sh b/src/test/shell/bazel/workspace_test.sh index 00bfd85d7b..5519435b30 100755 --- a/src/test/shell/bazel/workspace_test.sh +++ b/src/test/shell/bazel/workspace_test.sh @@ -20,6 +20,49 @@ source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ export JAVA_RUNFILES=$TEST_SRCDIR +function setup_repo() { + mkdir -p $1 + touch $1/WORKSPACE + echo $2 > $1/thing + cat > $1/BUILD <<EOF +genrule( + name = "x", + srcs = ["thing"], + cmd = "cat \$(location thing) > \$@", + outs = ["out"], +) +EOF +} + +function test_workspace_changes() { + repo_a=$TEST_TMPDIR/a + repo_b=$TEST_TMPDIR/b + setup_repo $repo_a hi + setup_repo $repo_b bye + + cat > WORKSPACE <<EOF +local_repository( + name = "x", + path = "$repo_a", +) +EOF + + bazel build @x//:x || fail "build failed" + assert_contains "hi" bazel-genfiles/out + + cat > WORKSPACE <<EOF +local_repository( + name = "x", + path = "$repo_b", +) +EOF + + bazel build @x//:x || fail "build failed" + ls -l $(bazel info execution_root)/external/x/ + assert_contains "bye" bazel-genfiles/out +} + + function test_path_with_spaces() { ws="a b" mkdir "$ws" |