Skip to content

Commit

Permalink
Make cpp assembly file extensions case sensitive again (#15986)
Browse files Browse the repository at this point in the history
This fixes an issue introduced by PR #14005 where .s and .S
extensions were handled case-insensitive on Windows so the action
assemble was triggered instead of preprocess_assemble.

Closes #14131.

PiperOrigin-RevId: 412005097

Co-authored-by: Simon Bjorklen <simon.bjorklen@gmail.com>
  • Loading branch information
fmeum and Simon Bjorklen authored Jul 27, 2022
1 parent 04c373b commit a24d1bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,46 @@ public ImmutableList<String> getExtensions() {
}
};

public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = FileType.of(".S");
public static final FileType PIC_ASSEMBLER = FileType.of(".pic.s");
// FileType is extended to use case-sensitive comparison also on Windows
public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR =
new FileType() {
final String ext = ".S";

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

@Override
public ImmutableList<String> getExtensions() {
return ImmutableList.of(ext);
}
};

// FileType is extended to use case-sensitive comparison also on Windows
public static final FileType PIC_ASSEMBLER =
new FileType() {
final String ext = ".pic.s";

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

@Override
public ImmutableList<String> getExtensions() {
return ImmutableList.of(ext);
}
};

// FileType is extended to use case-sensitive comparison also on Windows
public static final FileType ASSEMBLER =
new FileType() {
final String ext = ".s";

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ public void testVersionedSharedLibraries() {
assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("libA.so.if.exp")).isFalse();
assertThat(CppFileTypes.VERSIONED_SHARED_LIBRARY.matches("libA.so.if.lib")).isFalse();
}

@Test
public void testCaseSensitiveAssemblyFiles() {
assertThat(CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches("foo.S")).isTrue();
assertThat(CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches("foo.s")).isFalse();
assertThat(CppFileTypes.PIC_ASSEMBLER.matches("foo.pic.s")).isTrue();
assertThat(CppFileTypes.PIC_ASSEMBLER.matches("foo.pic.S")).isFalse();
assertThat(CppFileTypes.ASSEMBLER.matches("foo.s")).isTrue();
assertThat(CppFileTypes.ASSEMBLER.matches("foo.asm")).isTrue();
assertThat(CppFileTypes.ASSEMBLER.matches("foo.pic.s")).isFalse();
assertThat(CppFileTypes.ASSEMBLER.matches("foo.S")).isFalse();
}
}

0 comments on commit a24d1bc

Please sign in to comment.