Enable code coverage for cc shared library
Bug: None
Test: Manual and unit tests
Change-Id: I5064e4407d3451ff172ab203256f3c073cc0ad1b
diff --git a/cc/binary.go b/cc/binary.go
index 998934e..54c1abc 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -644,6 +644,8 @@
Features: baseAttrs.features,
sdkAttributes: bp2BuildParseSdkAttributes(m),
+
+ Native_coverage: baseAttrs.Native_coverage,
}
m.convertTidyAttributes(ctx, &attrs.tidyAttributes)
@@ -703,4 +705,6 @@
sdkAttributes
tidyAttributes
+
+ Native_coverage *bool
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 510ecee..66157ae 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -63,7 +63,7 @@
Enabled bazel.BoolAttribute
- Native_coverage bazel.BoolAttribute
+ Native_coverage *bool
sdkAttributes
@@ -358,6 +358,7 @@
features bazel.StringListAttribute
protoDependency *bazel.LabelAttribute
aidlDependency *bazel.LabelAttribute
+ Native_coverage *bool
}
// Convenience struct to hold all attributes parsed from compiler properties.
@@ -753,10 +754,10 @@
compilerAttrs.convertStlProps(ctx, module)
(&linkerAttrs).convertStripProps(ctx, module)
+ var nativeCoverage *bool
if module.coverage != nil && module.coverage.Properties.Native_coverage != nil &&
!Bool(module.coverage.Properties.Native_coverage) {
- // Native_coverage is arch neutral
- (&linkerAttrs).features.Append(bazel.MakeStringListAttribute([]string{"-coverage"}))
+ nativeCoverage = BoolPtr(false)
}
productVariableProps := android.ProductVariableProperties(ctx)
@@ -812,6 +813,7 @@
*features,
protoDep.protoDep,
aidlDep,
+ nativeCoverage,
}
}
diff --git a/cc/library.go b/cc/library.go
index ed0ed01..8afc2fe 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -351,6 +351,7 @@
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
Runtime_deps: linkerAttrs.runtimeDeps,
sdkAttributes: bp2BuildParseSdkAttributes(m),
+ Native_coverage: baseAttributes.Native_coverage,
}
sharedCommonAttrs := staticOrSharedAttributes{
@@ -369,6 +370,7 @@
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
Runtime_deps: linkerAttrs.runtimeDeps,
sdkAttributes: bp2BuildParseSdkAttributes(m),
+ Native_coverage: baseAttributes.Native_coverage,
}
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
@@ -2869,6 +2871,7 @@
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
sdkAttributes: bp2BuildParseSdkAttributes(module),
Runtime_deps: linkerAttrs.runtimeDeps,
+ Native_coverage: baseAttributes.Native_coverage,
}
module.convertTidyAttributes(ctx, &commonAttrs.tidyAttributes)
@@ -2956,6 +2959,13 @@
}
tags := android.ApexAvailableTags(module)
+
+ // This lib needs some special handling in bazel, so add this tag to the build
+ // file.
+ if module.Name() == "libprofile-clang-extras" {
+ tags.Append(bazel.MakeStringListAttribute([]string{"NO_EXPORTING"}))
+ }
+
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs)
}