Skip to content

Commit 158c136

Browse files
lberkiWyverald
authored andcommitted
Remove the "overwrote runfile" warning.
At HEAD, this is reported on the console as an error but doesn't actually cause a build error and this has been the case for a long time. This means that this particular cat is out of the bag and we can't prohibit this behavior anymore and therefore it's better to not emit spam. RELNOTES: None. PiperOrigin-RevId: 720983277 Change-Id: I2f62247b7bb7a81e30281ab578a8b93f17cef476
1 parent 1b9b842 commit 158c136

File tree

3 files changed

+16
-253
lines changed

3 files changed

+16
-253
lines changed

src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.util.HashSet;
5252
import java.util.LinkedHashMap;
5353
import java.util.Map;
54-
import java.util.Objects;
5554
import java.util.Set;
5655
import java.util.UUID;
5756
import java.util.function.BiConsumer;
@@ -356,7 +355,7 @@ public BiConsumer<ConflictType, String> eventRunfilesConflictReceiver(
356355
EventKind kind =
357356
switch (conflictType) {
358357
case NESTED_RUNFILES_TREE -> EventKind.ERROR;
359-
case ROOT_SYMLINK, PREFIX_CONFLICT ->
358+
case PREFIX_CONFLICT ->
360359
conflictPolicy == ConflictPolicy.ERROR ? EventKind.ERROR : EventKind.WARNING;
361360
default ->
362361
switch (conflictPolicy) {
@@ -386,7 +385,6 @@ public Map<PathFragment, Artifact> getRunfilesInputs(
386385
conflictPolicy == ConflictPolicy.IGNORE
387386
? EnumSet.of(
388387
ConflictType.NESTED_RUNFILES_TREE,
389-
ConflictType.ROOT_SYMLINK,
390388
ConflictType.PREFIX_CONFLICT)
391389
: EnumSet.allOf(ConflictType.class);
392390

@@ -401,7 +399,7 @@ private Map<PathFragment, Artifact> getRunfilesInputs(
401399
Map<PathFragment, Artifact> manifest = getSymlinksAsMap(checker);
402400
// Add artifacts (committed to inclusion on construction of runfiles).
403401
for (Artifact artifact : artifacts.toList()) {
404-
checker.put(manifest, artifact.getRunfilesPath(), artifact, ConflictType.OTHER);
402+
checker.put(manifest, artifact.getRunfilesPath(), artifact);
405403
}
406404

407405
manifest =
@@ -412,7 +410,7 @@ private Map<PathFragment, Artifact> getRunfilesInputs(
412410

413411
// TODO(bazel-team): Create /dev/null-like Artifact to avoid nulls?
414412
for (PathFragment extraPath : emptyFilesSupplier.getExtraPaths(manifest.keySet())) {
415-
checker.put(manifest, extraPath, null, ConflictType.OTHER);
413+
checker.put(manifest, extraPath, null);
416414
}
417415

418416
// Copy manifest map to another manifest map, prepending the workspace name to every path.
@@ -423,11 +421,7 @@ private Map<PathFragment, Artifact> getRunfilesInputs(
423421
builder.addUnderWorkspace(manifest, checker);
424422
builder.addRootSymlinks(getRootSymlinksAsMap(checker), checker);
425423
if (repoMappingManifest != null) {
426-
checker.put(
427-
builder.manifest,
428-
REPO_MAPPING_PATH_FRAGMENT,
429-
repoMappingManifest,
430-
ConflictType.ROOT_SYMLINK);
424+
checker.put(builder.manifest, REPO_MAPPING_PATH_FRAGMENT, repoMappingManifest);
431425
}
432426
return builder.build();
433427
}
@@ -463,15 +457,13 @@ void addUnderWorkspace(Map<PathFragment, Artifact> inputManifest, ConflictChecke
463457
PathFragment path = entry.getKey();
464458
if (isUnderWorkspace(path)) {
465459
sawWorkspaceName = true;
466-
checker.put(
467-
manifest, workspaceName.getRelative(path), entry.getValue(), ConflictType.OTHER);
460+
checker.put(manifest, workspaceName.getRelative(path), entry.getValue());
468461
} else {
469462
if (legacyExternalRunfiles) {
470-
checker.put(
471-
manifest, getLegacyExternalPath(path), entry.getValue(), ConflictType.OTHER);
463+
checker.put(manifest, getLegacyExternalPath(path), entry.getValue());
472464
}
473465
// Always add the non-legacy .runfiles/repo/whatever path.
474-
checker.put(manifest, getExternalPath(path), entry.getValue(), ConflictType.OTHER);
466+
checker.put(manifest, getExternalPath(path), entry.getValue());
475467
}
476468
}
477469
}
@@ -480,11 +472,7 @@ void addUnderWorkspace(Map<PathFragment, Artifact> inputManifest, ConflictChecke
480472
public void addRootSymlinks(
481473
Map<PathFragment, Artifact> inputManifest, ConflictChecker checker) {
482474
for (Map.Entry<PathFragment, Artifact> entry : inputManifest.entrySet()) {
483-
checker.put(
484-
manifest,
485-
checkForWorkspace(entry.getKey()),
486-
entry.getValue(),
487-
ConflictType.ROOT_SYMLINK);
475+
checker.put(manifest, checkForWorkspace(entry.getKey()), entry.getValue());
488476
}
489477
}
490478

@@ -606,7 +594,7 @@ private static Map<PathFragment, Artifact> entriesToMap(
606594
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
607595
for (SymlinkEntry entry : entrySet.toList()) {
608596
// ConflictType does not matter, we ignore conflicts here
609-
checker.put(map, entry.getPath(), entry.getArtifact(), ConflictType.OTHER);
597+
checker.put(map, entry.getPath(), entry.getArtifact());
610598
}
611599
return map;
612600
}
@@ -627,8 +615,6 @@ public Runfiles setConflictPolicy(ConflictPolicy conflictPolicy) {
627615
public enum ConflictType {
628616
NESTED_RUNFILES_TREE, // A runfiles tree artifact in a runfiles tree
629617
PREFIX_CONFLICT, // An entry is the prefix of another
630-
ROOT_SYMLINK, // A root symlink conflicts with something else
631-
OTHER // Everything else
632618
};
633619

634620
/** Checks for conflicts between entries in a runfiles tree while putting them in a map. */
@@ -655,11 +641,7 @@ public ConflictChecker(
655641
* @param path Path fragment to use as key in map.
656642
* @param artifact Artifact to store in map. This may be null to indicate an empty file.
657643
*/
658-
void put(
659-
Map<PathFragment, Artifact> map,
660-
PathFragment path,
661-
Artifact artifact,
662-
ConflictType conflictType) {
644+
void put(Map<PathFragment, Artifact> map, PathFragment path, Artifact artifact) {
663645
if (artifact != null && artifact.isMiddlemanArtifact()) {
664646
if (conflictsToReport.contains(ConflictType.NESTED_RUNFILES_TREE)) {
665647
receiver.accept(
@@ -669,23 +651,6 @@ void put(
669651
return;
670652
}
671653

672-
if (map.containsKey(path) && conflictsToReport.contains(conflictType)) {
673-
// Previous and new entry might have value of null
674-
Artifact previous = map.get(path);
675-
if (!Objects.equals(previous, artifact)) {
676-
String previousStr =
677-
(previous == null) ? "empty file" : previous.getExecPath().toString();
678-
String artifactStr =
679-
(artifact == null) ? "empty file" : artifact.getExecPath().toString();
680-
if (!previousStr.equals(artifactStr)) {
681-
String message =
682-
String.format(
683-
"overwrote runfile %s, was symlink to %s, now symlink to %s",
684-
path.getSafePathString(), previousStr, artifactStr);
685-
receiver.accept(conflictType, message);
686-
}
687-
}
688-
}
689654
map.put(path, artifact);
690655
}
691656
}

src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java

Lines changed: 6 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,6 @@ public void testFilterListForObscuringSymlinksNoObscurers() {
175175
assertNoEvents();
176176
}
177177

178-
private void checkConflictWarning() {
179-
assertContainsEvent("overwrote runfile");
180-
assertWithMessage("ConflictChecker.put should have warned once")
181-
.that(eventCollector.count())
182-
.isEqualTo(1);
183-
assertThat(Iterables.getOnlyElement(eventCollector).getKind()).isEqualTo(EventKind.WARNING);
184-
}
185-
186-
private void checkConflictError() {
187-
assertContainsEvent("overwrote runfile");
188-
assertWithMessage("ConflictChecker.put should have errored once")
189-
.that(eventCollector.count())
190-
.isEqualTo(1);
191-
assertThat(Iterables.getOnlyElement(eventCollector).getKind()).isEqualTo(EventKind.ERROR);
192-
}
193-
194178
private static final class SimpleActionLookupKey implements ActionLookupKey {
195179
private final String name;
196180

@@ -217,7 +201,7 @@ public BuildConfigurationKey getConfigurationKey() {
217201
}
218202

219203
@Test
220-
public void testPutDerivedArtifactWithDifferentOwnerDoesNotConflict() throws Exception {
204+
public void testPutDerivedArtifactWithDifferentOwner() throws Exception {
221205
ArtifactRoot root =
222206
ArtifactRoot.asDerivedRoot(scratch.dir("/workspace"), RootType.Output, "out");
223207
PathFragment path = PathFragment.create("src/foo.cc");
@@ -230,36 +214,13 @@ public void testPutDerivedArtifactWithDifferentOwnerDoesNotConflict() throws Exc
230214
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
231215

232216
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
233-
checker.put(map, path, artifact1, ConflictType.OTHER);
217+
checker.put(map, path, artifact1);
234218
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(path, artifact1));
235-
checker.put(map, path, artifact2, ConflictType.OTHER);
219+
checker.put(map, path, artifact2);
236220
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(path, artifact2));
237221
assertNoEvents();
238222
}
239223

240-
@Test
241-
public void testPutDerivedArtifactWithDifferentPathConflicts() throws Exception {
242-
ArtifactRoot root =
243-
ArtifactRoot.asDerivedRoot(scratch.dir("/workspace"), RootType.Output, "out");
244-
PathFragment path = PathFragment.create("src/foo.cc");
245-
PathFragment path2 = PathFragment.create("src/bar.cc");
246-
247-
SimpleActionLookupKey owner1 = new SimpleActionLookupKey("//owner1");
248-
SimpleActionLookupKey owner2 = new SimpleActionLookupKey("//owner2");
249-
Artifact artifact1 = DerivedArtifact.create(root, root.getExecPath().getRelative(path), owner1);
250-
Artifact artifact2 =
251-
DerivedArtifact.create(root, root.getExecPath().getRelative(path2), owner2);
252-
253-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
254-
255-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
256-
checker.put(map, path, artifact1, ConflictType.OTHER);
257-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(path, artifact1));
258-
checker.put(map, path, artifact2, ConflictType.OTHER);
259-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(path, artifact2));
260-
checkConflictWarning();
261-
}
262-
263224
private BiConsumer<ConflictType, String> eventConflictReceiver(EventKind eventKind) {
264225
return (conflictType, message) -> reporter.handle(Event.of(eventKind, message));
265226
}
@@ -277,127 +238,6 @@ private Runfiles.ConflictChecker eventConflictChecker(Runfiles.ConflictPolicy co
277238
}
278239
;
279240

280-
@Test
281-
public void testPutCatchesConflict() {
282-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
283-
PathFragment pathA = PathFragment.create("a");
284-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
285-
Artifact artifactC = ActionsTestUtil.createArtifact(root, "c");
286-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
287-
288-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
289-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
290-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactB));
291-
checker.put(map, pathA, artifactC, ConflictType.OTHER);
292-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactC));
293-
checkConflictWarning();
294-
}
295-
296-
@Test
297-
public void testPutReportsError() {
298-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
299-
PathFragment pathA = PathFragment.create("a");
300-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
301-
Artifact artifactC = ActionsTestUtil.createArtifact(root, "c");
302-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
303-
304-
// Same as above but with ERROR not WARNING
305-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.ERROR);
306-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
307-
reporter.removeHandler(failFastHandler); // So it doesn't throw AssertionError
308-
checker.put(map, pathA, artifactC, ConflictType.OTHER);
309-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactC));
310-
checkConflictError();
311-
}
312-
313-
@Test
314-
public void testPutCatchesConflictBetweenNullAndNotNull() {
315-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
316-
PathFragment pathA = PathFragment.create("a");
317-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
318-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
319-
320-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
321-
checker.put(map, pathA, null, ConflictType.OTHER);
322-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
323-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactB));
324-
checkConflictWarning();
325-
}
326-
327-
@Test
328-
public void testPutCatchesConflictBetweenNotNullAndNull() {
329-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
330-
PathFragment pathA = PathFragment.create("a");
331-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
332-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
333-
334-
// Same as above but opposite order
335-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
336-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
337-
checker.put(map, pathA, null, ConflictType.OTHER);
338-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, null));
339-
checkConflictWarning();
340-
}
341-
342-
@Test
343-
public void testPutIgnoresConflict() {
344-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
345-
PathFragment pathA = PathFragment.create("a");
346-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
347-
Artifact artifactC = ActionsTestUtil.createArtifact(root, "c");
348-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
349-
350-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.IGNORE);
351-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
352-
checker.put(map, pathA, artifactC, ConflictType.OTHER);
353-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactC));
354-
assertNoEvents();
355-
}
356-
357-
@Test
358-
public void testPutIgnoresConflictWithIgnorePolicy() {
359-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
360-
PathFragment pathA = PathFragment.create("a");
361-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
362-
Artifact artifactC = ActionsTestUtil.createArtifact(root, "c");
363-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
364-
365-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.IGNORE);
366-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
367-
checker.put(map, pathA, artifactC, ConflictType.OTHER);
368-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactC));
369-
assertNoEvents();
370-
}
371-
372-
@Test
373-
public void testPutIgnoresSameArtifact() {
374-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
375-
PathFragment pathA = PathFragment.create("a");
376-
Artifact artifactB = ActionsTestUtil.createArtifact(root, "b");
377-
Artifact artifactB2 = ActionsTestUtil.createArtifact(root, "b");
378-
assertThat(artifactB2).isEqualTo(artifactB);
379-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
380-
381-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
382-
checker.put(map, pathA, artifactB, ConflictType.OTHER);
383-
checker.put(map, pathA, artifactB2, ConflictType.OTHER);
384-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, artifactB2));
385-
assertNoEvents();
386-
}
387-
388-
@Test
389-
public void testPutIgnoresNullAndNull() {
390-
PathFragment pathA = PathFragment.create("a");
391-
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
392-
393-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
394-
checker.put(map, pathA, null, ConflictType.OTHER);
395-
// Add it again
396-
checker.put(map, pathA, null, ConflictType.OTHER);
397-
assertThat(map.entrySet()).containsExactly(Maps.immutableEntry(pathA, null));
398-
assertNoEvents();
399-
}
400-
401241
@Test
402242
public void testPutNoConflicts() {
403243
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
@@ -409,11 +249,11 @@ public void testPutNoConflicts() {
409249
Map<PathFragment, Artifact> map = new LinkedHashMap<>();
410250

411251
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
412-
checker.put(map, pathA, artifactA, ConflictType.OTHER);
252+
checker.put(map, pathA, artifactA);
413253
// Add different artifact under different path
414-
checker.put(map, pathB, artifactB, ConflictType.OTHER);
254+
checker.put(map, pathB, artifactB);
415255
// Add artifact again under different path
416-
checker.put(map, pathC, artifactA, ConflictType.OTHER);
256+
checker.put(map, pathC, artifactA);
417257
assertThat(map.entrySet())
418258
.containsExactly(
419259
Maps.immutableEntry(pathA, artifactA),
@@ -495,31 +335,6 @@ public void testRunfileAdded() {
495335
assertNoEvents();
496336
}
497337

498-
// TODO(kchodorow): remove this once the default workspace name is always set.
499-
@Test
500-
public void testConflictWithExternal() {
501-
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));
502-
PathFragment pathB = PathFragment.create("repo/b");
503-
PathFragment externalLegacyPath = LabelConstants.EXTERNAL_PATH_PREFIX.getRelative(pathB);
504-
PathFragment externalRunfilesPathB =
505-
LabelConstants.EXTERNAL_RUNFILES_PATH_PREFIX.getRelative(pathB);
506-
Artifact artifactB = ActionsTestUtil.createArtifactWithRootRelativePath(root, pathB);
507-
Artifact artifactExternalB =
508-
ActionsTestUtil.createArtifactWithRootRelativePath(root, externalLegacyPath);
509-
510-
Runfiles.ManifestBuilder builder = new Runfiles.ManifestBuilder(
511-
PathFragment.EMPTY_FRAGMENT, false);
512-
513-
Map<PathFragment, Artifact> inputManifest =
514-
ImmutableMap.of(pathB, artifactB, externalRunfilesPathB, artifactExternalB);
515-
Runfiles.ConflictChecker checker = eventConflictChecker(Runfiles.ConflictPolicy.WARN);
516-
builder.addUnderWorkspace(inputManifest, checker);
517-
518-
assertThat(builder.build().entrySet()).containsExactly(
519-
Maps.immutableEntry(PathFragment.create("repo/b"), artifactExternalB));
520-
checkConflictWarning();
521-
}
522-
523338
@Test
524339
public void testMergeWithSymlinks() throws Exception {
525340
ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace")));

0 commit comments

Comments
 (0)