|
35 | 35 | import com.google.devtools.build.lib.collect.nestedset.NestedSet;
|
36 | 36 | import com.google.devtools.build.lib.concurrent.ThreadSafety;
|
37 | 37 | import com.google.devtools.build.lib.skyframe.SkyFunctions;
|
38 |
| -import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext; |
39 |
| -import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; |
40 |
| -import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; |
41 |
| -import com.google.devtools.build.lib.skyframe.serialization.SerializationException; |
42 | 38 | import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization;
|
43 | 39 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
|
44 | 40 | import com.google.devtools.build.lib.starlarkbuildapi.FileApi;
|
|
51 | 47 | import com.google.devtools.build.skyframe.ExecutionPhaseSkyKey;
|
52 | 48 | import com.google.devtools.build.skyframe.SkyFunctionName;
|
53 | 49 | import com.google.devtools.build.skyframe.SkyKey;
|
54 |
| -import com.google.protobuf.CodedInputStream; |
55 |
| -import com.google.protobuf.CodedOutputStream; |
56 |
| -import java.io.IOException; |
57 | 50 | import java.util.ArrayList;
|
58 | 51 | import java.util.Collection;
|
59 | 52 | import java.util.Comparator;
|
@@ -363,7 +356,8 @@ public static DerivedArtifact create(
|
363 | 356 | return new DerivedArtifact(root, execPath, owner, contentBasedPath);
|
364 | 357 | }
|
365 | 358 |
|
366 |
| - private DerivedArtifact(ArtifactRoot root, PathFragment execPath, Object owner) { |
| 359 | + @VisibleForSerialization |
| 360 | + DerivedArtifact(ArtifactRoot root, PathFragment execPath, Object owner) { |
367 | 361 | this(root, execPath, owner, /*contentBasedPath=*/ false);
|
368 | 362 | }
|
369 | 363 |
|
@@ -504,64 +498,6 @@ public String toString() {
|
504 | 498 | }
|
505 | 499 | };
|
506 | 500 |
|
507 |
| - @SuppressWarnings("unused") // Codec used by reflection. |
508 |
| - private static final class DerivedArtifactCodec implements ObjectCodec<DerivedArtifact> { |
509 |
| - |
510 |
| - @Override |
511 |
| - public Class<DerivedArtifact> getEncodedClass() { |
512 |
| - return DerivedArtifact.class; |
513 |
| - } |
514 |
| - |
515 |
| - @Override |
516 |
| - public void serialize( |
517 |
| - SerializationContext context, DerivedArtifact obj, CodedOutputStream codedOut) |
518 |
| - throws SerializationException, IOException { |
519 |
| - context.serialize(obj.getRoot(), codedOut); |
520 |
| - context.serialize(obj.getRootRelativePath(), codedOut); |
521 |
| - context.serialize(getGeneratingActionKeyForSerialization(obj, context), codedOut); |
522 |
| - } |
523 |
| - |
524 |
| - @Override |
525 |
| - public DerivedArtifact deserialize(DeserializationContext context, CodedInputStream codedIn) |
526 |
| - throws SerializationException, IOException { |
527 |
| - ArtifactRoot root = context.deserialize(codedIn); |
528 |
| - PathFragment rootRelativePath = context.deserialize(codedIn); |
529 |
| - Object generatingActionKey = context.deserialize(codedIn); |
530 |
| - DerivedArtifact artifact = |
531 |
| - new DerivedArtifact( |
532 |
| - root, |
533 |
| - getExecPathForDeserialization(root, rootRelativePath, generatingActionKey), |
534 |
| - generatingActionKey); |
535 |
| - return context.getDependency(ArtifactSerializationContext.class).intern(artifact); |
536 |
| - } |
537 |
| - } |
538 |
| - |
539 |
| - private static Object getGeneratingActionKeyForSerialization( |
540 |
| - DerivedArtifact artifact, SerializationContext context) { |
541 |
| - return context |
542 |
| - .getDependency(ArtifactSerializationContext.class) |
543 |
| - .includeGeneratingActionKey(artifact) |
544 |
| - ? artifact.getGeneratingActionKey() |
545 |
| - : OMITTED_FOR_SERIALIZATION; |
546 |
| - } |
547 |
| - |
548 |
| - private static PathFragment getExecPathForDeserialization( |
549 |
| - ArtifactRoot root, PathFragment rootRelativePath, Object generatingActionKey) { |
550 |
| - Preconditions.checkArgument( |
551 |
| - !root.isSourceRoot(), |
552 |
| - "Root not derived: %s (rootRelativePath=%s, generatingActionKey=%s)", |
553 |
| - root, |
554 |
| - rootRelativePath, |
555 |
| - generatingActionKey); |
556 |
| - Preconditions.checkArgument( |
557 |
| - root.getRoot().isAbsolute() == rootRelativePath.isAbsolute(), |
558 |
| - "Illegal root relative path: %s (root=%s, generatingActionKey=%s)", |
559 |
| - rootRelativePath, |
560 |
| - root, |
561 |
| - generatingActionKey); |
562 |
| - return root.getExecPath().getRelative(rootRelativePath); |
563 |
| - } |
564 |
| - |
565 | 501 | public final Path getPath() {
|
566 | 502 | return root.getRoot().getRelative(getRootRelativePath());
|
567 | 503 | }
|
@@ -986,36 +922,6 @@ boolean differentOwnerOrRoot(ArtifactOwner owner, ArtifactRoot root) {
|
986 | 922 | }
|
987 | 923 | }
|
988 | 924 |
|
989 |
| - /** {@link ObjectCodec} for {@link SourceArtifact} */ |
990 |
| - @SuppressWarnings("unused") // Used by reflection. |
991 |
| - private static final class SourceArtifactCodec implements ObjectCodec<SourceArtifact> { |
992 |
| - |
993 |
| - @Override |
994 |
| - public Class<SourceArtifact> getEncodedClass() { |
995 |
| - return SourceArtifact.class; |
996 |
| - } |
997 |
| - |
998 |
| - @Override |
999 |
| - public void serialize( |
1000 |
| - SerializationContext context, SourceArtifact obj, CodedOutputStream codedOut) |
1001 |
| - throws SerializationException, IOException { |
1002 |
| - context.serialize(obj.getExecPath(), codedOut); |
1003 |
| - context.serialize(obj.getRoot(), codedOut); |
1004 |
| - context.serialize(obj.getArtifactOwner(), codedOut); |
1005 |
| - } |
1006 |
| - |
1007 |
| - @Override |
1008 |
| - public SourceArtifact deserialize(DeserializationContext context, CodedInputStream codedIn) |
1009 |
| - throws SerializationException, IOException { |
1010 |
| - PathFragment execPath = context.deserialize(codedIn); |
1011 |
| - ArtifactRoot artifactRoot = context.deserialize(codedIn); |
1012 |
| - ArtifactOwner owner = context.deserialize(codedIn); |
1013 |
| - return context |
1014 |
| - .getDependency(ArtifactSerializationContext.class) |
1015 |
| - .getSourceArtifact(execPath, artifactRoot.getRoot(), owner); |
1016 |
| - } |
1017 |
| - } |
1018 |
| - |
1019 | 925 | /**
|
1020 | 926 | * Special artifact types.
|
1021 | 927 | *
|
@@ -1055,7 +961,8 @@ public static SpecialArtifact create(
|
1055 | 961 | return new SpecialArtifact(root, execPath, owner, type);
|
1056 | 962 | }
|
1057 | 963 |
|
1058 |
| - private SpecialArtifact( |
| 964 | + @VisibleForSerialization |
| 965 | + SpecialArtifact( |
1059 | 966 | ArtifactRoot root, PathFragment execPath, Object owner, SpecialArtifactType type) {
|
1060 | 967 | super(root, execPath, owner);
|
1061 | 968 | this.type = type;
|
@@ -1096,42 +1003,10 @@ public PathFragment getParentRelativePath() {
|
1096 | 1003 | public boolean valueIsShareable() {
|
1097 | 1004 | return !isConstantMetadata();
|
1098 | 1005 | }
|
1099 |
| - } |
1100 |
| - |
1101 |
| - // Keep in sync with DerivedArtifactCodec. |
1102 |
| - @SuppressWarnings("unused") // Used by reflection. |
1103 |
| - private static final class SpecialArtifactCodec implements ObjectCodec<SpecialArtifact> { |
1104 | 1006 |
|
1105 |
| - @Override |
1106 |
| - public Class<SpecialArtifact> getEncodedClass() { |
1107 |
| - return SpecialArtifact.class; |
1108 |
| - } |
1109 |
| - |
1110 |
| - @Override |
1111 |
| - public void serialize( |
1112 |
| - SerializationContext context, SpecialArtifact obj, CodedOutputStream codedOut) |
1113 |
| - throws SerializationException, IOException { |
1114 |
| - context.serialize(obj.getRoot(), codedOut); |
1115 |
| - context.serialize(obj.getRootRelativePath(), codedOut); |
1116 |
| - context.serialize(getGeneratingActionKeyForSerialization(obj, context), codedOut); |
1117 |
| - context.serialize(obj.type, codedOut); |
1118 |
| - } |
1119 |
| - |
1120 |
| - @Override |
1121 |
| - public SpecialArtifact deserialize(DeserializationContext context, CodedInputStream codedIn) |
1122 |
| - throws SerializationException, IOException { |
1123 |
| - ArtifactRoot root = context.deserialize(codedIn); |
1124 |
| - PathFragment rootRelativePath = context.deserialize(codedIn); |
1125 |
| - Object generatingActionKey = context.deserialize(codedIn); |
1126 |
| - SpecialArtifactType type = context.deserialize(codedIn); |
1127 |
| - SpecialArtifact artifact = |
1128 |
| - new SpecialArtifact( |
1129 |
| - root, |
1130 |
| - getExecPathForDeserialization(root, rootRelativePath, generatingActionKey), |
1131 |
| - generatingActionKey, |
1132 |
| - type); |
1133 |
| - return (SpecialArtifact) |
1134 |
| - context.getDependency(ArtifactSerializationContext.class).intern(artifact); |
| 1007 | + @VisibleForSerialization |
| 1008 | + SpecialArtifactType getSpecialArtifactType() { |
| 1009 | + return type; |
1135 | 1010 | }
|
1136 | 1011 | }
|
1137 | 1012 |
|
@@ -1202,7 +1077,8 @@ public static ArchivedTreeArtifact createWithCustomDerivedTreeRoot(
|
1202 | 1077 | treeArtifact, derivedTreeRoot, rootRelativePath, treeArtifact.getGeneratingActionKey());
|
1203 | 1078 | }
|
1204 | 1079 |
|
1205 |
| - private static ArchivedTreeArtifact createInternal( |
| 1080 | + @VisibleForSerialization |
| 1081 | + static ArchivedTreeArtifact createInternal( |
1206 | 1082 | SpecialArtifact treeArtifact,
|
1207 | 1083 | PathFragment derivedTreeRoot,
|
1208 | 1084 | PathFragment rootRelativePath,
|
@@ -1253,43 +1129,6 @@ private static Path getExecRoot(ArtifactRoot artifactRoot) {
|
1253 | 1129 | }
|
1254 | 1130 | }
|
1255 | 1131 |
|
1256 |
| - @SuppressWarnings("unused") // Codec used by reflection. |
1257 |
| - private static final class ArchivedTreeArtifactCodec |
1258 |
| - implements ObjectCodec<ArchivedTreeArtifact> { |
1259 |
| - |
1260 |
| - @Override |
1261 |
| - public Class<ArchivedTreeArtifact> getEncodedClass() { |
1262 |
| - return ArchivedTreeArtifact.class; |
1263 |
| - } |
1264 |
| - |
1265 |
| - @Override |
1266 |
| - public void serialize( |
1267 |
| - SerializationContext context, ArchivedTreeArtifact obj, CodedOutputStream codedOut) |
1268 |
| - throws SerializationException, IOException { |
1269 |
| - PathFragment derivedTreeRoot = obj.getRoot().getExecPath().subFragment(1, 2); |
1270 |
| - |
1271 |
| - context.serialize(obj.getParent(), codedOut); |
1272 |
| - context.serialize(derivedTreeRoot, codedOut); |
1273 |
| - context.serialize(obj.getRootRelativePath(), codedOut); |
1274 |
| - } |
1275 |
| - |
1276 |
| - @Override |
1277 |
| - public ArchivedTreeArtifact deserialize( |
1278 |
| - DeserializationContext context, CodedInputStream codedIn) |
1279 |
| - throws SerializationException, IOException { |
1280 |
| - SpecialArtifact treeArtifact = context.deserialize(codedIn); |
1281 |
| - PathFragment derivedTreeRoot = context.deserialize(codedIn); |
1282 |
| - PathFragment rootRelativePath = context.deserialize(codedIn); |
1283 |
| - Object generatingActionKey = |
1284 |
| - treeArtifact.hasGeneratingActionKey() |
1285 |
| - ? treeArtifact.getGeneratingActionKey() |
1286 |
| - : OMITTED_FOR_SERIALIZATION; |
1287 |
| - |
1288 |
| - return ArchivedTreeArtifact.createInternal( |
1289 |
| - treeArtifact, derivedTreeRoot, rootRelativePath, generatingActionKey); |
1290 |
| - } |
1291 |
| - } |
1292 |
| - |
1293 | 1132 | /**
|
1294 | 1133 | * A special kind of artifact that represents a concrete file created at execution time under its
|
1295 | 1134 | * associated parent TreeArtifact.
|
@@ -1378,8 +1217,8 @@ public static TreeFileArtifact createTemplateExpansionOutput(
|
1378 | 1217 | return createTemplateExpansionOutput(parent, PathFragment.create(parentRelativePath), owner);
|
1379 | 1218 | }
|
1380 | 1219 |
|
1381 |
| - private TreeFileArtifact( |
1382 |
| - SpecialArtifact parent, PathFragment parentRelativePath, Object owner) { |
| 1220 | + @VisibleForSerialization |
| 1221 | + TreeFileArtifact(SpecialArtifact parent, PathFragment parentRelativePath, Object owner) { |
1383 | 1222 | super(parent.getRoot(), parent.getExecPath().getRelative(parentRelativePath), owner);
|
1384 | 1223 | Preconditions.checkArgument(
|
1385 | 1224 | parent.isTreeArtifact(),
|
@@ -1419,33 +1258,6 @@ private static boolean isActionTemplateExpansionKey(ActionLookupKey key) {
|
1419 | 1258 | }
|
1420 | 1259 | }
|
1421 | 1260 |
|
1422 |
| - @SuppressWarnings("unused") // Used by reflection. |
1423 |
| - private static final class TreeFileArtifactCodec implements ObjectCodec<TreeFileArtifact> { |
1424 |
| - |
1425 |
| - @Override |
1426 |
| - public Class<TreeFileArtifact> getEncodedClass() { |
1427 |
| - return TreeFileArtifact.class; |
1428 |
| - } |
1429 |
| - |
1430 |
| - @Override |
1431 |
| - public void serialize( |
1432 |
| - SerializationContext context, TreeFileArtifact obj, CodedOutputStream codedOut) |
1433 |
| - throws SerializationException, IOException { |
1434 |
| - context.serialize(obj.parent, codedOut); |
1435 |
| - context.serialize(obj.parentRelativePath, codedOut); |
1436 |
| - context.serialize(getGeneratingActionKeyForSerialization(obj, context), codedOut); |
1437 |
| - } |
1438 |
| - |
1439 |
| - @Override |
1440 |
| - public TreeFileArtifact deserialize(DeserializationContext context, CodedInputStream codedIn) |
1441 |
| - throws SerializationException, IOException { |
1442 |
| - SpecialArtifact parent = context.deserialize(codedIn); |
1443 |
| - PathFragment parentRelativePath = context.deserialize(codedIn); |
1444 |
| - Object generatingActionKey = context.deserialize(codedIn); |
1445 |
| - return new TreeFileArtifact(parent, parentRelativePath, generatingActionKey); |
1446 |
| - } |
1447 |
| - } |
1448 |
| - |
1449 | 1261 | // ---------------------------------------------------------------------------
|
1450 | 1262 | // Static methods to assist in working with Artifacts
|
1451 | 1263 |
|
|
0 commit comments