Add test-only for test-per-src cc modules

When testing test-only validations, I noticed that some cc_test modules
where not reporting that they were test-only.

This happened because test-per-src variations were short-circuiting
writing out the provider.

The `all_teams` target is using the first variation for a module, but
it possibly should see if any variation is test-only.
For now, just making this fix to cc.

Test: m all_teams  && gqui from  "flatten(out/soong/ownership/all_teams.pb, teams)" proto build/soong/android/team_proto/team.proto:AllTeams ' where teams.kind = "cc_test" and teams.target_name="libnativebridge-tests"'
Test: go test ./cc
Change-Id: I6d44a521f5f2457527049399509d979559d7dc17
This commit is contained in:
Ronald Braunstein
2024-04-15 12:55:30 -07:00
parent 935b4db4cb
commit 6a08d4915a
2 changed files with 46 additions and 13 deletions

View File

@@ -1995,6 +1995,20 @@ func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
ctx := moduleContextFromAndroidModuleContext(actx, c)
// If Test_only is set on a module in bp file, respect the setting, otherwise
// see if is a known test module type.
testOnly := c.testModule || c.testLibrary()
if c.sourceProperties.Test_only != nil {
testOnly = Bool(c.sourceProperties.Test_only)
}
// Keep before any early returns.
android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
TestOnly: testOnly,
TopLevelTarget: c.testModule,
})
// Handle the case of a test module split by `test_per_src` mutator.
//
// The `test_per_src` mutator adds an extra variation named "", depending on all the other
@@ -2013,8 +2027,6 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
c.makeLinkType = GetMakeLinkType(actx, c)
ctx := moduleContextFromAndroidModuleContext(actx, c)
deps := c.depsToPaths(ctx)
if ctx.Failed() {
return
@@ -2141,17 +2153,6 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
// If Test_only is set on a module in bp file, respect the setting, otherwise
// see if is a known test module type.
testOnly := c.testModule || c.testLibrary()
if c.sourceProperties.Test_only != nil {
testOnly = Bool(c.sourceProperties.Test_only)
}
android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
TestOnly: testOnly,
TopLevelTarget: c.testModule,
})
android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: deps.GeneratedSources.Strings()})
android.CollectDependencyAconfigFiles(ctx, &c.mergedAconfigFiles)