Rename Artifact's path methods to clarify their usages and limitations.

PiperOrigin-RevId: 333359503
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Actions.java b/src/main/java/com/google/devtools/build/lib/actions/Actions.java
index 3fa883d..87cd45b 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Actions.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Actions.java
@@ -309,9 +309,9 @@
         } else {
           // No: populate the output label map with this artifact if applicable: if this
           // artifact corresponds to a target that is an OutputFile with associated rule this label.
-          PathFragment packagePath = output.getPackagePath();
-          if (packageDirectory != null && packagePath.startsWith(packageDirectory)) {
-            PathFragment packageRelativePath = packagePath.relativeTo(packageDirectory);
+          PathFragment ouputPath = output.getOutputDirRelativePath();
+          if (packageDirectory != null && ouputPath.startsWith(packageDirectory)) {
+            PathFragment packageRelativePath = ouputPath.relativeTo(packageDirectory);
             Label outputLabel = outputFileNames.get(packageRelativePath.getPathString());
             if (outputLabel != null) {
               artifactsByOutputLabel.put(outputLabel, artifact);
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 8d3f02f..27f3abf 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
@@ -616,7 +616,7 @@
    * assumptions should be made in terms of where the root portion of the path ends, and the
    * returned value almost always needs to be used in conjunction with its root.
    *
-   * <p>{#link Artifact#getPackagePath()} is more versatile for general use cases.
+   * <p>{#link Artifact#getOutputDirRelativePath()} is more versatile for general use cases.
    */
   public abstract PathFragment getRootRelativePath();
 
@@ -624,11 +624,34 @@
    * Returns the fully-qualified package path to this artifact. By "fully-qualified", it means the
    * returned path is prefixed with "external/<repository name>" if this artifact is in an external
    * repository.
+   *
+   * <p>Do not call this method just because you need a path prefixed with the "external/<repository
+   * name>" fragment for external repository artifacts. {@link * Artifact#getOutputDirRelativePath}
+   * is the right one to use in almost all cases.
+   *
+   * @deprecated This method is only to be used for $(location) and getOutputDirRelativePath
+   *     implementations.
    */
-  public PathFragment getPackagePath() {
+  @Deprecated
+  public PathFragment getPathForLocationExpansion() {
     return getRootRelativePath();
   }
 
+  /**
+   * Returns the path to this artifact relative to an output directory, e.g. the bin directory. Note
+   * that this is available on every Artifact type, including source artifacts. As a matter of fact,
+   * one of its most common use cases is to construct a derived artifact's output path out of a
+   * sibling source artifact's by replacing the basename in its output-dir-relative path.
+   *
+   * <p>This is just a wrapper over {@link Artifact#getPathForLocationExpansion} at the moment.
+   * However, since it will be kept in sync with the output directory layout, which is planned for
+   * an overhaul, it must be preferred over {@link Artifact#getPathForLocationExpansion} whenever
+   * possible.
+   */
+  public final PathFragment getOutputDirRelativePath() {
+    return getPathForLocationExpansion();
+  }
+
   /** Returns this.getExecPath().getPathString(). */
   @Override
   public final String getExecPathString() {
@@ -639,8 +662,8 @@
     return getRootRelativePath().getPathString();
   }
 
-  public final String getPackagePathString() {
-    return getPackagePath().getPathString();
+  public final String getOutputDirRelativePathString() {
+    return getOutputDirRelativePath().getPathString();
   }
 
   @Override
@@ -752,7 +775,7 @@
    * runfiles tree. For local targets, it returns the rootRelativePath.
    */
   public final PathFragment getRunfilesPath() {
-    PathFragment relativePath = getPackagePath();
+    PathFragment relativePath = getOutputDirRelativePath();
     // We can't use root.isExternalSource() here since it needs to handle derived artifacts too.
     if (relativePath.startsWith(LabelConstants.EXTERNAL_PATH_PREFIX)) {
       // Turn external/repo/foo into ../repo/foo.
@@ -858,7 +881,7 @@
     }
 
     @Override
-    public PathFragment getPackagePath() {
+    public PathFragment getPathForLocationExpansion() {
       return getExecPath();
     }
 
@@ -1279,8 +1302,8 @@
   public static final Function<Artifact, String> ROOT_RELATIVE_PATH_STRING =
       artifact -> artifact.getRootRelativePath().getPathString();
 
-  public static final Function<Artifact, String> PACKAGE_PATH_STRING =
-      artifact -> artifact.getPackagePath().getPathString();
+  public static final Function<Artifact, String> OUTPUT_DIR_RELATIVE_PATH_STRING =
+      artifact -> artifact.getOutputDirRelativePath().getPathString();
 
   /**
    * Converts a collection of artifacts into execution-time path strings, and
@@ -1333,21 +1356,21 @@
   }
 
   /**
-   * Lazily converts artifacts into package path strings. Middleman artifacts are ignored by this
-   * method.
+   * Lazily converts artifacts into output-dir-relative path strings. Middleman artifacts are
+   * ignored by this method.
    */
-  public static Iterable<String> toPackagePaths(NestedSet<Artifact> artifacts) {
-    return toPackagePaths(artifacts.toList());
+  public static Iterable<String> toOutputDirRelativePaths(NestedSet<Artifact> artifacts) {
+    return toOutputDirRelativePaths(artifacts.toList());
   }
 
   /**
-   * Lazily converts artifacts into package path strings. Middleman artifacts are ignored by this
-   * method.
+   * Lazily converts artifacts into output-dir-relative path strings. Middleman artifacts are
+   * ignored by this method.
    */
-  public static Iterable<String> toPackagePaths(Iterable<Artifact> artifacts) {
+  public static Iterable<String> toOutputDirRelativePaths(Iterable<Artifact> artifacts) {
     return Iterables.transform(
         Iterables.filter(artifacts, MIDDLEMAN_FILTER),
-        artifact -> artifact.getPackagePath().getPathString());
+        artifact -> artifact.getOutputDirRelativePath().getPathString());
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
index c17ede5..e11c070 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
@@ -63,7 +63,7 @@
   private static final boolean EXACTLY_ONE = false;
   private static final boolean ALLOW_MULTIPLE = true;
 
-  private static final boolean USE_PACKAGE_PATHS = false;
+  private static final boolean USE_LOCATION_PATHS = false;
   private static final boolean USE_EXEC_PATHS = true;
 
   private final RuleErrorConsumer ruleErrorConsumer;
@@ -95,7 +95,7 @@
    * @param ruleContext BUILD rule
    * @param labelMap A mapping of labels to build artifacts.
    * @param execPaths If true, this expander will expand $(location)/$(locations) using
-   *     Artifact.getExecPath(); otherwise with Artifact.getPackagePath().
+   *     Artifact.getExecPath(); otherwise with Artifact.getLocationPath().
    * @param allowData If true, this expander will expand locations from the `data` attribute;
    *     otherwise it will not.
    */
@@ -115,9 +115,9 @@
   }
 
   /**
-   * Creates an expander that expands $(location)/$(locations) using Artifact.getPackagePath().
+   * Creates an expander that expands $(location)/$(locations) using Artifact.getLocationPath().
    *
-   * <p>The expander expands $(rootpath)/$(rootpaths) using Artifact.getPackagePath(), and
+   * <p>The expander expands $(rootpath)/$(rootpaths) using Artifact.getLocationPath(), and
    * $(execpath)/$(execpaths) using Artifact.getExecPath().
    *
    * @param ruleContext BUILD rule
@@ -129,7 +129,7 @@
   /**
    * Creates an expander that expands $(location)/$(locations) using Artifact.getExecPath().
    *
-   * <p>The expander expands $(rootpath)/$(rootpaths) using Artifact.getPackagePath(), and
+   * <p>The expander expands $(rootpath)/$(rootpaths) using Artifact.getLocationPath(), and
    * $(execpath)/$(execpaths) using Artifact.getExecPath().
    *
    * @param ruleContext BUILD rule
@@ -143,7 +143,7 @@
   /**
    * Creates an expander that expands $(location)/$(locations) using Artifact.getExecPath().
    *
-   * <p>The expander expands $(rootpath)/$(rootpaths) using Artifact.getPackagePath(), and
+   * <p>The expander expands $(rootpath)/$(rootpaths) using Artifact.getLocationPath(), and
    * $(execpath)/$(execpaths) using Artifact.getExecPath().
    *
    * @param ruleContext BUILD rule
@@ -304,13 +304,14 @@
      * Extracts list of all executables associated with given collection of label artifacts.
      *
      * @param artifacts to get the paths of
-     * @param takeExecPath if false, the package path will be taken
+     * @param takeExecPath if false, the location path will be taken
      * @return all associated executable paths
      */
     private Set<String> getPaths(Collection<Artifact> artifacts, boolean takeExecPath) {
       TreeSet<String> paths = Sets.newTreeSet();
       for (Artifact artifact : artifacts) {
-        PathFragment execPath = takeExecPath ? artifact.getExecPath() : artifact.getPackagePath();
+        PathFragment execPath =
+            takeExecPath ? artifact.getExecPath() : artifact.getPathForLocationExpansion();
         if (execPath != null) {  // omit middlemen etc
           paths.add(execPath.getCallablePathString());
         }
@@ -332,9 +333,10 @@
     return new ImmutableMap.Builder<String, LocationFunction>()
         .put("location", new LocationFunction(root, locationMap, execPaths, EXACTLY_ONE))
         .put("locations", new LocationFunction(root, locationMap, execPaths, ALLOW_MULTIPLE))
-        .put("rootpath", new LocationFunction(root, locationMap, USE_PACKAGE_PATHS, EXACTLY_ONE))
+        .put("rootpath", new LocationFunction(root, locationMap, USE_LOCATION_PATHS, EXACTLY_ONE))
         .put(
-            "rootpaths", new LocationFunction(root, locationMap, USE_PACKAGE_PATHS, ALLOW_MULTIPLE))
+            "rootpaths",
+            new LocationFunction(root, locationMap, USE_LOCATION_PATHS, ALLOW_MULTIPLE))
         .put("execpath", new LocationFunction(root, locationMap, USE_EXEC_PATHS, EXACTLY_ONE))
         .put("execpaths", new LocationFunction(root, locationMap, USE_EXEC_PATHS, ALLOW_MULTIPLE))
         .build();
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index 9e9ca93..07038bf 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -53,8 +53,8 @@
  * forming a symlink tree.
  *
  * <p>In order to reduce memory consumption, this map is not explicitly stored here, but instead as
- * a combination of three parts: artifacts placed at their root-relative paths, source tree symlinks
- * and root symlinks (outside of the source tree).
+ * a combination of three parts: artifacts placed at their output-dir-relative paths, source tree
+ * symlinks and root symlinks (outside of the source tree).
  */
 @Immutable
 @AutoCodec
@@ -168,15 +168,15 @@
    * The artifacts that should be present in the runfiles directory.
    *
    * <p>This collection may not include any middlemen. These artifacts will be placed at a location
-   * that corresponds to the root-relative path of each artifact. It's possible for several
-   * artifacts to have the same root-relative path, in which case the last one will win.
+   * that corresponds to the output-dir-relative path of each artifact. It's possible for several
+   * artifacts to have the same output-dir-relative path, in which case the last one will win.
    */
   private final NestedSet<Artifact> artifacts;
 
   /**
    * A map of symlinks that should be present in the runfiles directory. In general, the symlink can
-   * be determined from the artifact by using the root-relative path, so this should only be used
-   * for cases where that isn't possible.
+   * be determined from the artifact by using the output-dir-relative path, so this should only be
+   * used for cases where that isn't possible.
    *
    * <p>This may include runfiles symlinks from the root of the runfiles tree.
    */
@@ -299,7 +299,7 @@
     Set<PathFragment> manifestKeys =
         Streams.concat(
                 symlinks.toList().stream().map(SymlinkEntry::getPath),
-                getArtifacts().toList().stream().map(Artifact::getPackagePath))
+                getArtifacts().toList().stream().map(Artifact::getOutputDirRelativePath))
             .collect(ImmutableSet.toImmutableSet());
     Iterable<PathFragment> emptyKeys = emptyFilesSupplier.getExtraPaths(manifestKeys);
     return NestedSetBuilder.<String>stableOrder()
@@ -385,7 +385,7 @@
     Map<PathFragment, Artifact> manifest = getSymlinksAsMap(checker);
     // Add artifacts (committed to inclusion on construction of runfiles).
     for (Artifact artifact : getArtifacts().toList()) {
-      checker.put(manifest, artifact.getPackagePath(), artifact);
+      checker.put(manifest, artifact.getOutputDirRelativePath(), artifact);
     }
 
     manifest = filterListForObscuringSymlinks(eventHandler, location, manifest);
@@ -519,11 +519,11 @@
    */
   public Map<PathFragment, Artifact> asMapWithoutRootSymlinks() {
     Map<PathFragment, Artifact> result = entriesToMap(symlinks, null);
-    // If multiple artifacts have the same root-relative path, the last one in the list will win.
-    // That is because the runfiles tree cannot contain the same artifact for different
-    // configurations, because it only uses root-relative paths.
+    // If multiple artifacts have the same output-dir-relative path, the last one in the list will
+    // win. That is because the runfiles tree cannot contain the same artifact for different
+    // configurations, because it only uses output-dir-relative paths.
     for (Artifact artifact : artifacts.toList()) {
-      result.put(artifact.getPackagePath(), artifact);
+      result.put(artifact.getOutputDirRelativePath(), artifact);
     }
     return result;
   }
@@ -951,7 +951,7 @@
 
     /** Adds symlinks to given artifacts at their exec paths. */
     public Builder addSymlinksToArtifacts(NestedSet<Artifact> artifacts) {
-      // These are symlinks using the exec path, not the root-relative path, which currently
+      // These are symlinks using the exec path, not the output-dir-relative path, which currently
       // requires flattening.
       return addSymlinksToArtifacts(artifacts.toList());
     }
@@ -1074,7 +1074,7 @@
     }
 
     for (Artifact artifact : getArtifacts().toList()) {
-      fp.addPath(artifact.getPackagePath());
+      fp.addPath(artifact.getOutputDirRelativePath());
       fp.addPath(artifact.getExecPath());
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java
index e885b27..0309287 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkActionFactory.java
@@ -121,7 +121,7 @@
     if (Starlark.NONE.equals(sibling)) {
       fragment = ruleContext.getPackageDirectory().getRelative(PathFragment.create(filename));
     } else {
-      PathFragment original = ((Artifact) sibling).getPackagePath();
+      PathFragment original = ((Artifact) sibling).getOutputDirRelativePath();
       fragment = original.replaceName(filename);
     }
 
@@ -141,7 +141,7 @@
     if (Starlark.NONE.equals(sibling)) {
       fragment = ruleContext.getPackageDirectory().getRelative(PathFragment.create(filename));
     } else {
-      PathFragment original = ((Artifact) sibling).getPackagePath();
+      PathFragment original = ((Artifact) sibling).getOutputDirRelativePath();
       fragment = original.replaceName(filename);
     }
 
@@ -174,7 +174,7 @@
     if (Starlark.NONE.equals(sibling)) {
       rootRelativePath = ruleContext.getPackageDirectory().getRelative(filename);
     } else {
-      PathFragment original = ((Artifact) sibling).getPackagePath();
+      PathFragment original = ((Artifact) sibling).getOutputDirRelativePath();
       rootRelativePath = original.replaceName(filename);
     }
 
@@ -234,7 +234,7 @@
     String progressMessage =
         (progressMessageUnchecked != Starlark.NONE)
             ? (String) progressMessageUnchecked
-            : "Creating symlink " + outputArtifact.getPackagePathString();
+            : "Creating symlink " + outputArtifact.getOutputDirRelativePathString();
 
     SymlinkAction action;
     if (targetFile != Starlark.NONE) {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
index 21e16b2..c3bb114 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
@@ -337,7 +337,7 @@
                   + "\nexport TEST_RUNTIME_CLASSPATH_FILE=${JAVA_RUNFILES}"
                   + File.separator
                   + workspacePrefix
-                  + testRuntimeClasspathArtifact.getPackagePathString()));
+                  + testRuntimeClasspathArtifact.getOutputDirRelativePathString()));
     } else {
       arguments.add(
           new ComputedClasspathSubstitution(classpath, workspacePrefix, isRunfilesEnabled));
@@ -365,7 +365,7 @@
                 "export JACOCO_METADATA_JAR=${JAVA_RUNFILES}/"
                     + workspacePrefix
                     + "/"
-                    + runtimeClassPathArtifact.getPackagePathString()));
+                    + runtimeClassPathArtifact.getOutputDirRelativePathString()));
       } else {
         // Remove the placeholder in the stub otherwise bazel coverage fails.
         arguments.add(Substitution.of(JavaSemantics.JACOCO_METADATA_PLACEHOLDER, ""));
@@ -436,7 +436,7 @@
             .addJoinedValues(
                 "classpath",
                 ";",
-                Iterables.transform(classpath.toList(), Artifact.PACKAGE_PATH_STRING))
+                Iterables.transform(classpath.toList(), Artifact.OUTPUT_DIR_RELATIVE_PATH_STRING))
             // TODO(laszlocsomor): Change the Launcher to accept multiple jvm_flags entries. As of
             // 2019-02-13 the Launcher accepts just one jvm_flags entry, which contains all the
             // flags, joined by TAB characters. The Launcher splits up the string to get the
@@ -715,7 +715,7 @@
             && !ruleContext.attributes().isAttributeValueExplicitlySpecified("args")) {
           ImmutableList.Builder<String> builder = ImmutableList.builder();
           for (Artifact artifact : sources) {
-            PathFragment path = artifact.getPackagePath();
+            PathFragment path = artifact.getOutputDirRelativePath();
             String className = JavaUtil.getJavaFullClassname(FileSystemUtils.removeExtension(path));
             if (className != null) {
               builder.add(className);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
index ddbb01f..42f5726 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
@@ -879,7 +879,7 @@
     NestedSetBuilder<Pair<String, String>> virtualToOriginalHeaders =
         NestedSetBuilder.stableOrder();
     for (Artifact originalHeader : publicHeaders) {
-      if (!originalHeader.getPackagePath().startsWith(stripPrefix)) {
+      if (!originalHeader.getOutputDirRelativePath().startsWith(stripPrefix)) {
         ruleErrorConsumer.ruleError(
             String.format(
                 "header '%s' is not under the specified strip prefix '%s'",
@@ -887,7 +887,7 @@
         continue;
       }
 
-      PathFragment includePath = originalHeader.getPackagePath().relativeTo(stripPrefix);
+      PathFragment includePath = originalHeader.getOutputDirRelativePath().relativeTo(stripPrefix);
       if (prefix != null) {
         includePath = prefix.getRelative(includePath);
       }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java
index 5117279..c01d6b9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java
@@ -97,7 +97,7 @@
       List<String> userCompileFlags)
       throws RuleErrorException {
     this.bitcodeFile = bitcodeFile;
-    PathFragment obj = ltoOutputRootPrefix.getRelative(bitcodeFile.getPackagePath());
+    PathFragment obj = ltoOutputRootPrefix.getRelative(bitcodeFile.getOutputDirRelativePath());
 
     objectFile =
         linkArtifactFactory.create(actionConstructionContext, repositoryName, configuration, obj);
@@ -151,7 +151,7 @@
       throws RuleErrorException {
     this.bitcodeFile = bitcodeFile;
 
-    PathFragment obj = ltoOutputRootPrefix.getRelative(bitcodeFile.getPackagePath());
+    PathFragment obj = ltoOutputRootPrefix.getRelative(bitcodeFile.getOutputDirRelativePath());
     objectFile =
         linkArtifactFactory.create(actionConstructionContext, repositoryName, configuration, obj);
     imports = null;
@@ -265,7 +265,7 @@
               actionConstructionContext,
               repositoryName,
               configuration,
-              FileSystemUtils.replaceExtension(objectFile.getPackagePath(), ".dwo"));
+              FileSystemUtils.replaceExtension(objectFile.getOutputDirRelativePath(), ".dwo"));
       builder.addOutput(dwoFile);
       buildVariablesBuilder.addStringVariable(
           CompileBuildVariables.PER_OBJECT_DEBUG_INFO_FILE.getVariableName(),
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
index e41df20..e1c1067 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
@@ -110,7 +110,7 @@
   public static PathFragment getJavaResourcePath(
       JavaSemantics semantics, RuleContext ruleContext, Artifact resource)
       throws InterruptedException {
-    PathFragment resourcePath = resource.getPackagePath();
+    PathFragment resourcePath = resource.getOutputDirRelativePath();
     StarlarkSemantics starlarkSemantics =
         ruleContext.getAnalysisEnvironment().getStarlarkSemantics();
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
index 72148c2..0bbaddf 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
@@ -319,7 +319,7 @@
     for (Artifact realProtoSource : protoSources) {
       if (siblingRepositoryLayout && realProtoSource.isSourceArtifact()
           ? !realProtoSource.getExecPath().startsWith(stripImportPrefix)
-          : !realProtoSource.getPackagePath().startsWith(stripImportPrefix)) {
+          : !realProtoSource.getOutputDirRelativePath().startsWith(stripImportPrefix)) {
         ruleContext.ruleError(
             String.format(
                 ".proto file '%s' is not under the specified strip prefix '%s'",
@@ -362,7 +362,8 @@
           importPrefix.getRelative(realProtoSource.getExecPath().relativeTo(stripImportPrefix));
     } else {
       importPath =
-          importPrefix.getRelative(realProtoSource.getPackagePath().relativeTo(stripImportPrefix));
+          importPrefix.getRelative(
+              realProtoSource.getOutputDirRelativePath().relativeTo(stripImportPrefix));
     }
 
     Artifact virtualProtoSource =
@@ -577,7 +578,7 @@
     ArtifactRoot genfiles =
         ruleContext.getConfiguration().getGenfilesDirectory(ruleContext.getRule().getRepository());
     for (Artifact src : protoSources) {
-      PathFragment srcPath = src.getPackagePath();
+      PathFragment srcPath = src.getOutputDirRelativePath();
       if (pythonNames) {
         srcPath = srcPath.replaceName(srcPath.getBaseName().replace('-', '_'));
       }
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
index af8785c..8a0e833 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
@@ -301,7 +301,7 @@
   }
 
   protected String getAndroidJarPath() throws Exception {
-    return getAndroidSdk().getAndroidJar().getPackagePathString();
+    return getAndroidSdk().getAndroidJar().getOutputDirRelativePathString();
   }
 
   protected String getAndroidJarFilename() throws Exception {
@@ -313,7 +313,7 @@
   }
 
   protected String getMainDexClassesPath() throws Exception {
-    return getAndroidSdk().getMainDexClasses().getPackagePathString();
+    return getAndroidSdk().getMainDexClasses().getOutputDirRelativePathString();
   }
 
   protected String getMainDexClassesFilename() throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java
index e61b179..d416eb7 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/BazelJ2ObjcLibraryTest.java
@@ -87,12 +87,12 @@
     ConfiguredTarget j2objcLibraryTarget = getConfiguredTarget(
         "//java/com/google/dummy/test:transpile");
     ObjcProvider provider = j2objcLibraryTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
             "java/com/google/dummy/test/libtest_j2objc.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "java/com/google/dummy/test/_j2objc/test/java/com/google/dummy/test/test.h");
@@ -146,12 +146,12 @@
     ConfiguredTarget target = getConfiguredTarget("//java/com/google/test:transpile");
     ObjcProvider provider = target.get(ObjcProvider.STARLARK_CONSTRUCTOR);
     String genfilesFragment = getConfiguration(target).getGenfilesFragment().toString();
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
             "java/com/google/test/libtest_j2objc.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "java/com/google/test/_j2objc/test/"
@@ -195,7 +195,7 @@
     ConfiguredTarget j2objcLibraryTarget = getConfiguredTarget(
         "//java/com/google/dummy/test/proto:transpile");
     ObjcProvider provider = j2objcLibraryTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
@@ -203,7 +203,7 @@
                 + "third_party/java/j2objc/libproto_runtime.a",
             "java/com/google/dummy/test/proto/libtest_j2objc.a",
             "java/com/google/dummy/test/proto/libtest_proto_j2objc.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/runtime.h",
@@ -432,12 +432,12 @@
         "//java/com/google/dummy/test:transpile");
     ObjcProvider provider = j2objcLibraryTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
     // jre_io_lib and jre_emul_lib should be excluded.
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
             "java/com/google/dummy/test/libtest_j2objc.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "java/com/google/dummy/test/_j2objc/test/java/com/google/dummy/test/test.h");
@@ -512,7 +512,7 @@
         "//java/com/google/transpile:lib1");
     J2ObjcMappingFileProvider mappingFileProvider =
         target.getProvider(J2ObjcMappingFileProvider.class);
-    assertThat(Artifact.toPackagePaths(mappingFileProvider.getHeaderMappingFiles()))
+    assertThat(Artifact.toOutputDirRelativePaths(mappingFileProvider.getHeaderMappingFiles()))
         .containsExactly(
             "java/com/google/transpile/lib1.mapping.j2objc",
             "java/com/google/transpile/lib2.mapping.j2objc");
@@ -522,7 +522,7 @@
     SpawnAction headerMappingAction = (SpawnAction) getGeneratingAction(mappingFile);
     String execPath =
         getConfiguration(target).getBinDirectory(RepositoryName.MAIN).getExecPath() + "/";
-    assertThat(Artifact.toPackagePaths(headerMappingAction.getInputs()))
+    assertThat(Artifact.toOutputDirRelativePaths(headerMappingAction.getInputs()))
         .containsAtLeast(
             "java/com/google/transpile/libOne.java", "java/com/google/transpile/jar.srcjar");
     assertThat(headerMappingAction.getArguments())
@@ -541,7 +541,7 @@
       Artifact archiveFile, String objFileName, Iterable<String> compilationInputExecPaths)
       throws Exception {
     CommandAction compileAction = getObjcCompileAction(archiveFile, objFileName);
-    assertThat(Artifact.toPackagePaths(compileAction.getPossibleInputsForTesting()))
+    assertThat(Artifact.toOutputDirRelativePaths(compileAction.getPossibleInputsForTesting()))
         .containsAtLeastElementsIn(compilationInputExecPaths);
   }
 
@@ -637,13 +637,13 @@
     ConfiguredTarget objcTarget = getConfiguredTarget("//app:lib");
 
     ObjcProvider provider = objcTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
             "java/com/google/dummy/test/libtest_j2objc.a",
             "app/liblib.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "java/com/google/dummy/test/_j2objc/test/java/com/google/dummy/test/test.h");
@@ -683,14 +683,14 @@
     ConfiguredTarget objcTarget = getConfiguredTarget("//app:lib");
 
     ObjcProvider provider = objcTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
             "app/libdummyOne_j2objc.a",
             "app/libdummyTwo_j2objc.a",
             "app/liblib.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "app/_j2objc/dummyOne/app/dummyOne.h",
@@ -895,7 +895,7 @@
   public void testObjcCompileAction() throws Exception {
     Artifact archive = j2objcArchive("//java/com/google/dummy/test:transpile", "test");
     CommandAction compileAction = getObjcCompileAction(archive, "test.o");
-    assertThat(Artifact.toPackagePaths(compileAction.getPossibleInputsForTesting()))
+    assertThat(Artifact.toOutputDirRelativePaths(compileAction.getPossibleInputsForTesting()))
         .containsAtLeast(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "java/com/google/dummy/test/_j2objc/test/java/com/google/dummy/test/test.h",
@@ -1006,7 +1006,7 @@
     ObjcProvider provider = objcTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
 
     // The only way that //examples:lib can see inner's archive is through the Starlark rule.
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .contains("examples/libinner_j2objc.a");
   }
 
@@ -1106,14 +1106,14 @@
     ConfiguredTarget j2objcLibraryTarget =
         getConfiguredTarget("//java/com/google/dummy/test/proto:transpile");
     ObjcProvider provider = j2objcLibraryTarget.get(ObjcProvider.STARLARK_CONSTRUCTOR);
-    assertThat(Artifact.toPackagePaths(provider.get(ObjcProvider.LIBRARY)))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.get(ObjcProvider.LIBRARY)))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX
                 + "third_party/java/j2objc/libjre_core_lib.a",
             "tools/j2objc/libalt_proto_runtime.a",
             "java/com/google/dummy/test/proto/libtest_j2objc.a",
             "java/com/google/dummy/test/proto/libtest_proto_j2objc.a");
-    assertThat(Artifact.toPackagePaths(provider.header()))
+    assertThat(Artifact.toOutputDirRelativePaths(provider.header()))
         .containsExactly(
             TestConstants.TOOLS_REPOSITORY_PATH_PREFIX + "third_party/java/j2objc/jre_core.h",
             "tools/j2objc/alt_proto_runtime.h",