Replace AnalysisEnvironment.getDerivedArtifact() calls with RuleContext.getShareableArtifact() calls where the former method is used to create the outputs of shared actions.

--
MOS_MIGRATED_REVID=101116694
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index bddb2c2..0f07e39 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -467,6 +467,18 @@
   }
 
   /**
+   * Returns an artifact that can be an output of shared actions. Only use when there is no other
+   * option.
+   *
+   * <p>This artifact can be created anywhere in the output tree, which, in addition to making
+   * sharing possible, opens up the possibility of action conflicts and makes it impossible to
+   * infer the label of the rule creating the artifact from the path of the artifact.
+   */
+  public Artifact getShareableArtifact(PathFragment rootRelativePath, Root root) {
+    return getAnalysisEnvironment().getDerivedArtifact(rootRelativePath, root);
+  }
+
+  /**
    * Creates an artifact in a directory that is unique to the package that contains the rule,
    * thus guaranteeing that it never clashes with artifacts created by rules in other packages.
    */
diff --git a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
index 8c22344..e808eb5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
@@ -153,7 +153,7 @@
             linkopts, linkstamps.keySet(), buildInfoArtifacts,
             ruleContext.getFeatures())
         : nativeDepsPath;
-    Artifact sharedLibrary = ruleContext.getAnalysisEnvironment().getDerivedArtifact(
+    Artifact sharedLibrary = ruleContext.getShareableArtifact(
         linkerOutputPath, configuration.getBinDirectory());
     CppLinkAction.Builder builder = new CppLinkAction.Builder(
         ruleContext, sharedLibrary, configuration, toolchain);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
index c663b26..1dde893 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
@@ -83,7 +83,7 @@
   private static Artifact get2to3OutputArtifact(RuleContext ruleContext, Artifact input) {
     Root root = ruleContext.getConfiguration().getGenfilesDirectory();
     PathFragment path = new PathFragment("python3").getRelative(input.getRootRelativePath());
-    return ruleContext.getAnalysisEnvironment().getDerivedArtifact(path, root);
+    return ruleContext.getShareableArtifact(path, root);
   }
 
   /**