Skip to content

Commit 2852f1f

Browse files
LeFroschGoogler
and
Googler
authored
Add/Update getLocalFiles method to support both BlazeArtifact and OutputArtifact type artifacts (#7508)
- Add a method getLocalFilesForLegacySync to support processing BlazeArtifact artifact types. - Update existing getLocalFiles method to fetch local files for OutputArtifact type artifacts. - This will help migrate LocalFileArtifact#getLocalFiles to using RuntimeArtifactCache, which only supports OutputArtifact (as it expects artifacts to contain a digest). - Invokers of the method has been updated based on whether the flow is used in LegacySync or QuerySync (Native debugging). Bug: 385469770 Test: Existing tests for testing old and new methods as their implementation will only be updated in next CLs. Change-Id: I6b7ecfd522f086b712c99e90fe30f1b3b3cb7abe Change-Id: I523e59d72a3c239b234e0112c76b128e2bc19fb7 AOSP: ed8535e5178e2f3f0459e7c01de1902fb319d4c5 Co-authored-by: Googler <[email protected]>
1 parent a625dba commit 2852f1f

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

base/src/com/google/idea/blaze/base/command/buildresult/LocalFileArtifact.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.collect.ImmutableList;
2121
import com.google.idea.blaze.base.io.FileOperationProvider;
2222
import com.google.idea.blaze.common.artifact.BlazeArtifact;
23+
import com.google.idea.blaze.common.artifact.OutputArtifact;
2324
import java.io.File;
2425
import java.util.Collection;
2526

@@ -32,13 +33,26 @@ public interface LocalFileArtifact extends BlazeArtifact {
3233
* <p>Some callers will only ever accept local outputs (e.g. when debugging, and making use of
3334
* runfiles directories).
3435
*/
35-
static ImmutableList<File> getLocalFiles(Collection<? extends BlazeArtifact> artifacts) {
36+
static ImmutableList<File> getLocalFiles(Collection<? extends OutputArtifact> artifacts) {
3637
return artifacts.stream()
3738
.filter(a -> a instanceof LocalFileArtifact)
3839
.map(a -> ((LocalFileArtifact) a).getFile())
3940
.collect(toImmutableList());
4041
}
4142

43+
/**
44+
* Filters out non-local artifacts for legacy sync as it supports BlazeArtifact.
45+
*
46+
* <p>Some callers will only ever accept local outputs (e.g. when debugging, and making use of
47+
* runfiles directories).
48+
*/
49+
static ImmutableList<File> getLocalFilesForLegacySync(Collection<? extends BlazeArtifact> artifacts) {
50+
return artifacts.stream()
51+
.filter(a -> a instanceof LocalFileArtifact)
52+
.map(a -> ((LocalFileArtifact) a).getFile())
53+
.collect(toImmutableList());
54+
}
55+
4256
File getFile();
4357

4458
@Override

base/src/com/google/idea/blaze/base/sync/aspects/BlazeIdeInterfaceAspectsImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private static TargetMapAndInterfaceState updateTargetMap(
269269
ListenableFuture<?> fetchLocalFilesFuture =
270270
PrefetchService.getInstance()
271271
.prefetchFiles(
272-
/* files= */ LocalFileArtifact.getLocalFiles(diff.getUpdatedOutputs()),
272+
/* files= */ LocalFileArtifact.getLocalFilesForLegacySync(diff.getUpdatedOutputs()),
273273
/* refetchCachedFiles= */ true,
274274
/* fetchFileTypes= */ false);
275275
if (!FutureUtil.waitForFuture(context, fetchLocalFilesFuture)

base/tests/unittests/com/google/idea/blaze/base/command/buildresult/BuildEventProtocolOutputReaderLegacyTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void parseAllOutputs_singleTargetEvents_returnsAllOutputs() throws Except
133133
BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null)
134134
.getAllOutputArtifactsForTesting();
135135

136-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
136+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
137137
.containsExactlyElementsIn(filePaths.stream().map(File::new).toArray())
138138
.inOrder();
139139
}
@@ -175,7 +175,7 @@ public void parseAllOutputs_singleTargetEventsPlusExtras_returnsAllOutputs() thr
175175
BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null)
176176
.getAllOutputArtifactsForTesting();
177177

178-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
178+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
179179
.containsExactlyElementsIn(filePaths.stream().map(File::new).toArray())
180180
.inOrder();
181181
}
@@ -220,7 +220,7 @@ public void parseAllOutputs_singleTargetWithMultipleFileSets_returnsAllOutputs()
220220
BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null)
221221
.getAllOutputArtifactsForTesting();
222222

223-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
223+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
224224
.containsExactlyElementsIn(allFiles)
225225
.inOrder();
226226
}
@@ -257,7 +257,7 @@ public void parseAllOutputs_streamWithDuplicateFiles_returnsUniqueOutputs() thro
257257
BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null)
258258
.getAllOutputArtifactsForTesting();
259259

260-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
260+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
261261
.containsExactlyElementsIn(allFiles)
262262
.inOrder();
263263
}
@@ -289,7 +289,7 @@ public void parseArtifactsForTarget_singleTarget_returnsTargetOutputs() throws E
289289
getOutputGroupTargetArtifacts(
290290
BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null).fileSets, "group-name", "//some:target");
291291

292-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
292+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
293293
.containsExactlyElementsIn(allFiles)
294294
.inOrder();
295295
}
@@ -329,7 +329,7 @@ public void parseArtifactsForTarget_twoTargets_returnsCorrectTargetOutputs() thr
329329
getOutputGroupTargetArtifacts(
330330
BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null).fileSets, "group-name", "//some:target");
331331

332-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
332+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
333333
.containsExactlyElementsIn(allFiles)
334334
.inOrder();
335335
}
@@ -375,7 +375,7 @@ public void parseAllArtifactsInOutputGroups_oneGroup_returnsAllOutputs() throws
375375
getOutputGroupArtifacts(BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null).fileSets,
376376
"group-name");
377377

378-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
378+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
379379
.containsExactlyElementsIn(allFiles)
380380
.inOrder();
381381
}
@@ -416,7 +416,7 @@ public void parseAllArtifactsInOutputGroups_oneOfTwoGroups_returnsCorrectOutputs
416416
getOutputGroupArtifacts(BepParser.parseBepArtifactsForLegacySync(BuildEventStreamProvider.fromInputStream(asInputStream(events)), null).fileSets,
417417
"group-1");
418418

419-
assertThat(LocalFileArtifact.getLocalFiles(parsedFilenames))
419+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(parsedFilenames))
420420
.containsExactlyElementsIn(allFiles)
421421
.inOrder();
422422
}
@@ -453,7 +453,7 @@ public void getFullArtifactData_returnsTransitiveOutputs() throws Exception {
453453
ImmutableList<OutputArtifact> outputs =
454454
outputData.values().stream().map(d -> d.artifact).collect(toImmutableList());
455455

456-
assertThat(LocalFileArtifact.getLocalFiles(outputs)).containsExactlyElementsIn(allOutputs);
456+
assertThat(LocalFileArtifact.getLocalFilesForLegacySync(outputs)).containsExactlyElementsIn(allOutputs);
457457
}
458458

459459
private static InputStream asInputStream(BuildEvent.Builder... events) throws Exception {

base/tests/unittests/com/google/idea/blaze/base/command/buildresult/BuildEventProtocolOutputReaderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public void parseTestResults_multipleEvents_returnsAllResults() throws Exception
585585
}
586586

587587
private static ImmutableList<File> getOutputXmlFiles(BlazeTestResult result) {
588-
return LocalFileArtifact.getLocalFiles(result.getOutputXmlFiles());
588+
return LocalFileArtifact.getLocalFilesForLegacySync(result.getOutputXmlFiles());
589589
}
590590

591591
private static InputStream asInputStream(BuildEvent.Builder... events) throws Exception {

java/src/com/google/idea/blaze/java/sync/jdeps/JdepsFileReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private JdepsState doLoadJdepsFiles(
160160
/* outputArtifacts= */ RemoteOutputArtifact.getRemoteArtifacts(outputArtifacts));
161161
ListenableFuture<?> fetchLocalFilesFuture =
162162
PrefetchService.getInstance()
163-
.prefetchFiles(LocalFileArtifact.getLocalFiles(outputArtifacts), true, false);
163+
.prefetchFiles(LocalFileArtifact.getLocalFilesForLegacySync(outputArtifacts), true, false);
164164
if (!FutureUtil.waitForFuture(
165165
context, Futures.allAsList(downloadArtifactsFuture, fetchLocalFilesFuture))
166166
.timed("FetchJdeps", EventType.Prefetching)

java/src/com/google/idea/blaze/java/sync/source/PackageManifestReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public Map<TargetKey, Map<ArtifactLocation, String>> readPackageManifestFiles(
115115
RemoteArtifactPrefetcher.getInstance().downloadArtifacts(project.getName(), toDownload);
116116
ListenableFuture<PrefetchStats> fetchLocalFilesFuture =
117117
PrefetchService.getInstance()
118-
.prefetchFiles(LocalFileArtifact.getLocalFiles(diff.getUpdatedOutputs()), true, false);
118+
.prefetchFiles(LocalFileArtifact.getLocalFilesForLegacySync(diff.getUpdatedOutputs()), true, false);
119119

120120
if (!FutureUtil.waitForFuture(
121121
context, Futures.allAsList(fetchRemoteArtifactFuture, fetchLocalFilesFuture))

0 commit comments

Comments
 (0)