Skip to content

Commit edfe2a1

Browse files
Simon Bjorklencopybara-github
Simon Bjorklen
authored andcommitted
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
1 parent cbad324 commit edfe2a1

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java

+34-4
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,46 @@ public ImmutableList<String> getExtensions() {
9191
}
9292
};
9393

94-
public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = FileType.of(".S");
95-
public static final FileType PIC_ASSEMBLER = FileType.of(".pic.s");
94+
// FileType is extended to use case-sensitive comparison also on Windows
95+
public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR =
96+
new FileType() {
97+
final String ext = ".S";
98+
99+
@Override
100+
public boolean apply(String path) {
101+
return path.endsWith(ext);
102+
}
103+
104+
@Override
105+
public ImmutableList<String> getExtensions() {
106+
return ImmutableList.of(ext);
107+
}
108+
};
109+
110+
// FileType is extended to use case-sensitive comparison also on Windows
111+
public static final FileType PIC_ASSEMBLER =
112+
new FileType() {
113+
final String ext = ".pic.s";
114+
115+
@Override
116+
public boolean apply(String path) {
117+
return OS.endsWith(path, ext) && path.endsWith(".s");
118+
}
119+
120+
@Override
121+
public ImmutableList<String> getExtensions() {
122+
return ImmutableList.of(ext);
123+
}
124+
};
125+
126+
// FileType is extended to use case-sensitive comparison also on Windows
96127
public static final FileType ASSEMBLER =
97128
new FileType() {
98129
final String ext = ".s";
99130

100131
@Override
101132
public boolean apply(String path) {
102-
return (OS.endsWith(path, ext) && !PIC_ASSEMBLER.matches(path))
103-
|| OS.endsWith(path, ".asm");
133+
return (path.endsWith(ext) && !PIC_ASSEMBLER.matches(path)) || OS.endsWith(path, ".asm");
104134
}
105135

106136
@Override

src/test/java/com/google/devtools/build/lib/rules/cpp/CppFileTypesTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@ public void testVersionedSharedLibraries() {
5757
assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("libA.so.if.exp")).isFalse();
5858
assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("libA.so.if.lib")).isFalse();
5959
}
60+
61+
@Test
62+
public void testCaseSensitiveAssemblyFiles() {
63+
assertThat(CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches("foo.S")).isTrue();
64+
assertThat(CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches("foo.s")).isFalse();
65+
assertThat(CppFileTypes.PIC_ASSEMBLER.matches("foo.pic.s")).isTrue();
66+
assertThat(CppFileTypes.PIC_ASSEMBLER.matches("foo.pic.S")).isFalse();
67+
assertThat(CppFileTypes.ASSEMBLER.matches("foo.s")).isTrue();
68+
assertThat(CppFileTypes.ASSEMBLER.matches("foo.asm")).isTrue();
69+
assertThat(CppFileTypes.ASSEMBLER.matches("foo.pic.s")).isFalse();
70+
assertThat(CppFileTypes.ASSEMBLER.matches("foo.S")).isFalse();
71+
}
6072
}

0 commit comments

Comments
 (0)