Change Python in Soong to support device side build.
Add python_test to generate executables for both host and device side. And change python_library_host to python_library. installation for python device test will be under target/product/generic_arm[64]/data/nativetest[64]. Bug: b/69114465 Test: m clean && m -j Device Test: adb root; adb push nan_devicetest /data; adb shell; ./nan_devicetest print(sys.path) ['/data/nan_devicetest/runfiles', '/data/nan_devicetest', '/data/nan_devicetest/internal', '/data/nan_devicetest/internal/stdlib'] Change-Id: If8317070a3aa1b6dab2e84b8df2d037f495d7247
This commit is contained in:
parent
e261615792
commit
3bba05962d
6 changed files with 58 additions and 17 deletions
|
@ -39,7 +39,7 @@ func (p *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
|
|||
}
|
||||
|
||||
func (p *Module) AndroidMk() android.AndroidMkData {
|
||||
ret := android.AndroidMkData{}
|
||||
ret := android.AndroidMkData{OutputFile: p.installSource}
|
||||
|
||||
p.subAndroidMk(&ret, p.installer)
|
||||
|
||||
|
@ -55,7 +55,7 @@ func (p *binaryDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
|
|||
strings.Join(p.binaryProperties.Test_suites, " "))
|
||||
}
|
||||
})
|
||||
base.subAndroidMk(ret, p.baseInstaller)
|
||||
base.subAndroidMk(ret, p.pythonInstaller)
|
||||
}
|
||||
|
||||
func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
|
||||
|
@ -67,7 +67,7 @@ func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
|
|||
strings.Join(p.binaryDecorator.binaryProperties.Test_suites, " "))
|
||||
}
|
||||
})
|
||||
base.subAndroidMk(ret, p.binaryDecorator.baseInstaller)
|
||||
base.subAndroidMk(ret, p.binaryDecorator.pythonInstaller)
|
||||
}
|
||||
|
||||
func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMkData) {
|
||||
|
|
|
@ -49,24 +49,20 @@ type BinaryProperties struct {
|
|||
type binaryDecorator struct {
|
||||
binaryProperties BinaryProperties
|
||||
|
||||
baseInstaller *pythonInstaller
|
||||
*pythonInstaller
|
||||
}
|
||||
|
||||
type IntermPathProvider interface {
|
||||
IntermPathForModuleOut() android.OptionalPath
|
||||
}
|
||||
|
||||
func (binary *binaryDecorator) install(ctx android.ModuleContext, file android.Path) {
|
||||
binary.baseInstaller.install(ctx, file)
|
||||
}
|
||||
|
||||
var (
|
||||
stubTemplateHost = "build/soong/python/scripts/stub_template_host.txt"
|
||||
)
|
||||
|
||||
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
||||
module := newModule(hod, android.MultilibFirst)
|
||||
decorator := &binaryDecorator{baseInstaller: NewPythonInstaller("bin")}
|
||||
decorator := &binaryDecorator{pythonInstaller: NewPythonInstaller("bin", "")}
|
||||
|
||||
module.bootstrapper = decorator
|
||||
module.installer = decorator
|
||||
|
|
|
@ -15,26 +15,47 @@
|
|||
package python
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
// This file handles installing python executables into their final location
|
||||
|
||||
type installLocation int
|
||||
|
||||
const (
|
||||
InstallInData installLocation = iota
|
||||
)
|
||||
|
||||
type pythonInstaller struct {
|
||||
dir string
|
||||
dir string
|
||||
dir64 string
|
||||
relative string
|
||||
|
||||
path android.OutputPath
|
||||
}
|
||||
|
||||
func NewPythonInstaller(dir string) *pythonInstaller {
|
||||
func NewPythonInstaller(dir, dir64 string) *pythonInstaller {
|
||||
return &pythonInstaller{
|
||||
dir: dir,
|
||||
dir: dir,
|
||||
dir64: dir64,
|
||||
}
|
||||
}
|
||||
|
||||
var _ installer = (*pythonInstaller)(nil)
|
||||
|
||||
func (installer *pythonInstaller) install(ctx android.ModuleContext, file android.Path) {
|
||||
installer.path = ctx.InstallFile(android.PathForModuleInstall(ctx, installer.dir),
|
||||
file.Base(), file)
|
||||
func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.OutputPath {
|
||||
dir := installer.dir
|
||||
if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" {
|
||||
dir = installer.dir64
|
||||
}
|
||||
if !ctx.Host() && !ctx.Arch().Native {
|
||||
dir = filepath.Join(dir, ctx.Arch().ArchType.String())
|
||||
}
|
||||
return android.PathForModuleInstall(ctx, dir, installer.relative)
|
||||
}
|
||||
|
||||
func (installer *pythonInstaller) install(ctx android.ModuleContext, file android.Path) {
|
||||
installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
func init() {
|
||||
android.RegisterModuleType("python_library_host", PythonLibraryHostFactory)
|
||||
android.RegisterModuleType("python_library", PythonLibraryFactory)
|
||||
}
|
||||
|
||||
func PythonLibraryHostFactory() android.Module {
|
||||
|
@ -29,3 +30,9 @@ func PythonLibraryHostFactory() android.Module {
|
|||
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
func PythonLibraryFactory() android.Module {
|
||||
module := newModule(android.HostAndDeviceSupported, android.MultilibBoth)
|
||||
|
||||
return module.Init()
|
||||
}
|
||||
|
|
|
@ -558,5 +558,9 @@ func fillInMap(ctx android.ModuleContext, m map[string]string,
|
|||
return true
|
||||
}
|
||||
|
||||
func (p *Module) InstallInData() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var Bool = proptools.Bool
|
||||
var String = proptools.String
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
func init() {
|
||||
android.RegisterModuleType("python_test_host", PythonTestHostFactory)
|
||||
android.RegisterModuleType("python_test", PythonTestFactory)
|
||||
}
|
||||
|
||||
type testDecorator struct {
|
||||
|
@ -29,13 +30,18 @@ type testDecorator struct {
|
|||
}
|
||||
|
||||
func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) {
|
||||
test.binaryDecorator.baseInstaller.install(ctx, file)
|
||||
test.binaryDecorator.pythonInstaller.dir = "nativetest"
|
||||
test.binaryDecorator.pythonInstaller.dir64 = "nativetest64"
|
||||
|
||||
test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName()
|
||||
|
||||
test.binaryDecorator.pythonInstaller.install(ctx, file)
|
||||
}
|
||||
|
||||
func NewTest(hod android.HostOrDeviceSupported) *Module {
|
||||
module, binary := NewBinary(hod)
|
||||
|
||||
binary.baseInstaller = NewPythonInstaller("nativetest")
|
||||
binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64")
|
||||
|
||||
test := &testDecorator{binaryDecorator: binary}
|
||||
|
||||
|
@ -50,3 +56,10 @@ func PythonTestHostFactory() android.Module {
|
|||
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
func PythonTestFactory() android.Module {
|
||||
module := NewTest(android.HostAndDeviceSupported)
|
||||
module.multilib = android.MultilibBoth
|
||||
|
||||
return module.Init()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue