From edfe2a17e3434cce660757f59b14f2e9d6ab944e Mon Sep 17 00:00:00 2001 From: Simon Bjorklen Date: Wed, 24 Nov 2021 02:36:52 -0800 Subject: [PATCH] Make cpp assembly file extensions case sensitive again This fixes an issue introduced by PR #14005 where .s and .S extensions were handled case-insensitive on Windows so the action assemble was triggered instead of preprocess_assemble. Closes #14131. PiperOrigin-RevId: 412005097 --- .../build/lib/rules/cpp/CppFileTypes.java | 38 +++++++++++++++++-- .../build/lib/rules/cpp/CppFileTypesTest.java | 12 ++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index 5140b4afdd5625..7becb65247b599 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -91,16 +91,46 @@ public ImmutableList getExtensions() { } }; - public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = FileType.of(".S"); - public static final FileType PIC_ASSEMBLER = FileType.of(".pic.s"); + // FileType is extended to use case-sensitive comparison also on Windows + public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = + new FileType() { + final String ext = ".S"; + + @Override + public boolean apply(String path) { + return path.endsWith(ext); + } + + @Override + public ImmutableList getExtensions() { + return ImmutableList.of(ext); + } + }; + + // FileType is extended to use case-sensitive comparison also on Windows + public static final FileType PIC_ASSEMBLER = + new FileType() { + final String ext = ".pic.s"; + + @Override + public boolean apply(String path) { + return OS.endsWith(path, ext) && path.endsWith(".s"); + } + + @Override + public ImmutableList getExtensions() { + return ImmutableList.of(ext); + } + }; + + // FileType is extended to use case-sensitive comparison also on Windows public static final FileType ASSEMBLER = new FileType() { final String ext = ".s"; @Override public boolean apply(String path) { - return (OS.endsWith(path, ext) && !PIC_ASSEMBLER.matches(path)) - || OS.endsWith(path, ".asm"); + return (path.endsWith(ext) && !PIC_ASSEMBLER.matches(path)) || OS.endsWith(path, ".asm"); } @Override diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java index 3c58219aafd127..e631c8615b9085 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java @@ -57,4 +57,16 @@ public void testVersionedSharedLibraries() { assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("libA.so.if.exp")).isFalse(); assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("libA.so.if.lib")).isFalse(); } + + @Test + public void testCaseSensitiveAssemblyFiles() { + assertThat(CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches("foo.S")).isTrue(); + assertThat(CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches("foo.s")).isFalse(); + assertThat(CppFileTypes.PIC_ASSEMBLER.matches("foo.pic.s")).isTrue(); + assertThat(CppFileTypes.PIC_ASSEMBLER.matches("foo.pic.S")).isFalse(); + assertThat(CppFileTypes.ASSEMBLER.matches("foo.s")).isTrue(); + assertThat(CppFileTypes.ASSEMBLER.matches("foo.asm")).isTrue(); + assertThat(CppFileTypes.ASSEMBLER.matches("foo.pic.s")).isFalse(); + assertThat(CppFileTypes.ASSEMBLER.matches("foo.S")).isFalse(); + } }