Skip to content

Commit e4990f8

Browse files
kkpatterncopybara-github
authored andcommitted
Make cpp file extensions case sensitive again
This fixes an issue introduced by PR #14005 where .c and .C extensions were handled case-insensitive on Windows so the cxxopt will be passed to C source files. Closes #15073 . Closes #18119. PiperOrigin-RevId: 526001251 Change-Id: I464e5feae397bdac443ddd159309f77071629e01
1 parent d3ebbb7 commit e4990f8

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,44 @@ public final class CppFileTypes {
3030
// .cu and .cl are CUDA and OpenCL source extensions, respectively. They are expected to only be
3131
// supported with clang. Bazel is not officially supporting these targets, and the extensions are
3232
// listed only as long as they work with the existing C++ actions.
33+
// FileType is extended to use case-sensitive comparison also on Windows
3334
public static final FileType CPP_SOURCE =
34-
FileType.of(".cc", ".cpp", ".cxx", ".c++", ".C", ".cu", ".cl");
35-
public static final FileType C_SOURCE = FileType.of(".c");
35+
new FileType() {
36+
final ImmutableList<String> extensions =
37+
ImmutableList.of(".cc", ".cpp", ".cxx", ".c++", ".C", ".cu", ".cl");
38+
39+
@Override
40+
public boolean apply(String path) {
41+
for (String ext : extensions) {
42+
if (path.endsWith(ext)) {
43+
return true;
44+
}
45+
}
46+
return false;
47+
}
48+
49+
@Override
50+
public ImmutableList<String> getExtensions() {
51+
return extensions;
52+
}
53+
};
54+
55+
// FileType is extended to use case-sensitive comparison also on Windows
56+
public static final FileType C_SOURCE =
57+
new FileType() {
58+
final String ext = ".c";
59+
60+
@Override
61+
public boolean apply(String path) {
62+
return path.endsWith(ext);
63+
}
64+
65+
@Override
66+
public ImmutableList<String> getExtensions() {
67+
return ImmutableList.of(ext);
68+
}
69+
};
70+
3671
public static final FileType OBJC_SOURCE = FileType.of(".m");
3772
public static final FileType OBJCPP_SOURCE = FileType.of(".mm");
3873
public static final FileType CLIF_INPUT_PROTO = FileType.of(".ipb");

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ public void testNoExtensionLibraries() {
7777
assertThat(Link.ARCHIVE_LIBRARY_FILETYPES.matches("someframework")).isTrue();
7878
assertThat(Link.ARCHIVE_FILETYPES.matches("someframework")).isTrue();
7979
}
80+
81+
@Test
82+
public void testCaseSensitiveCFiles() {
83+
assertThat(CppFileTypes.C_SOURCE.matches("foo.c")).isTrue();
84+
assertThat(CppFileTypes.CPP_SOURCE.matches("foo.c")).isFalse();
85+
assertThat(CppFileTypes.C_SOURCE.matches("foo.C")).isFalse();
86+
assertThat(CppFileTypes.CPP_SOURCE.matches("foo.C")).isTrue();
87+
}
8088
}

0 commit comments

Comments
 (0)