diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java index 85516bc220cbc3..73894018591823 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java @@ -1222,15 +1222,16 @@ private ImmutableMap 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 diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index bf9ff66ae49bdd..c509a366de907f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -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'])"); } @@ -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 @@ -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 {