Skip to content

Commit

Permalink
Ignore prebuilt apex_contributions in coverage builds
Browse files Browse the repository at this point in the history
This CL unsets the prebuilt contents of a selected apex_contribution
in coverage builds. The effect of this will be that mainline modules
will be built from source with the following in coverage builds
1. Instrumentation turned on
2. RELEASE_ACONFIG_VALUE_SETS for that release config

Test: Added a unit test
Test: lunch cf_x86_64_phone-next-userdebug && EMMA_INSTRUMENT=true m nothing (with ag/26298763)
Bug: 325666427
Change-Id: Ic4e1f0612072377261602842dfd303c064095035
  • Loading branch information
dasspandan committed Feb 26, 2024
1 parent 50bfc34 commit bffd7fb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions android/apex_contributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package android

import (
"strings"

"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
Expand Down Expand Up @@ -102,6 +104,15 @@ func (a *allApexContributions) SetPrebuiltSelectionInfoProvider(ctx BaseModuleCo
if InList(content, ctx.Config().BuildIgnoreApexContributionContents()) {
continue
}
// Coverage builds for TARGET_RELEASE=foo should always build from source,
// even if TARGET_RELEASE=foo uses prebuilt mainline modules.
// This is necessary because the checked-in prebuilts were generated with
// instrumentation turned off.
//
// Skip any prebuilt contents in coverage builds
if strings.HasPrefix(content, "prebuilt_") && (ctx.Config().JavaCoverageEnabled() || ctx.DeviceConfig().NativeCoverageEnabled()) {
continue
}
if !ctx.OtherModuleExists(content) && !ctx.Config().AllowMissingDependencies() {
ctx.ModuleErrorf("%s listed in apex_contributions %s does not exist\n", content, m.Name())
}
Expand Down
42 changes: 42 additions & 0 deletions android/prebuilt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,45 @@ func TestPrebuiltErrorCannotListBothSourceAndPrebuiltInContributions(t *testing.
}
`, selectMainlineModuleContritbutions)
}

// Test that apex_contributions of prebuilt modules are ignored in coverage builds
func TestSourceIsSelectedInCoverageBuilds(t *testing.T) {
prebuiltMainlineContributions := GroupFixturePreparers(
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
variables.BuildFlags = map[string]string{
"RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_prebuilt_apex_contributions",
}
}),
FixtureMergeEnv(map[string]string{
"EMMA_INSTRUMENT_FRAMEWORK": "true",
}),
)
bp := `
source {
name: "foo",
}
prebuilt {
name: "foo",
srcs: ["prebuilt_file"],
}
apex_contributions {
name: "my_prebuilt_apex_contributions",
api_domain: "my_mainline_module",
contents: [
"prebuilt_foo",
],
}
all_apex_contributions {
name: "all_apex_contributions",
}
`
ctx := GroupFixturePreparers(
PrepareForTestWithArchMutator,
PrepareForTestWithPrebuilts,
FixtureRegisterWithContext(registerTestPrebuiltModules),
prebuiltMainlineContributions).RunTestWithBp(t, bp)
source := ctx.ModuleForTests("foo", "android_common").Module()
AssertBoolEquals(t, "Source should be preferred in coverage builds", true, !source.IsHideFromMake())
prebuilt := ctx.ModuleForTests("prebuilt_foo", "android_common").Module()
AssertBoolEquals(t, "Prebuilt should not be preferred in coverage builds", false, !prebuilt.IsHideFromMake())
}

0 comments on commit bffd7fb

Please sign in to comment.