Make Artifact an abstract class, and break out a DerivedArtifact subclass. This will facilitate future refactorings in which a DerivedArtifact will have an ActionLookupData "owner", while a SourceArtifact will have a Label owner (or an ArtifactOwner, depending on how lazy I am).
I verified using the test in ArtifactTest, modified to use dummy classes, that derived artifacts don't use any more memory with this refactoring than they did before.
PiperOrigin-RevId: 249535371
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java
index bdc969c..99a2290 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java
@@ -21,6 +21,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ArtifactRoot;
+import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.LocationExpander.LocationFunction;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.RepositoryName;
@@ -190,12 +191,12 @@
private static Artifact makeArtifact(String path) {
FileSystem fs = new InMemoryFileSystem();
if (path.startsWith("/exec/out")) {
- return new Artifact(
- fs.getPath(path),
- ArtifactRoot.asDerivedRoot(fs.getPath("/exec"), fs.getPath("/exec/out")));
+ return ActionsTestUtil.createArtifact(
+ ArtifactRoot.asDerivedRoot(fs.getPath("/exec"), fs.getPath("/exec/out")),
+ fs.getPath(path));
} else {
- return new Artifact(
- fs.getPath(path), ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/exec"))));
+ return ActionsTestUtil.createArtifact(
+ ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/exec"))), fs.getPath(path));
}
}
}