Rollback of commit 4b73e972d909bcd533f2f9940f95a00b9b73bdde.

*** Reason for rollback ***

Broke tests on CI: http://ci.bazel.io/job/bazel-tests/570/


*** Original change description ***

Roll forward execroot change

RELNOTES[INC]: Previously, an external repository would be symlinked into the
execution root at execroot/local_repo/external/remote_repo. This changes it to
be at execroot/remote_repo. This may break genrules/Skylark actions that
hardcode execution root paths. If this causes breakages for you, ensure that
genrules are using $(location :target) to access files and Skylark rules are
using http://bazel.io/docs/skylark/lib/File.html's path, dirname, etc.
functions. Cust...

--
PiperOrigin-RevId: 147833177
MOS_MIGRATED_REVID=147833177
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
index 4378934..4b7adbc 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
@@ -139,6 +139,7 @@
     throw new ComparisonException("Cannot compare artifact with " + EvalUtils.getDataTypeName(o));
   }
 
+
   /** An object that can expand middleman artifacts. */
   public interface ArtifactExpander {
 
@@ -210,6 +211,7 @@
     this.hashCode = path.hashCode();
     this.path = path;
     this.root = root;
+    this.execPath = execPath;
     // These two lines establish the invariant that
     // execPath == rootRelativePath <=> execPath.equals(rootRelativePath)
     // This is important for isSourceArtifact.
@@ -219,7 +221,6 @@
           + rootRel + " at " + path + " with root " + root);
     }
     this.rootRelativePath = rootRel.equals(execPath) ? execPath : rootRel;
-    this.execPath = externalfy(execPath);
     this.owner = Preconditions.checkNotNull(owner, path);
   }
 
@@ -368,12 +369,7 @@
     doc = "Returns true if this is a source file, i.e. it is not generated."
   )
   public final boolean isSourceArtifact() {
-     // All source roots should, you know, point to sources. However, for embedded binaries, they
-     // are actually created as derived artifacts, so we have to special-case isSourceArtifact to
-     // treat derived roots in the main repo where execPath==rootRelPath as source roots.
-     // Source artifacts have reference-identical execPaths and rootRelativePaths, so use
-     // of == instead of .equals() is intentional here.
-    return execPath == rootRelativePath || root.isSourceRoot();
+    return execPath == rootRelativePath;
   }
 
   /**
@@ -544,9 +540,15 @@
    * For targets in external repositories, this returns the path the artifact live at in the
    * runfiles tree. For local targets, it returns the rootRelativePath.
    */
-  // TODO(kchodorow): remove.
   public final PathFragment getRunfilesPath() {
-    return externalfy(rootRelativePath);
+    PathFragment relativePath = rootRelativePath;
+    if (relativePath.segmentCount() > 1
+        && relativePath.getSegment(0).equals(Label.EXTERNAL_PATH_PREFIX)) {
+      // Turn external/repo/foo into ../repo/foo.
+      relativePath = relativePath.relativeTo(Label.EXTERNAL_PATH_PREFIX);
+      relativePath = new PathFragment("..").getRelative(relativePath);
+    }
+    return relativePath;
   }
 
   @SkylarkCallable(
@@ -580,23 +582,7 @@
             + "runfiles of a binary."
   )
   public final String getExecPathString() {
-    return getExecPath().toString();
-  }
-
-  private PathFragment externalfy(PathFragment relativePath) {
-    if (root.isMainRepo()) {
-      return relativePath;
-    }
-
-    PathFragment prefix;
-    if (root.isSourceRoot()) {
-      prefix = new PathFragment(Label.EXTERNAL_PATH_PREFIX)
-          .getRelative(root.getPath().getBaseName());
-    } else {
-      prefix = new PathFragment(Label.EXTERNAL_PATH_PREFIX)
-          .getRelative(root.getExecRoot().getBaseName());
-    }
-    return prefix.getRelative(relativePath);
+    return getExecPath().getPathString();
   }
 
   /*