Skip to content

Commit

Permalink
Remove expectation of clang in producing .gcno of assembly files for …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
c-parsons authored and damienmg committed Sep 11, 2015
1 parent 8fa0ddc commit 1d619c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,14 @@ private void registerCompileAction(
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));
}
CustomCommandLine.Builder commandLine = new CustomCommandLine.Builder();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SdkFramework> AUTOMATIC_SDK_FRAMEWORKS = ImmutableList.of(
new SdkFramework("Foundation"), new SdkFramework("UIKit"));
Expand Down Expand Up @@ -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");

Expand All @@ -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"));

Expand Down

0 comments on commit 1d619c2

Please sign in to comment.