Refactor python to use AndroidMkEntries.

This is to enable consolidating test compatibility suite handling in
Soong's AndroidMk files.

Test: go test soong tests
Test: m nothing and compare soong/Android mk files -- only diffs is that
      lines matching "^LOCAL_SHARED_LIBRARIES := $" are absent
Change-Id: I4922a1c8b0231cd98ebd2bc7257956eb9c0d240c
This commit is contained in:
Liz Kammer
2020-11-24 08:36:14 -08:00
parent 0dabd31057
commit d8dceb0f2d
2 changed files with 31 additions and 47 deletions

View File

@@ -15,8 +15,6 @@
package python package python
import ( import (
"fmt"
"io"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -24,86 +22,72 @@ import (
) )
type subAndroidMkProvider interface { type subAndroidMkProvider interface {
AndroidMk(*Module, *android.AndroidMkData) AndroidMk(*Module, *android.AndroidMkEntries)
} }
func (p *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) { func (p *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
if p.subAndroidMkOnce == nil { if p.subAndroidMkOnce == nil {
p.subAndroidMkOnce = make(map[subAndroidMkProvider]bool) p.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
} }
if androidmk, ok := obj.(subAndroidMkProvider); ok { if androidmk, ok := obj.(subAndroidMkProvider); ok {
if !p.subAndroidMkOnce[androidmk] { if !p.subAndroidMkOnce[androidmk] {
p.subAndroidMkOnce[androidmk] = true p.subAndroidMkOnce[androidmk] = true
androidmk.AndroidMk(p, data) androidmk.AndroidMk(p, entries)
} }
} }
} }
func (p *Module) AndroidMk() android.AndroidMkData { func (p *Module) AndroidMkEntries() []android.AndroidMkEntries {
ret := android.AndroidMkData{OutputFile: p.installSource} entries := android.AndroidMkEntries{OutputFile: p.installSource}
p.subAndroidMk(&ret, p.installer) p.subAndroidMk(&entries, p.installer)
return ret return []android.AndroidMkEntries{entries}
} }
func (p *binaryDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { func (p *binaryDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
ret.Class = "EXECUTABLES" entries.Class = "EXECUTABLES"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
if len(p.binaryProperties.Test_suites) > 0 { entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", p.binaryProperties.Test_suites...)
fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
strings.Join(p.binaryProperties.Test_suites, " "))
}
}) })
base.subAndroidMk(ret, p.pythonInstaller) base.subAndroidMk(entries, p.pythonInstaller)
} }
func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) { func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
ret.Class = "NATIVE_TESTS" entries.Class = "NATIVE_TESTS"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
if len(p.binaryDecorator.binaryProperties.Test_suites) > 0 { entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", p.binaryDecorator.binaryProperties.Test_suites...)
fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
strings.Join(p.binaryDecorator.binaryProperties.Test_suites, " "))
}
if p.testConfig != nil { if p.testConfig != nil {
fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", entries.SetString("LOCAL_FULL_TEST_CONFIG", p.testConfig.String())
p.testConfig.String())
} }
if !BoolDefault(p.binaryProperties.Auto_gen_config, true) { entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true))
fmt.Fprintln(w, "LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG := true")
}
if len(p.data) > 0 { entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...)
fmt.Fprintln(w, "LOCAL_TEST_DATA :=",
strings.Join(android.AndroidMkDataPaths(p.data), " "))
}
if Bool(p.testProperties.Test_options.Unit_test) { entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test))
fmt.Fprintln(w, "LOCAL_IS_UNIT_TEST := true")
}
}) })
base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller) base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller)
} }
func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMkData) { func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.AndroidMkEntries) {
// Soong installation is only supported for host modules. Have Make // Soong installation is only supported for host modules. Have Make
// installation trigger Soong installation. // installation trigger Soong installation.
if base.Target().Os.Class == android.Host { if base.Target().Os.Class == android.Host {
ret.OutputFile = android.OptionalPathForPath(installer.path) entries.OutputFile = android.OptionalPathForPath(installer.path)
} }
ret.Required = append(ret.Required, "libc++") entries.Required = append(entries.Required, "libc++")
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
path, file := filepath.Split(installer.path.ToMakePath().String()) path, file := filepath.Split(installer.path.ToMakePath().String())
stem := strings.TrimSuffix(file, filepath.Ext(file)) stem := strings.TrimSuffix(file, filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) entries.SetString("LOCAL_MODULE_SUFFIX", filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) entries.SetString("LOCAL_MODULE_PATH", path)
fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) entries.SetString("LOCAL_MODULE_STEM", stem)
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " ")) entries.AddStrings("LOCAL_SHARED_LIBRARIES", installer.androidMkSharedLibs...)
fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := false") entries.SetBool("LOCAL_CHECK_ELF_FILES", false)
}) })
} }

View File

@@ -194,7 +194,7 @@ func (p *Module) GetSrcsZip() android.Path {
var _ PythonDependency = (*Module)(nil) var _ PythonDependency = (*Module)(nil)
var _ android.AndroidMkDataProvider = (*Module)(nil) var _ android.AndroidMkEntriesProvider = (*Module)(nil)
func (p *Module) Init() android.Module { func (p *Module) Init() android.Module {