Some little changes to prep for rolling forward the execroot change

This are random little nits that aren't dependent on changing the
directory structure, so it makes the (rather large) CL that is
coming cleaner.

--
PiperOrigin-RevId: 143690681
MOS_MIGRATED_REVID=143690681
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 5575e74..8072b3a 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
@@ -40,16 +40,17 @@
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Objects;
 import javax.annotation.Nullable;
 
 /**
  * An Artifact represents a file used by the build system, whether it's a source
  * file or a derived (output) file. Not all Artifacts have a corresponding
- * FileTarget object in the <code>build.packages</code> API: for example,
+ * FileTarget object in the <code>build.lib.packages</code> API: for example,
  * low-level intermediaries internal to a given rule, such as a Java class files
  * or C++ object files. However all FileTargets have a corresponding Artifact.
  *
- * <p>In any given call to Builder#buildArtifacts(), no two Artifacts in the
+ * <p>In any given call to SkyframeExecutor#buildArtifacts(), no two Artifacts in the
  * action graph may refer to the same path.
  *
  * <p>Artifacts generally fall into two classifications, source and derived, but
@@ -191,10 +192,10 @@
    * </pre>
    *
    * <p>In a derived Artifact, the execPath will overlap with part of the root, which in turn will
-   * be below of the execRoot.
+   * be below the execRoot.
    * <pre>
    *  [path] == [/root][pathTail] == [/execRoot][execPath] == [/execRoot][rootPrefix][pathTail]
-   * <pre>
+   * </pre>
    */
   @VisibleForTesting
   public Artifact(Path path, Root root, PathFragment execPath, ArtifactOwner owner) {
@@ -407,7 +408,7 @@
    * @see SpecialArtifact
    */
   @VisibleForTesting
-  public static enum SpecialArtifactType {
+  public enum SpecialArtifactType {
     FILESET,
     TREE,
     CONSTANT_METADATA,
@@ -604,7 +605,7 @@
     // We don't bother to check root in the equivalence relation, because we
     // assume that no root is an ancestor of another one.
     Artifact that = (Artifact) other;
-    return this.path.equals(that.path);
+    return Objects.equals(this.path, that.path);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java
index bba4928..7d187f9 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java
@@ -288,7 +288,8 @@
    * lives in a subpackage distinct from that of baseExecPath, and {@code baseRoot} otherwise.
    */
   public synchronized Artifact resolveSourceArtifactWithAncestor(
-      PathFragment relativePath, PathFragment baseExecPath, Root baseRoot) {
+      PathFragment relativePath, PathFragment baseExecPath, Root baseRoot,
+      RepositoryName repositoryName) {
     Preconditions.checkState(
         (baseExecPath == null) == (baseRoot == null),
         "%s %s %s",
@@ -313,7 +314,8 @@
       return null;
     }
 
-    return createArtifactIfNotValid(findSourceRoot(execPath, baseExecPath, baseRoot), execPath);
+    return createArtifactIfNotValid(
+        findSourceRoot(execPath, baseExecPath, baseRoot, repositoryName), execPath);
   }
 
   /**
@@ -322,22 +324,21 @@
    */
   @Nullable
   private Root findSourceRoot(
-      PathFragment execPath, @Nullable PathFragment baseExecPath, @Nullable Root baseRoot) {
+      PathFragment execPath, @Nullable PathFragment baseExecPath, @Nullable Root baseRoot,
+      RepositoryName repositoryName) {
     PathFragment dir = execPath.getParentDirectory();
     if (dir == null) {
       return null;
     }
 
-    RepositoryName repoName = RepositoryName.MAIN;
-
     Pair<RepositoryName, PathFragment> repo = RepositoryName.fromPathFragment(dir);
     if (repo != null) {
-      repoName = repo.getFirst();
+      repositoryName = repo.getFirst();
       dir = repo.getSecond();
     }
 
     while (dir != null && !dir.equals(baseExecPath)) {
-      Root sourceRoot = packageRoots.get(PackageIdentifier.create(repoName, dir));
+      Root sourceRoot = packageRoots.get(PackageIdentifier.create(repositoryName, dir));
       if (sourceRoot != null) {
         return sourceRoot;
       }
@@ -350,7 +351,7 @@
   @Override
   public Artifact resolveSourceArtifact(PathFragment execPath,
       @SuppressWarnings("unused") RepositoryName repositoryName) {
-    return resolveSourceArtifactWithAncestor(execPath, null, null);
+    return resolveSourceArtifactWithAncestor(execPath, null, null, repositoryName);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Root.java b/src/main/java/com/google/devtools/build/lib/actions/Root.java
index f39bced..59010e9 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Root.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Root.java
@@ -181,7 +181,7 @@
 
   @Override
   public int hashCode() {
-    return Objects.hash(execRoot, path.hashCode());
+    return Objects.hash(execRoot, path.hashCode(), isMainRepo);
   }
 
   @Override
@@ -193,7 +193,8 @@
       return false;
     }
     Root r = (Root) o;
-    return path.equals(r.path) && Objects.equals(execRoot, r.execRoot);
+    return path.equals(r.path) && Objects.equals(execRoot, r.execRoot)
+        && Objects.equals(isMainRepo, r.isMainRepo);
   }
 
   @Override
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
index ba48f7a..1e2e3d0 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
@@ -124,7 +124,7 @@
   }
 
   public PathFragment getPathUnderExecRoot() {
-    return getSourceRoot();
+    return repository.getPathUnderExecRoot().getRelative(pkgName);
   }
 
   /**