Remove expectation of clang in producing .gcno of assembly files for instrumentation/coverage purposes.
This is easier by grouping together all assembly files in a file set, thus justifying a simultaneous cleanup of the redundant usage of the assembler-with-cpp flag
--
MOS_MIGRATED_REVID=102671848
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 9fa1675..05eaa44 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -205,7 +205,7 @@
ImmutableList.Builder<String> coverageFlags = new ImmutableList.Builder<>();
ImmutableList.Builder<Artifact> gcnoFiles = new ImmutableList.Builder<>();
ImmutableList.Builder<Artifact> additionalInputs = new ImmutableList.Builder<>();
- if (isCodeCoverageEnabled) {
+ if (isCodeCoverageEnabled && ObjcRuleClasses.isInstrumentable(sourceFile)) {
coverageFlags.addAll(CLANG_COVERAGE_FLAGS);
gcnoFiles.add(intermediateArtifacts.gcnoFile(sourceFile));
}
@@ -213,9 +213,6 @@
if (ObjcRuleClasses.CPP_SOURCES.matches(sourceFile.getExecPath())) {
commandLine.add("-stdlib=libc++");
}
- if (ObjcRuleClasses.PREPROCESSED_ASSEMBLY_SOURCES.matches(sourceFile.getExecPath())) {
- commandLine.add("-x").add("assembler-with-cpp");
- }
if (compilationArtifacts.hasSwiftSources()) {
// Add the directory that contains merged TargetName-Swift.h header to search path, in case
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
index 3a2ce46..7c2c1d9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
@@ -461,8 +461,10 @@
if (configuration.isCodeCoverageEnabled()
&& filter.isIncluded(context.getLabel().toString())) {
for (Artifact source : allSources) {
- objcProvider.add(INSTRUMENTED_SOURCE, source);
- objcProvider.add(GCNO, intermediateArtifacts.gcnoFile(source));
+ if (ObjcRuleClasses.isInstrumentable(source)) {
+ objcProvider.add(INSTRUMENTED_SOURCE, source);
+ objcProvider.add(GCNO, intermediateArtifacts.gcnoFile(source));
+ }
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
index 7760a42..ec8cf2e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
@@ -142,6 +142,14 @@
return ruleContext.getFragment(ObjcConfiguration.class);
}
+ /**
+ * Returns true if the source file can be instrumented for coverage.
+ */
+ public static boolean isInstrumentable(Artifact sourceArtifact) {
+ return !ASSEMBLY_SOURCES.matches(sourceArtifact.getFilename());
+ }
+
+
@VisibleForTesting
static final Iterable<SdkFramework> AUTOMATIC_SDK_FRAMEWORKS = ImmutableList.of(
new SdkFramework("Foundation"), new SdkFramework("UIKit"));
@@ -318,9 +326,9 @@
*/
static final FileType CPP_SOURCES = FileType.of(".cc", ".cpp", ".mm", ".cxx", ".C");
- private static final FileType NON_CPP_SOURCES = FileType.of(".m", ".c", ".s", ".asm");
+ private static final FileType NON_CPP_SOURCES = FileType.of(".m", ".c");
- static final FileType PREPROCESSED_ASSEMBLY_SOURCES = FileType.of(".S");
+ static final FileType ASSEMBLY_SOURCES = FileType.of(".s", ".S", ".asm");
static final FileType SWIFT_SOURCES = FileType.of(".swift");
@@ -333,13 +341,13 @@
* Files allowed in the srcs attribute. This includes private headers.
*/
static final FileTypeSet SRCS_TYPE = FileTypeSet.of(NON_CPP_SOURCES, CPP_SOURCES,
- PREPROCESSED_ASSEMBLY_SOURCES, SWIFT_SOURCES, HEADERS);
+ ASSEMBLY_SOURCES, SWIFT_SOURCES, HEADERS);
/**
* Files that should actually be compiled.
*/
static final FileTypeSet COMPILABLE_SRCS_TYPE = FileTypeSet.of(NON_CPP_SOURCES, CPP_SOURCES,
- PREPROCESSED_ASSEMBLY_SOURCES, SWIFT_SOURCES);
+ ASSEMBLY_SOURCES, SWIFT_SOURCES);
static final FileTypeSet NON_ARC_SRCS_TYPE = FileTypeSet.of(FileType.of(".m", ".mm"));