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 d525d0be65d8e5..a8e7c535240e14 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 @@ -30,9 +30,43 @@ public final class CppFileTypes { // .cu and .cl are CUDA and OpenCL source extensions, respectively. They are expected to only be // supported with clang. Bazel is not officially supporting these targets, and the extensions are // listed only as long as they work with the existing C++ actions. + // FileType is extended to use case-sensitive comparison also on Windows public static final FileType CPP_SOURCE = - FileType.of(".cc", ".cpp", ".cxx", ".c++", ".C", ".cu", ".cl"); - public static final FileType C_SOURCE = FileType.of(".c"); + new FileType() { + final ImmutableList extensions = ImmutableList.of(".cc", ".cpp", ".cxx", ".c++", ".C", ".cu", ".cl"); + + @Override + public boolean apply(String path) { + for (String ext : extensions) { + if (path.endsWith(ext)) { + return true; + } + } + return false; + } + + @Override + public ImmutableList getExtensions() { + return extensions; + } + }; + + // FileType is extended to use case-sensitive comparison also on Windows + public static final FileType C_SOURCE = + new FileType() { + final String ext = ".c"; + + @Override + public boolean apply(String path) { + return path.endsWith(ext); + } + + @Override + public ImmutableList getExtensions() { + return ImmutableList.of(ext); + } + }; + public static final FileType OBJC_SOURCE = FileType.of(".m"); public static final FileType OBJCPP_SOURCE = FileType.of(".mm"); public static final FileType CLIF_INPUT_PROTO = FileType.of(".ipb"); 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 88aa7ba707292f..4487d6545b8096 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 @@ -77,4 +77,12 @@ public void testNoExtensionLibraries() { assertThat(Link.ARCHIVE_LIBRARY_FILETYPES.matches("someframework")).isTrue(); assertThat(Link.ARCHIVE_FILETYPES.matches("someframework")).isTrue(); } + + @Test + public void testCaseSensitiveCFiles() { + assertThat(CppFileTypes.C_SOURCE.matches("foo.c")).isTrue(); + assertThat(CppFileTypes.CPP_SOURCE.matches("foo.c")).isFalse(); + assertThat(CppFileTypes.C_SOURCE.matches("foo.C")).isFalse(); + assertThat(CppFileTypes.CPP_SOURCE.matches("foo.C")).isTrue(); + } }