Add repository parameter to source artifact resolver
Needed for #1262. Doesn't do anything, yet, other than make the CL smaller.
--
MOS_MIGRATED_REVID=132671036
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 973e95d..bba4928 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
@@ -348,7 +348,8 @@
}
@Override
- public Artifact resolveSourceArtifact(PathFragment execPath) {
+ public Artifact resolveSourceArtifact(PathFragment execPath,
+ @SuppressWarnings("unused") RepositoryName repositoryName) {
return resolveSourceArtifactWithAncestor(execPath, null, null);
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactResolver.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactResolver.java
index 58b36c9..7bb3b01 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactResolver.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.actions;
+import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Map;
import javax.annotation.Nullable;
@@ -51,10 +52,11 @@
* post-compile .d or manifest scanning methods.
*
* @param execPath the exec path of the artifact to resolve
+ * @param repositoryName the name of repository this artifact belongs to
* @return an existing or new source Artifact for the given execPath. Returns null if
* the root can not be determined and the artifact did not exist before.
*/
- Artifact resolveSourceArtifact(PathFragment execPath);
+ Artifact resolveSourceArtifact(PathFragment execPath, RepositoryName repositoryName);
/**
* Resolves source Artifacts given execRoot-relative paths.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java
index 96c7b81..512281a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java
@@ -20,6 +20,7 @@
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ArtifactResolver;
+import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
@@ -119,7 +120,7 @@
}
Artifact artifact = allowedDerivedInputsMap.get(execPathFragment);
if (artifact == null) {
- artifact = artifactResolver.resolveSourceArtifact(execPathFragment);
+ artifact = artifactResolver.resolveSourceArtifact(execPathFragment, RepositoryName.MAIN);
}
if (artifact != null) {
inputs.add(artifact);
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java
index cfdeef4..c0bec56 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java
@@ -28,6 +28,7 @@
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -50,6 +51,8 @@
@RunWith(JUnit4.class)
public class ArtifactFactoryTest {
+ private static final RepositoryName MAIN = RepositoryName.MAIN;
+
private Scratch scratch = new Scratch();
private Path execRoot;
@@ -120,31 +123,31 @@
@Test
public void testResolveArtifact_noDerived_simpleSource() throws Exception {
assertSame(artifactFactory.getSourceArtifact(fooRelative, clientRoot),
- artifactFactory.resolveSourceArtifact(fooRelative));
+ artifactFactory.resolveSourceArtifact(fooRelative, MAIN));
assertSame(artifactFactory.getSourceArtifact(barRelative, clientRoRoot),
- artifactFactory.resolveSourceArtifact(barRelative));
+ artifactFactory.resolveSourceArtifact(barRelative, MAIN));
}
@Test
public void testResolveArtifact_inExternalRepo() throws Exception {
assertSame(
artifactFactory.getSourceArtifact(alienRelative, alienRoot),
- artifactFactory.resolveSourceArtifact(alienRelative));
+ artifactFactory.resolveSourceArtifact(alienRelative, MAIN));
}
@Test
public void testResolveArtifact_noDerived_derivedRoot() throws Exception {
assertNull(artifactFactory.resolveSourceArtifact(
- outRoot.getPath().getRelative(fooRelative).relativeTo(execRoot)));
+ outRoot.getPath().getRelative(fooRelative).relativeTo(execRoot), MAIN));
assertNull(artifactFactory.resolveSourceArtifact(
- outRoot.getPath().getRelative(barRelative).relativeTo(execRoot)));
+ outRoot.getPath().getRelative(barRelative).relativeTo(execRoot), MAIN));
}
@Test
public void testResolveArtifact_noDerived_simpleSource_other() throws Exception {
- Artifact actual = artifactFactory.resolveSourceArtifact(fooRelative);
+ Artifact actual = artifactFactory.resolveSourceArtifact(fooRelative, MAIN);
assertSame(artifactFactory.getSourceArtifact(fooRelative, clientRoot), actual);
- actual = artifactFactory.resolveSourceArtifact(barRelative);
+ actual = artifactFactory.resolveSourceArtifact(barRelative, MAIN);
assertSame(artifactFactory.getSourceArtifact(barRelative, clientRoRoot), actual);
}
@@ -158,9 +161,9 @@
PathFragment outsideWorkspace = new PathFragment("../foo");
PathFragment insideWorkspace =
new PathFragment("../" + clientRoot.getPath().getBaseName() + "/foo");
- assertNull(artifactFactory.resolveSourceArtifact(outsideWorkspace));
+ assertNull(artifactFactory.resolveSourceArtifact(outsideWorkspace, MAIN));
assertNull("Up-level-containing paths that descend into the right workspace aren't allowed",
- artifactFactory.resolveSourceArtifact(insideWorkspace));
+ artifactFactory.resolveSourceArtifact(insideWorkspace, MAIN));
MockPackageRootResolver packageRootResolver = new MockPackageRootResolver();
packageRootResolver.setPackageRoots(packageRoots);
Map<PathFragment, Artifact> result = new HashMap<>();