aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java22
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java155
2 files changed, 96 insertions, 81 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index 4a97d11181..4f7bce06a0 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -381,7 +381,7 @@ public class CppCompileAction extends AbstractAction
// discarded as orphans.
// This is strictly better than marking all transitive modules as inputs, which would also
// effectively disable orphan detection for .pcm files.
- if (CppFileTypes.CPP_MODULE.matches(outputFile.getFilename())) {
+ if (outputFile.isFileType(CppFileTypes.CPP_MODULE)) {
return ImmutableSet.of(outputFile);
}
return super.getMandatoryOutputs();
@@ -447,7 +447,7 @@ public class CppCompileAction extends AbstractAction
if (shouldPruneModules) {
Set<Artifact> initialResultSet = Sets.newLinkedHashSet(initialResult);
- if (CppFileTypes.CPP_MODULE.matches(sourceFile.getFilename())) {
+ if (sourceFile.isFileType(CppFileTypes.CPP_MODULE)) {
usedModules = ImmutableSet.of(sourceFile);
initialResultSet.add(sourceFile);
} else {
@@ -485,7 +485,7 @@ public class CppCompileAction extends AbstractAction
value, "Owner %s of %s not in graph %s", artifact.getArtifactOwner(), artifact, skyKey);
// We can get the generating action here because #canRemoveAfterExecution is overridden.
Preconditions.checkState(
- CppFileTypes.CPP_MODULE.matches(artifact.getFilename()),
+ artifact.isFileType(CppFileTypes.CPP_MODULE),
"Non-module? %s (%s %s)",
artifact,
this,
@@ -493,7 +493,7 @@ public class CppCompileAction extends AbstractAction
CppCompileAction action =
(CppCompileAction) value.getGeneratingActionDangerousReadJavadoc(artifact);
for (Artifact input : action.getInputs()) {
- if (CppFileTypes.CPP_MODULE.matches(input.getFilename())) {
+ if (input.isFileType(CppFileTypes.CPP_MODULE)) {
additionalModules.add(input);
}
}
@@ -631,7 +631,7 @@ public class CppCompileAction extends AbstractAction
@Override
public Artifact getMainIncludeScannerSource() {
- return CppFileTypes.CPP_MODULE_MAP.matches(getSourceFile().getPath())
+ return getSourceFile().isFileType(CppFileTypes.CPP_MODULE_MAP)
? Iterables.getFirst(context.getHeaderModuleSrcs(), null)
: getSourceFile();
}
@@ -639,7 +639,7 @@ public class CppCompileAction extends AbstractAction
@Override
public Collection<Artifact> getIncludeScannerSources() {
NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder();
- if (CppFileTypes.CPP_MODULE_MAP.matches(getSourceFile().getPath())) {
+ if (getSourceFile().isFileType(CppFileTypes.CPP_MODULE_MAP)) {
// If this is an action that compiles the header module itself, the source we build is the
// module map, and we need to include-scan all headers that are referenced in the module map.
// We need to do include scanning as long as we want to support building code bases that are
@@ -702,7 +702,7 @@ public class CppCompileAction extends AbstractAction
public boolean canRemoveAfterExecution() {
// Module-generating actions are needed because the action may be retrieved in
// #discoverInputsStage2.
- return !CppFileTypes.CPP_MODULE.matches(getPrimaryOutput().getFilename());
+ return !getPrimaryOutput().isFileType(CppFileTypes.CPP_MODULE);
}
@Override
@@ -962,7 +962,7 @@ public class CppCompileAction extends AbstractAction
Iterable<Artifact> potentialModules) {
ImmutableList.Builder<String> usedModulePaths = ImmutableList.builder();
for (Artifact input : potentialModules) {
- if (CppFileTypes.CPP_MODULE.matches(input.getFilename())) {
+ if (input.isFileType(CppFileTypes.CPP_MODULE)) {
usedModulePaths.add(input.getExecPathString());
}
}
@@ -1242,7 +1242,7 @@ public class CppCompileAction extends AbstractAction
*/
private void ensureCoverageNotesFilesExist() throws ActionExecutionException {
for (Artifact output : getOutputs()) {
- if (CppFileTypes.COVERAGE_NOTES.matches(output.getFilename()) // ".gcno"
+ if (output.isFileType(CppFileTypes.COVERAGE_NOTES) // ".gcno"
&& !output.getPath().exists()) {
try {
FileSystemUtils.createEmptyFile(output.getPath());
@@ -1281,8 +1281,8 @@ public class CppCompileAction extends AbstractAction
@Override
public String getMnemonic() {
- if (CppFileTypes.OBJC_SOURCE.matches(sourceFile.getExecPath())
- || CppFileTypes.OBJCPP_SOURCE.matches(sourceFile.getExecPath())) {
+ if (sourceFile.isFileType(CppFileTypes.OBJC_SOURCE)
+ || sourceFile.isFileType(CppFileTypes.OBJCPP_SOURCE)) {
return "ObjcCompile";
} else {
return "CppCompile";
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java
index c63f7d8e00..0c7fa7d795 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java
@@ -42,44 +42,52 @@ public final class CppFileTypes {
public static final FileType CPP_TEXTUAL_INCLUDE = FileType.of(".inc");
public static final FileType PIC_PREPROCESSED_C = FileType.of(".pic.i");
- public static final FileType PREPROCESSED_C = new FileType() {
- final String ext = ".i";
- @Override
- public boolean apply(String filename) {
- return filename.endsWith(ext) && !PIC_PREPROCESSED_C.matches(filename);
- }
- @Override
- public List<String> getExtensions() {
- return ImmutableList.of(ext);
- }
- };
+ public static final FileType PREPROCESSED_C =
+ new FileType() {
+ final String ext = ".i";
+
+ @Override
+ public boolean apply(String path) {
+ return path.endsWith(ext) && !PIC_PREPROCESSED_C.matches(path);
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ return ImmutableList.of(ext);
+ }
+ };
public static final FileType PIC_PREPROCESSED_CPP = FileType.of(".pic.ii");
- public static final FileType PREPROCESSED_CPP = new FileType() {
- final String ext = ".ii";
- @Override
- public boolean apply(String filename) {
- return filename.endsWith(ext) && !PIC_PREPROCESSED_CPP.matches(filename);
- }
- @Override
- public List<String> getExtensions() {
- return ImmutableList.of(ext);
- }
- };
+ public static final FileType PREPROCESSED_CPP =
+ new FileType() {
+ final String ext = ".ii";
+
+ @Override
+ public boolean apply(String path) {
+ return path.endsWith(ext) && !PIC_PREPROCESSED_CPP.matches(path);
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ return ImmutableList.of(ext);
+ }
+ };
public static final FileType ASSEMBLER_WITH_C_PREPROCESSOR = FileType.of(".S");
public static final FileType PIC_ASSEMBLER = FileType.of(".pic.s");
- public static final FileType ASSEMBLER = new FileType() {
- final String ext = ".s";
- @Override
- public boolean apply(String filename) {
- return (filename.endsWith(ext) && !PIC_ASSEMBLER.matches(filename))
- || filename.endsWith(".asm");
- }
- @Override
- public List<String> getExtensions() {
- return ImmutableList.of(ext, ".asm");
- }
- };
+ public static final FileType ASSEMBLER =
+ new FileType() {
+ final String ext = ".s";
+
+ @Override
+ public boolean apply(String path) {
+ return (path.endsWith(ext) && !PIC_ASSEMBLER.matches(path)) || path.endsWith(".asm");
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ return ImmutableList.of(ext, ".asm");
+ }
+ };
public static final FileType PIC_ARCHIVE = FileType.of(".pic.a");
public static final FileType ARCHIVE =
@@ -87,9 +95,9 @@ public final class CppFileTypes {
final List<String> extensions = ImmutableList.of(".a", ".lib");
@Override
- public boolean apply(String filename) {
+ public boolean apply(String path) {
for (String ext : extensions) {
- if (filename.endsWith(ext) && !PIC_ARCHIVE.matches(filename)) {
+ if (path.endsWith(ext) && !PIC_ARCHIVE.matches(path)) {
return true;
}
}
@@ -103,30 +111,36 @@ public final class CppFileTypes {
};
public static final FileType ALWAYS_LINK_PIC_LIBRARY = FileType.of(".pic.lo");
- public static final FileType ALWAYS_LINK_LIBRARY = new FileType() {
- final String ext = ".lo";
- @Override
- public boolean apply(String filename) {
- return filename.endsWith(ext) && !ALWAYS_LINK_PIC_LIBRARY.matches(filename);
- }
- @Override
- public List<String> getExtensions() {
- return ImmutableList.of(ext);
- }
- };
+ public static final FileType ALWAYS_LINK_LIBRARY =
+ new FileType() {
+ final String ext = ".lo";
+
+ @Override
+ public boolean apply(String path) {
+ return path.endsWith(ext) && !ALWAYS_LINK_PIC_LIBRARY.matches(path);
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ return ImmutableList.of(ext);
+ }
+ };
public static final FileType PIC_OBJECT_FILE = FileType.of(".pic.o");
- public static final FileType OBJECT_FILE = new FileType() {
- final String ext = ".o";
- @Override
- public boolean apply(String filename) {
- return filename.endsWith(ext) && !PIC_OBJECT_FILE.matches(filename);
- }
- @Override
- public List<String> getExtensions() {
- return ImmutableList.of(ext);
- }
- };
+ public static final FileType OBJECT_FILE =
+ new FileType() {
+ final String ext = ".o";
+
+ @Override
+ public boolean apply(String path) {
+ return path.endsWith(ext) && !PIC_OBJECT_FILE.matches(path);
+ }
+
+ @Override
+ public List<String> getExtensions() {
+ return ImmutableList.of(ext);
+ }
+ };
// Minimized bitcode file emitted by the ThinLTO compile step and used just for LTO indexing.
public static final FileType LTO_INDEXING_OBJECT_FILE = FileType.of(".indexing.o");
@@ -144,19 +158,20 @@ public final class CppFileTypes {
// libmylib.so.2 or libmylib.so.2.10.
private static final Pattern VERSIONED_SHARED_LIBRARY_PATTERN =
Pattern.compile("^.+\\.so(\\.\\d+)+$");
- public static final FileType VERSIONED_SHARED_LIBRARY = new FileType() {
- @Override
- public boolean apply(String filename) {
- // Because regex matching can be slow, we first do a quick digit check on the final
- // character before risking the full-on regex match. This should eliminate the performance
- // hit on practically every non-qualifying file type.
- if (Character.isDigit(filename.charAt(filename.length() - 1))) {
- return VERSIONED_SHARED_LIBRARY_PATTERN.matcher(filename).matches();
- } else {
- return false;
+ public static final FileType VERSIONED_SHARED_LIBRARY =
+ new FileType() {
+ @Override
+ public boolean apply(String path) {
+ // Because regex matching can be slow, we first do a quick digit check on the final
+ // character before risking the full-on regex match. This should eliminate the performance
+ // hit on practically every non-qualifying file type.
+ if (Character.isDigit(path.charAt(path.length() - 1))) {
+ return VERSIONED_SHARED_LIBRARY_PATTERN.matcher(path).matches();
+ } else {
+ return false;
+ }
}
- }
- };
+ };
public static final FileType COVERAGE_NOTES = FileType.of(".gcno");
public static final FileType COVERAGE_DATA = FileType.of(".gcda");