From 74b1e2b88001378b8e2fa7aeeae8fd81e218a1ab Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Sun, 22 Nov 2020 20:23:02 -0800 Subject: [PATCH 1/3] Support SourceFileProducer in android.OutputFilesForModule Add support to android.OutputFilesForModule to get paths from a SourceFileProducer as well as an OutputFileProducer. Bug: 173977903 Test: m checkbuild Change-Id: I4b2ca2837342ddbb4210bee8f549a636d8b8b049 --- android/module.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/android/module.go b/android/module.go index 6b659d2cd..8be00b2a5 100644 --- a/android/module.go +++ b/android/module.go @@ -2578,6 +2578,15 @@ func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module)) } return paths, nil + } else if sourceFileProducer, ok := module.(SourceFileProducer); ok { + if tag != "" { + return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag) + } + paths := sourceFileProducer.Srcs() + if len(paths) == 0 { + return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module)) + } + return paths, nil } else { return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module)) } From e20113d8ab84d0965d10df00832bac94cbd396f3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Sun, 22 Nov 2020 19:37:44 -0800 Subject: [PATCH 2/3] Use local variations for python version splits Use a local variation for python version splits. This causes dependencies from python modules not to look for variations that match the version split, which will simplify a python module depending on a java module (for example for test data) because Soong won't look for a python version variant of the java module. Bug: 173977903 Test: go test ./python Change-Id: Ib034140c478ffbc7467ab830d3cfa5683c31d05c --- python/python.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/python/python.go b/python/python.go index e4c8e9481..770ea4d14 100644 --- a/python/python.go +++ b/python/python.go @@ -34,7 +34,7 @@ func init() { } func RegisterPythonPreDepsMutators(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("version_split", versionSplitMutator()).Parallel() + ctx.BottomUp("python_version", versionSplitMutator()).Parallel() } // the version properties that apply to python libraries and binaries. @@ -248,7 +248,7 @@ func versionSplitMutator() func(android.BottomUpMutatorContext) { versionNames = append(versionNames, pyVersion2) versionProps = append(versionProps, base.properties.Version.Py2) } - modules := mctx.CreateVariations(versionNames...) + modules := mctx.CreateLocalVariations(versionNames...) if len(versionNames) > 0 { mctx.AliasVariation(versionNames[0]) } @@ -306,16 +306,20 @@ func (p *Module) hasSrcExt(ctx android.BottomUpMutatorContext, ext string) bool func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { android.ProtoDeps(ctx, &p.protoProperties) - if p.hasSrcExt(ctx, protoExt) && p.Name() != "libprotobuf-python" { - ctx.AddVariationDependencies(nil, pythonLibTag, "libprotobuf-python") + versionVariation := []blueprint.Variation{ + {"python_version", p.properties.Actual_version}, } - ctx.AddVariationDependencies(nil, pythonLibTag, android.LastUniqueStrings(p.properties.Libs)...) + + if p.hasSrcExt(ctx, protoExt) && p.Name() != "libprotobuf-python" { + ctx.AddVariationDependencies(versionVariation, pythonLibTag, "libprotobuf-python") + } + ctx.AddVariationDependencies(versionVariation, pythonLibTag, android.LastUniqueStrings(p.properties.Libs)...) switch p.properties.Actual_version { case pyVersion2: if p.bootstrapper != nil && p.isEmbeddedLauncherEnabled() { - ctx.AddVariationDependencies(nil, pythonLibTag, "py2-stdlib") + ctx.AddVariationDependencies(versionVariation, pythonLibTag, "py2-stdlib") launcherModule := "py2-launcher" if p.bootstrapper.autorun() { @@ -338,7 +342,7 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { case pyVersion3: if p.bootstrapper != nil && p.isEmbeddedLauncherEnabled() { - ctx.AddVariationDependencies(nil, pythonLibTag, "py3-stdlib") + ctx.AddVariationDependencies(versionVariation, pythonLibTag, "py3-stdlib") launcherModule := "py3-launcher" if p.bootstrapper.autorun() { From 1bc63938f00284f4bee3fd6e713816a6e999dbfd Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Sun, 22 Nov 2020 20:12:45 -0800 Subject: [PATCH 3/3] Add java_data parameter to python modules csuite has a python module that wants to embed the outputs of java modules. This has caused issues with mismatched variants bewteen the arch-specific python module and the common java modules. Add a java_data property that is similar to the data property but uses the common arch variant. Bug: 173977903 Test: m checkbuild Change-Id: I0f2f0e4159650cd5d42b510d5177678e7ee91b4d --- python/python.go | 14 ++++++++++++++ python/test.go | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/python/python.go b/python/python.go index 770ea4d14..d7b1bbad4 100644 --- a/python/python.go +++ b/python/python.go @@ -86,6 +86,9 @@ type BaseProperties struct { // the test. the file extension can be arbitrary except for (.py). Data []string `android:"path,arch_variant"` + // list of java modules that provide data that should be installed alongside the test. + Java_data []string + // list of the Python libraries compatible both with Python2 and Python3. Libs []string `android:"arch_variant"` @@ -216,6 +219,7 @@ type dependencyTag struct { var ( pythonLibTag = dependencyTag{name: "pythonLib"} + javaDataTag = dependencyTag{name: "javaData"} launcherTag = dependencyTag{name: "launcher"} launcherSharedLibTag = dependencyTag{name: "launcherSharedLib"} pyIdentifierRegexp = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`) @@ -370,6 +374,11 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", p.properties.Actual_version, ctx.ModuleName())) } + + // Emulate the data property for java_data but with the arch variation overridden to "common" + // so that it can point to java modules. + javaDataVariation := []blueprint.Variation{{"arch", android.Common.String()}} + ctx.AddVariationDependencies(javaDataVariation, javaDataTag, p.properties.Java_data...) } func (p *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -416,6 +425,11 @@ func (p *Module) GeneratePythonBuildActions(ctx android.ModuleContext) { // expand data files from "data" property. expandedData := android.PathsForModuleSrc(ctx, p.properties.Data) + // Emulate the data property for java_data dependencies. + for _, javaData := range ctx.GetDirectDepsWithTag(javaDataTag) { + expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...) + } + // sanitize pkg_path. pkgPath := String(p.properties.Pkg_path) if pkgPath != "" { diff --git a/python/test.go b/python/test.go index f9baa465c..4df71c11b 100644 --- a/python/test.go +++ b/python/test.go @@ -45,6 +45,9 @@ type TestProperties struct { // the test Data []string `android:"path,arch_variant"` + // list of java modules that provide data that should be installed alongside the test. + Java_data []string + // Test options. Test_options TestOptions } @@ -80,6 +83,13 @@ func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) for _, dataSrcPath := range dataSrcPaths { test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath}) } + + // Emulate the data property for java_data dependencies. + for _, javaData := range ctx.GetDirectDepsWithTag(javaDataTag) { + for _, javaDataSrcPath := range android.OutputFilesForModule(ctx, javaData, "") { + test.data = append(test.data, android.DataPath{SrcPath: javaDataSrcPath}) + } + } } func NewTest(hod android.HostOrDeviceSupported) *Module {