3232import com .google .idea .blaze .qsync .project .ProjectProto .ProjectArtifact ;
3333import com .intellij .openapi .diagnostic .Logger ;
3434import com .intellij .openapi .project .Project ;
35+ import com .intellij .openapi .util .Pair ;
3536import java .io .IOException ;
3637import java .nio .file .Path ;
3738import java .nio .file .Paths ;
4344
4445public final class RuntimeArtifactCacheImpl implements RuntimeArtifactCache {
4546 private static final Logger logger = Logger .getInstance (RuntimeArtifactCacheImpl .class );
46- private final Map <Label , Map <Path , ProjectProto . ProjectArtifact >> artifactCacheMap = new HashMap <>();
47+ private final Map <Pair < Label , RuntimeArtifactKind >, Map <Path , ProjectArtifact >> artifactCacheMap = new HashMap <>();
4748 private final Path runfilesDirectory ;
4849 private static final String SEPARATOR_DIR_NAME = "_" ;
4950 private final BuildArtifactCache buildArtifactCache ;
@@ -67,20 +68,21 @@ private RuntimeArtifactCacheImpl(Project project) throws IOException {
6768
6869 @ Override
6970 public ImmutableList <Path > fetchArtifacts (
70- Label target , List <? extends OutputArtifact > artifacts , BlazeContext context ) {
71+ Label target , List <? extends OutputArtifact > artifacts , BlazeContext context , RuntimeArtifactKind artifactKind ) {
72+ var targetKind = Pair .create (target , artifactKind );
7173 final var artifactsCachedFuture =
7274 buildArtifactCache .addAll (artifacts .stream ().collect (toImmutableList ()), context );
73- artifactCacheMap .put (target , buildArtifactLayout (target , artifacts ));
75+ artifactCacheMap .put (targetKind , buildArtifactLayout (target , artifacts ));
7476 final var artifactDirectoryContents = buildArtifactDirectoryContents (artifactCacheMap );
7577 waitForArtifacts (artifactsCachedFuture );
7678 updateArtifactDirectory (artifactDirectoryContents );
7779
78- return resolveArtifactLayoutPaths (target , artifactCacheMap .get (target ).keySet ());
80+ return resolveArtifactLayoutPaths (target , artifactKind , artifactCacheMap .get (targetKind ).keySet ());
7981 }
8082
81- private ImmutableList <Path > resolveArtifactLayoutPaths (Label target , Set <Path > artifactPaths ) {
83+ private ImmutableList <Path > resolveArtifactLayoutPaths (Label target , RuntimeArtifactKind artifactKind , Set <Path > artifactPaths ) {
8284 return artifactPaths .stream ()
83- .map (artifactPath -> runfilesDirectory .resolve (getArtifactLocalPath (target , artifactPath )))
85+ .map (artifactPath -> runfilesDirectory .resolve (getArtifactLocalPath (target , artifactKind , artifactPath )))
8486 .collect (toImmutableList ());
8587 }
8688
@@ -131,15 +133,15 @@ private void updateArtifactDirectory(
131133 * path -> project artifact.
132134 */
133135 private static ProjectProto .ArtifactDirectoryContents buildArtifactDirectoryContents (
134- Map <Label , Map <Path , ProjectProto .ProjectArtifact >> artifacts ) {
136+ Map <Pair < Label , RuntimeArtifactKind > , Map <Path , ProjectProto .ProjectArtifact >> artifacts ) {
135137 final var artifactDirectoryContents = ProjectProto .ArtifactDirectoryContents .newBuilder ();
136138 for (final var entry : artifacts .entrySet ()) {
137- final var target = entry .getKey ();
139+ final var key = entry .getKey ();
138140 for (final var artifactPathAndDigest : entry .getValue ().entrySet ()) {
139141 final var artifactPath = artifactPathAndDigest .getKey ();
140142 final var artifact = artifactPathAndDigest .getValue ();
141143 artifactDirectoryContents .putContents (
142- getArtifactLocalPath (target , artifactPath ).toString (), artifact );
144+ getArtifactLocalPath (key . first , key . second , artifactPath ).toString (), artifact );
143145 }
144146 }
145147 return artifactDirectoryContents .build ();
@@ -149,7 +151,7 @@ private static ProjectProto.ArtifactDirectoryContents buildArtifactDirectoryCont
149151 * Generates the local artifact path from the target and artifact path. Local Artifact path ->
150152 * Target + SEPARATOR_DIR_NAME + artifactPath.
151153 */
152- public static Path getArtifactLocalPath (Label target , Path artifactPath ) {
153- return target .toFilePath ().resolve (Path .of (SEPARATOR_DIR_NAME )).resolve (artifactPath );
154+ public static Path getArtifactLocalPath (Label target , RuntimeArtifactKind artifactKind , Path artifactPath ) {
155+ return target .toFilePath ().resolve (Path .of (artifactKind . name ())). resolve ( Path . of ( SEPARATOR_DIR_NAME )).resolve (artifactPath );
154156 }
155157}
0 commit comments