Skip to content

Commit

Permalink
Make output name case-insensitive while calculating output names for …
Browse files Browse the repository at this point in the history
…object files

This change is due to Windows and macOS, where file paths are case-insensitive

RELNOTES:
PiperOrigin-RevId: 194223755
  • Loading branch information
meteorcloudy authored and Copybara-Service committed Apr 25, 2018
1 parent b858ade commit 204dfe1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1222,15 +1222,16 @@ private ImmutableMap<Artifact, String> calculateOutputNameMap(
for (Artifact source : sourceArtifacts) {
String outputName =
FileSystemUtils.removeExtension(source.getRootRelativePath()).getBaseName();
count.put(outputName, count.getOrDefault(outputName, 0) + 1);
count.put(outputName.toLowerCase(),
count.getOrDefault(outputName.toLowerCase(), 0) + 1);
}

for (Artifact source : sourceArtifacts) {
String outputName =
FileSystemUtils.removeExtension(source.getRootRelativePath()).getBaseName();
if (count.getOrDefault(outputName, 0) > 1) {
int num = number.getOrDefault(outputName, 0);
number.put(outputName, num + 1);
if (count.getOrDefault(outputName.toLowerCase(), 0) > 1) {
int num = number.getOrDefault(outputName.toLowerCase(), 0);
number.put(outputName.toLowerCase(), num + 1);
outputName = num + "/" + outputName;
}
// If prefixDir is set, prepend it to the outputName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private void setupPackagesForSourcesWithSameBaseNameTests() throws Exception {
"foo/BUILD",
"cc_library(",
" name = 'lib',",
" srcs = ['a.cc', 'subpkg/b.cc', 'subpkg/a.c', '//bar:srcs'],",
" srcs = ['a.cc', 'subpkg1/b.cc', 'subpkg1/a.c', '//bar:srcs', 'subpkg2/A.c'],",
")");
scratch.file("bar/BUILD", "filegroup(name = 'srcs', srcs = ['a.cpp'])");
}
Expand All @@ -599,17 +599,20 @@ public void testContainingSourcesWithSameBaseNameWithNewObjPath() throws Excepti
Artifact a0 = getBinArtifact("_objs/lib/0/a.pic.o", "//foo:lib");
Artifact a1 = getBinArtifact("_objs/lib/1/a.pic.o", "//foo:lib");
Artifact a2 = getBinArtifact("_objs/lib/2/a.pic.o", "//foo:lib");
Artifact a3 = getBinArtifact("_objs/lib/3/A.pic.o", "//foo:lib");
Artifact b = getBinArtifact("_objs/lib/b.pic.o", "//foo:lib");

assertThat(getGeneratingAction(a0)).isNotNull();
assertThat(getGeneratingAction(a1)).isNotNull();
assertThat(getGeneratingAction(a2)).isNotNull();
assertThat(getGeneratingAction(a3)).isNotNull();
assertThat(getGeneratingAction(b)).isNotNull();

assertThat(getGeneratingAction(a0).getInputs()).contains(getSourceArtifact("foo/a.cc"));
assertThat(getGeneratingAction(a1).getInputs()).contains(getSourceArtifact("foo/subpkg/a.c"));
assertThat(getGeneratingAction(a1).getInputs()).contains(getSourceArtifact("foo/subpkg1/a.c"));
assertThat(getGeneratingAction(a2).getInputs()).contains(getSourceArtifact("bar/a.cpp"));
assertThat(getGeneratingAction(b).getInputs()).contains(getSourceArtifact("foo/subpkg/b.cc"));
assertThat(getGeneratingAction(a3).getInputs()).contains(getSourceArtifact("foo/subpkg2/A.c"));
assertThat(getGeneratingAction(b).getInputs()).contains(getSourceArtifact("foo/subpkg1/b.cc"));
}

@Test
Expand All @@ -620,19 +623,22 @@ public void testContainingSourcesWithSameBaseNameWithLegacyObjPath() throws Exce
getConfiguredTarget("//foo:lib");

Artifact a0 = getBinArtifact("_objs/lib/foo/a.pic.o", "//foo:lib");
Artifact a1 = getBinArtifact("_objs/lib/foo/subpkg/a.pic.o", "//foo:lib");
Artifact a1 = getBinArtifact("_objs/lib/foo/subpkg1/a.pic.o", "//foo:lib");
Artifact a2 = getBinArtifact("_objs/lib/bar/a.pic.o", "//foo:lib");
Artifact b = getBinArtifact("_objs/lib/foo/subpkg/b.pic.o", "//foo:lib");
Artifact a3 = getBinArtifact("_objs/lib/foo/subpkg2/A.pic.o", "//foo:lib");
Artifact b = getBinArtifact("_objs/lib/foo/subpkg1/b.pic.o", "//foo:lib");

assertThat(getGeneratingAction(a0)).isNotNull();
assertThat(getGeneratingAction(a1)).isNotNull();
assertThat(getGeneratingAction(a2)).isNotNull();
assertThat(getGeneratingAction(a3)).isNotNull();
assertThat(getGeneratingAction(b)).isNotNull();

assertThat(getGeneratingAction(a0).getInputs()).contains(getSourceArtifact("foo/a.cc"));
assertThat(getGeneratingAction(a1).getInputs()).contains(getSourceArtifact("foo/subpkg/a.c"));
assertThat(getGeneratingAction(a1).getInputs()).contains(getSourceArtifact("foo/subpkg1/a.c"));
assertThat(getGeneratingAction(a2).getInputs()).contains(getSourceArtifact("bar/a.cpp"));
assertThat(getGeneratingAction(b).getInputs()).contains(getSourceArtifact("foo/subpkg/b.cc"));
assertThat(getGeneratingAction(a3).getInputs()).contains(getSourceArtifact("foo/subpkg2/A.c"));
assertThat(getGeneratingAction(b).getInputs()).contains(getSourceArtifact("foo/subpkg1/b.cc"));
}

private void setupPackagesForModuleTests(boolean useHeaderModules) throws Exception {
Expand Down

0 comments on commit 204dfe1

Please sign in to comment.