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
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
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/actions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/util:var_int",
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:ospathpolicy",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
"//src/main/java/com/google/devtools/build/skyframe",
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/cmdline/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:string",
"//src/main/java/com/google/devtools/build/lib/vfs:ospathpolicy",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//third_party:auto_value",
"//third_party:caffeine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/util:string",
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:ospathpolicy",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
Expand Down
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
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ java_library(
deps = [
":string",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/vfs:ospathpolicy",
"//third_party:guava",
"//third_party:jsr305",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.vfs.OsPathPolicy;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.concurrent.Immutable;

/** A base class for FileType matchers. */
@Immutable
public abstract class FileType implements Predicate<String> {
private static final OsPathPolicy OS = OsPathPolicy.getFilePathOs();

// A special file type
@AutoCodec @VisibleForSerialization
public static final FileType NO_EXTENSION =
Expand Down Expand Up @@ -63,7 +67,7 @@ static final class SingletonFileType extends FileType {

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

@Override
Expand All @@ -86,7 +90,7 @@ static final class ListFileType extends FileType {
public boolean apply(String path) {
// Do not use an iterator based for loop here as that creates excessive garbage.
for (int i = 0; i < extensions.size(); i++) {
if (path.endsWith(extensions.get(i))) {
if (OS.endsWith(path, extensions.get(i))) {
return true;
}
}
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/com/google/devtools/build/lib/vfs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,42 @@ filegroup(
visibility = ["//src:__subpackages__"],
)

OS_PATH_POLICY_SOURCES = [
"OsPathPolicy.java",
"UnixOsPathPolicy.java",
"WindowsOsPathPolicy.java",
]

PATH_FRAGMENT_SOURCES = [
"PathFragment.java",
"PathFragmentSerializationProxy.java",
"PathSegmentIterator.java",
"OsPathPolicy.java",
"UnixOsPathPolicy.java",
"WindowsOsPathPolicy.java",
]

OUTPUT_SERVICE_SOURCES = [
"OutputService.java",
]

java_library(
name = "ospathpolicy",
srcs = OS_PATH_POLICY_SOURCES,
deps = [
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/windows:file",
"//src/main/java/com/google/devtools/build/lib/windows:windows_short_path",
"//third_party:guava",
],
)

java_library(
name = "pathfragment",
srcs = PATH_FRAGMENT_SOURCES,
deps = [
":ospathpolicy",
"//src/main/java/com/google/devtools/build/lib/actions:commandline_item",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant",
"//src/main/java/com/google/devtools/build/lib/util:filetype",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/windows:file",
"//src/main/java/com/google/devtools/build/lib/windows:windows_short_path",
"//third_party:error_prone_annotations",
"//third_party:guava",
"//third_party:jsr305",
Expand All @@ -45,7 +57,7 @@ java_library(
[
"*.java",
],
exclude = PATH_FRAGMENT_SOURCES + OUTPUT_SERVICE_SOURCES,
exclude = PATH_FRAGMENT_SOURCES + OUTPUT_SERVICE_SOURCES + OS_PATH_POLICY_SOURCES,
),
deps = [
":pathfragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:ospathpolicy",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//third_party:auto_value",
"//third_party:guava",
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/google/devtools/build/lib/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ java_test(
],
)

# Tests windows specific filetype handling on Unix.
java_library(
name = "FileTypeTests_lib",
srcs = ["FileTypeTest.java"],

deps = [
"//src/main/java/com/google/devtools/build/lib/util:filetype",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:guava",
"//third_party:junit4",
"//third_party:truth",
],
)

java_test(
name = "FileTypeWindowsTests",
size = "small",
jvm_flags = [
"-Dblaze.os=Windows",
"-Dbazel.windows_unix_root=C:/fake/msys",
],
test_class = "com.google.devtools.build.lib.AllTests",
runtime_deps = [
":FileTypeTests_lib",
"//src/test/java/com/google/devtools/build/lib:test_runner",
],
)

# Tests windows specific path handling on Unix.
java_library(
name = "UtilWindowsTests_lib",
Expand Down
Loading