summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/binary.go2
-rw-r--r--python/python.go11
-rw-r--r--python/python_test.go73
-rw-r--r--python/test.go4
4 files changed, 86 insertions, 4 deletions
diff --git a/python/binary.go b/python/binary.go
index d6750c655..c84eeeedb 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -203,7 +203,7 @@ func (p *PythonBinaryModule) OutputFiles(tag string) (android.Paths, error) {
}
func (p *PythonBinaryModule) isEmbeddedLauncherEnabled() bool {
- return Bool(p.properties.Embedded_launcher)
+ return BoolDefault(p.properties.Embedded_launcher, true)
}
func (b *PythonBinaryModule) autorun() bool {
diff --git a/python/python.go b/python/python.go
index 2b1974eb8..e14fdf333 100644
--- a/python/python.go
+++ b/python/python.go
@@ -59,7 +59,7 @@ type VersionProperties struct {
// list of the Python libraries used only for this Python version.
Libs []string `android:"arch_variant"`
- // whether the binary is required to be built with embedded launcher for this version, defaults to false.
+ // whether the binary is required to be built with embedded launcher for this version, defaults to true.
Embedded_launcher *bool // TODO(b/174041232): Remove this property
}
@@ -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)
diff --git a/python/python_test.go b/python/python_test.go
index 75a6a899b..c0b7295f9 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -18,10 +18,13 @@ import (
"fmt"
"os"
"path/filepath"
+ "strings"
"testing"
"android/soong/android"
"android/soong/cc"
+
+ "github.com/google/blueprint"
)
type pyModule struct {
@@ -360,6 +363,76 @@ cc_binary {
}
}
+func TestTestOnlyProvider(t *testing.T) {
+ t.Parallel()
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithPythonBuildComponents,
+ android.PrepareForTestWithAllowMissingDependencies,
+ ).RunTestWithBp(t, `
+ // These should be test-only
+ python_library { name: "py-lib-test", test_only: true }
+ python_library { name: "py-lib-test-host", test_only: true, host_supported: true }
+ python_test { name: "py-test", srcs: ["py-test.py"] }
+ python_test_host { name: "py-test-host", srcs: ["py-test-host.py"] }
+ python_binary_host { name: "py-bin-test", srcs: ["py-bin-test.py"] }
+
+ // These should not be.
+ python_library { name: "py-lib" }
+ python_binary_host { name: "py-bin", srcs: ["py-bin.py"] }
+ `)
+
+ // Visit all modules and ensure only the ones that should
+ // marked as test-only are marked as test-only.
+
+ actualTestOnly := []string{}
+ ctx.VisitAllModules(func(m blueprint.Module) {
+ if provider, ok := android.OtherModuleProvider(ctx.TestContext.OtherModuleProviderAdaptor(), m, android.TestOnlyProviderKey); ok {
+ if provider.TestOnly {
+ actualTestOnly = append(actualTestOnly, m.Name())
+ }
+ }
+ })
+ expectedTestOnlyModules := []string{
+ "py-lib-test",
+ "py-lib-test-host",
+ "py-test",
+ "py-test-host",
+ }
+
+ notEqual, left, right := android.ListSetDifference(expectedTestOnlyModules, actualTestOnly)
+ if notEqual {
+ t.Errorf("test-only: Expected but not found: %v, Found but not expected: %v", left, right)
+ }
+}
+
+// Don't allow setting test-only on things that are always tests or never tests.
+func TestInvalidTestOnlyTargets(t *testing.T) {
+ testCases := []string{
+ ` python_test { name: "py-test", test_only: true, srcs: ["py-test.py"] } `,
+ ` python_test_host { name: "py-test-host", test_only: true, srcs: ["py-test-host.py"] } `,
+ ` python_defaults { name: "py-defaults", test_only: true, srcs: ["foo.py"] } `,
+ }
+
+ for i, bp := range testCases {
+ ctx := android.GroupFixturePreparers(
+ PrepareForTestWithPythonBuildComponents,
+ android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
+
+ ctx.RegisterModuleType("python_defaults", DefaultsFactory)
+ }),
+ android.PrepareForTestWithAllowMissingDependencies).
+ ExtendWithErrorHandler(android.FixtureIgnoreErrors).
+ RunTestWithBp(t, bp)
+ if len(ctx.Errs) != 1 {
+ t.Errorf("Expected err setting test_only in testcase #%d: %d errs", i, len(ctx.Errs))
+ continue
+ }
+ if !strings.Contains(ctx.Errs[0].Error(), "unrecognized property \"test_only\"") {
+ t.Errorf("ERR: %s bad bp: %s", ctx.Errs[0], bp)
+ }
+ }
+}
+
func expectModule(t *testing.T, ctx *android.TestContext, name, variant, expectedSrcsZip string, expectedPyRunfiles []string) {
module := ctx.ModuleForTests(name, variant)
diff --git a/python/test.go b/python/test.go
index 826f35358..2b939e7e4 100644
--- a/python/test.go
+++ b/python/test.go
@@ -36,7 +36,9 @@ func registerPythonTestComponents(ctx android.RegistrationContext) {
}
func NewTest(hod android.HostOrDeviceSupported) *PythonTestModule {
- return &PythonTestModule{PythonBinaryModule: *NewBinary(hod)}
+ p := &PythonTestModule{PythonBinaryModule: *NewBinary(hod)}
+ p.sourceProperties = android.SourceProperties{Test_only: proptools.BoolPtr(true), Top_level_test_target: true}
+ return p
}
func PythonTestHostFactory() android.Module {