From 204dfe13ead529cb3ba852243aa677f6b5f7c9ee Mon Sep 17 00:00:00 2001 From: pcloudy Date: Wed, 25 Apr 2018 04:47:05 -0700 Subject: [PATCH] Make output name case-insensitive while calculating output names for object files This change is due to Windows and macOS, where file paths are case-insensitive RELNOTES: PiperOrigin-RevId: 194223755 --- .../lib/rules/cpp/CcCompilationHelper.java | 9 +++++---- .../cpp/CcLibraryConfiguredTargetTest.java | 20 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) 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 {