From 02880e41963fdc799c6b202da41d15be224a5602 Mon Sep 17 00:00:00 2001 From: Logan Chien Date: Tue, 6 Nov 2018 17:30:35 +0800 Subject: [PATCH] Add missing dependencies for python_test This commit adds missing shared lib dependencies for `python_test` modules with embedded launcher. Bug: 119086738 Test: CHECK_ELF_FIELS=true make check-elf-files Change-Id: I26f8e1eb9086930093f60c7daa54469850fab32d --- python/androidmk.go | 1 + python/installer.go | 6 +++++ python/python.go | 54 +++++++++++++++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/python/androidmk.go b/python/androidmk.go index c1eaa5ebe..1e51e7b8a 100644 --- a/python/androidmk.go +++ b/python/androidmk.go @@ -96,5 +96,6 @@ func (installer *pythonInstaller) AndroidMk(base *Module, ret *android.AndroidMk fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file)) fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) + fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(installer.androidMkSharedLibs, " ")) }) } diff --git a/python/installer.go b/python/installer.go index ab3d9b4af..62f36f4b5 100644 --- a/python/installer.go +++ b/python/installer.go @@ -34,6 +34,8 @@ type pythonInstaller struct { relative string path android.OutputPath + + androidMkSharedLibs []string } func NewPythonInstaller(dir, dir64 string) *pythonInstaller { @@ -59,3 +61,7 @@ func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android. func (installer *pythonInstaller) install(ctx android.ModuleContext, file android.Path) { installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file) } + +func (installer *pythonInstaller) setAndroidMkSharedLibs(sharedLibs []string) { + installer.androidMkSharedLibs = sharedLibs +} diff --git a/python/python.go b/python/python.go index e8b47131b..ddc3f1f93 100644 --- a/python/python.go +++ b/python/python.go @@ -160,6 +160,7 @@ type bootstrapper interface { type installer interface { install(ctx android.ModuleContext, path android.Path) + setAndroidMkSharedLibs(sharedLibs []string) } type PythonDependency interface { @@ -203,18 +204,19 @@ type dependencyTag struct { } var ( - pythonLibTag = dependencyTag{name: "pythonLib"} - launcherTag = dependencyTag{name: "launcher"} - pyIdentifierRegexp = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`) - pyExt = ".py" - protoExt = ".proto" - pyVersion2 = "PY2" - pyVersion3 = "PY3" - initFileName = "__init__.py" - mainFileName = "__main__.py" - entryPointFile = "entry_point.txt" - parFileExt = ".zip" - internal = "internal" + pythonLibTag = dependencyTag{name: "pythonLib"} + launcherTag = dependencyTag{name: "launcher"} + launcherSharedLibTag = dependencyTag{name: "launcherSharedLib"} + pyIdentifierRegexp = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_-]*$`) + pyExt = ".py" + protoExt = ".proto" + pyVersion2 = "PY2" + pyVersion3 = "PY3" + initFileName = "__init__.py" + mainFileName = "__main__.py" + entryPointFile = "entry_point.txt" + parFileExt = ".zip" + internal = "internal" ) // create version variants for modules. @@ -308,6 +310,20 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddFarVariationDependencies([]blueprint.Variation{ {Mutator: "arch", Variation: ctx.Target().String()}, }, launcherTag, "py2-launcher") + + // Add py2-launcher shared lib dependencies. Ideally, these should be + // derived from the `shared_libs` property of "py2-launcher". However, we + // cannot read the property at this stage and it will be too late to add + // dependencies later. + ctx.AddFarVariationDependencies([]blueprint.Variation{ + {Mutator: "arch", Variation: ctx.Target().String()}, + }, launcherSharedLibTag, "libsqlite") + + if ctx.Target().Os.Bionic() { + ctx.AddFarVariationDependencies([]blueprint.Variation{ + {Mutator: "arch", Variation: ctx.Target().String()}, + }, launcherSharedLibTag, "libc", "libdl", "libm") + } } case pyVersion3: @@ -374,8 +390,18 @@ func (p *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { embeddedLauncher, p.srcsPathMappings, p.srcsZip, p.depsSrcsZips) } - if p.installer != nil && p.installSource.Valid() { - p.installer.install(ctx, p.installSource.Path()) + if p.installer != nil { + var sharedLibs []string + ctx.VisitDirectDeps(func(dep android.Module) { + if ctx.OtherModuleDependencyTag(dep) == launcherSharedLibTag { + sharedLibs = append(sharedLibs, ctx.OtherModuleName(dep)) + } + }) + p.installer.setAndroidMkSharedLibs(sharedLibs) + + if p.installSource.Valid() { + p.installer.install(ctx, p.installSource.Path()) + } } }