Skip to content

Commit

Permalink
Make cpp file extensions case sensitive again
Browse files Browse the repository at this point in the history
This fixes an issue introduced by PR bazelbuild#14005 where .c and .C
extensions were handled case-insensitive on Windows so the cxxopt will be passed to C source files.

Closes bazelbuild#15073 .
  • Loading branch information
kkpattern committed Apr 17, 2023
1 parent 592327a commit 8e3fea8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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<String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 8e3fea8

Please sign in to comment.