From 1d619c2d0c46a9b8962707736f096d37e59bc10a Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Wed, 9 Sep 2015 17:32:25 +0000 Subject: [PATCH] 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 --- .../build/lib/rules/objc/CompilationSupport.java | 5 +---- .../build/lib/rules/objc/ObjcCommon.java | 6 ++++-- .../build/lib/rules/objc/ObjcRuleClasses.java | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) 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 9fa16756ab4bcc..05eaa4470296d1 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 @@ private void registerCompileAction( ImmutableList.Builder coverageFlags = new ImmutableList.Builder<>(); ImmutableList.Builder gcnoFiles = new ImmutableList.Builder<>(); ImmutableList.Builder 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 @@ private void registerCompileAction( 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 3a2ce46dd058d1..7c2c1d9a44a421 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 @@ GENERAL_RESOURCE_DIR, xcodeStructuredResourceDirs(attributes.structuredResources 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 7760a42dbf3ce8..ec8cf2eb015553 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 @@ public static ObjcConfiguration objcConfiguration(RuleContext ruleContext) { 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 AUTOMATIC_SDK_FRAMEWORKS = ImmutableList.of( new SdkFramework("Foundation"), new SdkFramework("UIKit")); @@ -318,9 +326,9 @@ public Metadata getMetadata() { */ 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 @@ public Metadata getMetadata() { * 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"));