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

Make filetypes case insensitive on Windows #14005

Closed
Closed
Changes from 1 commit
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 @@ -18,12 +18,14 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.vfs.OsPathPolicy;
import java.util.regex.Pattern;

/**
* C++-related file type definitions.
*/
public final class CppFileTypes {
private static final OsPathPolicy OS = OsPathPolicy.getFilePathOs();

// .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.
Expand Down Expand Up @@ -64,7 +66,7 @@ public final class CppFileTypes {

@Override
public boolean apply(String path) {
return path.endsWith(ext) && !PIC_PREPROCESSED_C.matches(path);
return OS.endsWith(path, ext) && !PIC_PREPROCESSED_C.matches(path);
}

@Override
Expand All @@ -79,7 +81,7 @@ public ImmutableList<String> getExtensions() {

@Override
public boolean apply(String path) {
return path.endsWith(ext) && !PIC_PREPROCESSED_CPP.matches(path);
return OS.endsWith(path, ext) && !PIC_PREPROCESSED_CPP.matches(path);
}

@Override
Expand All @@ -96,7 +98,7 @@ public ImmutableList<String> getExtensions() {

@Override
public boolean apply(String path) {
return (path.endsWith(ext) && !PIC_ASSEMBLER.matches(path)) || path.endsWith(".asm");
return (OS.endsWith(path, ext) && !PIC_ASSEMBLER.matches(path)) || OS.endsWith(path, ".asm");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could make .S files end up with ASSEMBLE action instead of PREPROCESS_ASSEMBLE on Windows?

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

} else if (CppFileTypes.ASSEMBLER.matches(sourcePath)) {
  return CppActionNames.ASSEMBLE;
} else if (CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches(sourcePath)) {
  return CppActionNames.PREPROCESS_ASSEMBLE;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, is this a serious problem? Do you know how to distinguish assemble and preprocess assemble actions on Windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meteorcloudy we just saw that this is a problem also with .c and .C files, on one side Bazel considers .c as C and .C as C++, once you are case insensitive on Windows there is the problem that the .c files end up as C++ files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like Make filetypes case insensitive is going to be an incompatible change, which may not have much gains for us. I think maybe the correctly way to is to make filetype configuration first? Just like the artifcat extension for binary/static library/dynamic library /cc @oquenchil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this is the issue #15073

}

@Override
Expand All @@ -114,11 +116,11 @@ public ImmutableList<String> getExtensions() {
public boolean apply(String path) {
if (PIC_ARCHIVE.matches(path)
|| ALWAYS_LINK_LIBRARY.matches(path)
|| path.endsWith(".if.lib")) {
|| OS.endsWith(path, ".if.lib")) {
return false;
}
for (String ext : extensions) {
if (path.endsWith(ext)) {
if (OS.endsWith(path, ext)) {
return true;
}
}
Expand All @@ -138,8 +140,8 @@ public ImmutableList<String> getExtensions() {

@Override
public boolean apply(String path) {
return (path.endsWith(ext) && !ALWAYS_LINK_PIC_LIBRARY.matches(path))
|| path.endsWith(".lo.lib");
return (OS.endsWith(path, ext) && !ALWAYS_LINK_PIC_LIBRARY.matches(path))
|| OS.endsWith(path, ".lo.lib");
}

@Override
Expand All @@ -155,7 +157,7 @@ public ImmutableList<String> getExtensions() {

@Override
public boolean apply(String path) {
return (path.endsWith(ext) && !PIC_OBJECT_FILE.matches(path)) || path.endsWith(".obj");
return (OS.endsWith(path, ext) && !PIC_OBJECT_FILE.matches(path)) || OS.endsWith(path, ".obj");
}

@Override
Expand Down Expand Up @@ -220,7 +222,7 @@ public boolean apply(String path) {
// The current clang (clang-600.0.57) on Darwin doesn't support 'textual', so we can't
// have '.inc' files in the module map (since they're implictly textual).
// TODO(bazel-team): Use HEADERS file type once clang-700 is the base clang we support.
return artifact.getFilename().endsWith(".h");
return OS.endsWith(artifact.getFilename(), ".h");
}
};

Expand Down