Make default values of attributes point to the main repository.

Default values of attributes (e.g. "//tools/cpp:malloc" when an attribute declaration says .name("malloc").value("//tools/cpp:malloc")) are now considered as a label inside the main repository and not inside the external repository. This is consistent with how we treat implicit/default attributes and is useful because these are usually tool dependencies.

--
MOS_MIGRATED_REVID=99160392
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
index 52f78ab..bd091a1 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
@@ -156,7 +156,8 @@
     if (value != null) { // null values are particularly possible for computed defaults.
       for (Label label : type.getLabels(value)) {
         Label absoluteLabel;
-        if (attribute.isImplicit() || attribute.isLateBound()) {
+        if (attribute.isImplicit() || attribute.isLateBound()
+          || !attributes.isAttributeValueExplicitlySpecified(attribute)) {
           // Implicit dependencies are not usually present in remote repositories. They are
           // generally tools, which go to the main repository.
           absoluteLabel = label;
diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh
index ccba557..77a5c41b 100755
--- a/src/test/shell/bazel/local_repository_test.sh
+++ b/src/test/shell/bazel/local_repository_test.sh
@@ -572,4 +572,26 @@
   bazel query '//a:foo' || fail "query failed"
 }
 
+function test_cc_binary_in_local_repository() {
+  local r=$TEST_TMPDIR/r
+  rm -fr $r
+  mkdir $r
+  touch $r/WORKSPACE
+  cat > $r/BUILD <<EOF
+cc_binary(
+    name = "bin",
+    srcs = ["bin.cc"],
+)
+EOF
+
+  cat > WORKSPACE <<EOF
+local_repository(
+    name = "r",
+    path = "$r",
+)
+EOF
+
+  bazel build --nobuild @r//:bin || fail "build failed"
+}
+
 run_suite "local repository tests"