From 1673b5ab20f79d010340383f8df21d2968c46888 Mon Sep 17 00:00:00 2001 From: Damien Martin-Guillerez Date: Wed, 6 Sep 2017 14:05:26 +0200 Subject: Returns repository does not exists when referring to a bind rule... ...or any other non repository rule. Using a bind rule as the name of the repository was returning a strange error "could not find handler for bind rule" which was not useful, so was replaced by a crash. Fixes #3664 Change-Id: Id0711470e6a1ab9267e05eb273900b18d0a27d6b PiperOrigin-RevId: 167706825 --- .../repository/RepositoryDelegatorFunction.java | 6 +++--- src/test/shell/bazel/external_integration_test.sh | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'src') 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 a14800870d..6f6573e0f1 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 @@ -27,7 +27,6 @@ import com.google.devtools.build.lib.skyframe.FileValue; import com.google.devtools.build.lib.skyframe.PrecomputedValue; import com.google.devtools.build.lib.skyframe.PrecomputedValue.Precomputed; import com.google.devtools.build.lib.skyframe.SkyFunctions; -import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -122,6 +121,7 @@ public final class RepositoryDelegatorFunction implements SkyFunction { if (rule == null) { return null; } + RepositoryFunction handler; if (rule.getRuleClassObject().isSkylark()) { handler = skylarkHandler; @@ -129,8 +129,8 @@ public final class RepositoryDelegatorFunction implements SkyFunction { handler = handlers.get(rule.getRuleClass()); } if (handler == null) { - throw new IllegalStateException( - new EvalException(rule.getLocation(), "Could not find handler for " + rule)); + // If we refer to a non repository rule then the repository does not exist. + return RepositoryDirectoryValue.NO_SUCH_REPOSITORY_VALUE; } handler.setClientEnvironment(clientEnvironment); diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index fb16be7dfe..6d3f375500 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -813,6 +813,27 @@ EOF expect_log "//external:androidsdk" } +function test_use_bind_as_repository() { + cat > WORKSPACE <<'EOF' +local_repository(name = 'foobar', path = 'foo') +bind(name = 'foo', actual = '@foobar//:test') +EOF + mkdir foo + touch foo/WORKSPACE + touch foo/test + echo 'exports_files(["test"])' > foo/BUILD + cat > BUILD <<'EOF' +genrule( + name = "foo", + srcs = ["@foo//:test"], + cmd = "echo $< | tee $@", + outs = ["foo.txt"], +) +EOF + bazel build :foo &> "$TEST_log" && fail "Expected failure" || true + expect_log "no such package '@foo//'" +} + function test_flip_flopping() { REPO_PATH=$TEST_TMPDIR/repo mkdir -p "$REPO_PATH" -- cgit v1.2.3