From c4cd7a11a1410d6c9d9a8765194460822d0b51ff Mon Sep 17 00:00:00 2001 From: Ronald Braunstein Date: Tue, 16 Apr 2024 16:39:48 -0700 Subject: Implement test-only for python_ rules Similar to: aosp/3040036 and aosp/3035329, implements a test-only property for python_library and sets it for python_host. This combined with aosp/3045317 produces: gqui from "flatten(~/aosp-main-with-phones/out/soong/ownership/all_teams.pb, teams)" proto ~/aosp-main-with-phones/build/soong/android/team_proto/team.proto:AllTeams 'select teams.kind, count(*) total, sum(teams.test_only) as test_only, sum(teams.top_level_target) as top_level, where teams.kind like "%py%" group by teams.kind' +-----------------------------+-------+-----------+-----------+ | teams.kind | total | test_only | top_level | +-----------------------------+-------+-----------+-----------+ | cpython3_cc_defaults | 1 | 0 | 0 | | cpython3_cc_prebuilt_binary | 4 | 0 | 0 | | python_binary_host | 222 | 0 | 0 | | python_defaults | 27 | 0 | 0 | | python_library | 38 | 0 | 0 | | python_library_host | 131 | 0 | 0 | | python_test | 5 | 5 | 5 | | python_test_host | 172 | 172 | 172 | +-----------------------------+-------+-----------+-----------+ Change-Id: Iea14fcdbfd782d37ac0a3c780820deeed5f1923d Test: m blueprint_tests Test: go test ./python --- python/python.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'python/python.go') diff --git a/python/python.go b/python/python.go index 2b1974eb8..621e429b9 100644 --- a/python/python.go +++ b/python/python.go @@ -151,6 +151,8 @@ type PythonLibraryModule struct { // The zip file containing the current module's source/data files, with the // source files precompiled. precompiledSrcsZip android.Path + + sourceProperties android.SourceProperties } // newModule generates new Python base module @@ -203,7 +205,7 @@ func (p *PythonLibraryModule) getBaseProperties() *BaseProperties { var _ pythonDependency = (*PythonLibraryModule)(nil) func (p *PythonLibraryModule) init() android.Module { - p.AddProperties(&p.properties, &p.protoProperties) + p.AddProperties(&p.properties, &p.protoProperties, &p.sourceProperties) android.InitAndroidArchModule(p, p.hod, p.multilib) android.InitDefaultableModule(p) return p @@ -421,6 +423,11 @@ func (p *PythonLibraryModule) AddDepsOnPythonLauncherAndStdlib(ctx android.Botto func (p *PythonLibraryModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { expandedSrcs := android.PathsForModuleSrcExcludes(ctx, p.properties.Srcs, p.properties.Exclude_srcs) android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: expandedSrcs.Strings()}) + // Keep before any early returns. + android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{ + TestOnly: Bool(p.sourceProperties.Test_only), + TopLevelTarget: p.sourceProperties.Top_level_test_target, + }) // expand data files from "data" property. expandedData := android.PathsForModuleSrc(ctx, p.properties.Data) -- cgit v1.2.3-59-g8ed1b