Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.3.0] Make cpp file extensions case sensitive again #18552

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,44 @@ 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();
}
}