Use BaseModuleName() + SubName as apexFile.moduleName
This change fixes this error: ``` TARGET module com.android.adbd.flattened requires non-existent TARGET module: prebuilt_libclang_rt.ubsan_standalone-arm-android ``` apexFile.moduleName is used as Make dependency name, so it should use m.BaseModuleName() instead of m.Name(), because soong may prepend "prebuilt_" to or mutate the output of m.Name() in other ways. android/androidmk.go emits Android.mk modules with `LOCAL_MODULE := module.BaseModuleName() + <SubName>`, so replace apexFile.moduleName with BaseModuleName() + <SubName> as much as possible. Bug: 7456955 Test: Add unit test in apex/apex_test.go Test: lunch blueline_hwasan && SANITIZE_TARGET='hwaddress fuzzer' m nothing Test: Verify out/soong/Android-blueline_hwasan.mk Change-Id: If8537fc1bedbe6c3405de3662a5df210a073c43f
This commit is contained in:
@@ -82,9 +82,9 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
|
|||||||
|
|
||||||
var moduleName string
|
var moduleName string
|
||||||
if linkToSystemLib {
|
if linkToSystemLib {
|
||||||
moduleName = fi.moduleName
|
moduleName = fi.androidMkModuleName
|
||||||
} else {
|
} else {
|
||||||
moduleName = fi.moduleName + "." + apexBundleName + a.suffix
|
moduleName = fi.androidMkModuleName + "." + apexBundleName + a.suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
if !android.InList(moduleName, moduleNames) {
|
if !android.InList(moduleName, moduleNames) {
|
||||||
@@ -250,9 +250,9 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// m <module_name> will build <module_name>.<apex_name> as well.
|
// m <module_name> will build <module_name>.<apex_name> as well.
|
||||||
if fi.moduleName != moduleName && a.primaryApexType {
|
if fi.androidMkModuleName != moduleName && a.primaryApexType {
|
||||||
fmt.Fprintln(w, ".PHONY: "+fi.moduleName)
|
fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
|
||||||
fmt.Fprintln(w, fi.moduleName+": "+moduleName)
|
fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return moduleNames
|
return moduleNames
|
||||||
|
53
apex/apex.go
53
apex/apex.go
@@ -1136,7 +1136,9 @@ func (class apexFileClass) NameInMake() string {
|
|||||||
type apexFile struct {
|
type apexFile struct {
|
||||||
builtFile android.Path
|
builtFile android.Path
|
||||||
stem string
|
stem string
|
||||||
moduleName string
|
// Module name of `module` in AndroidMk. Note the generated AndroidMk module for
|
||||||
|
// apexFile is named something like <AndroidMk module name>.<apex name>[<apex suffix>]
|
||||||
|
androidMkModuleName string
|
||||||
installDir string
|
installDir string
|
||||||
class apexFileClass
|
class apexFileClass
|
||||||
module android.Module
|
module android.Module
|
||||||
@@ -1158,10 +1160,10 @@ type apexFile struct {
|
|||||||
isJniLib bool
|
isJniLib bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile {
|
func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidMkModuleName string, installDir string, class apexFileClass, module android.Module) apexFile {
|
||||||
ret := apexFile{
|
ret := apexFile{
|
||||||
builtFile: builtFile,
|
builtFile: builtFile,
|
||||||
moduleName: moduleName,
|
androidMkModuleName: androidMkModuleName,
|
||||||
installDir: installDir,
|
installDir: installDir,
|
||||||
class: class,
|
class: class,
|
||||||
module: module,
|
module: module,
|
||||||
@@ -1621,7 +1623,8 @@ func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, h
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileToCopy := ccMod.OutputFile().Path()
|
fileToCopy := ccMod.OutputFile().Path()
|
||||||
return newApexFile(ctx, fileToCopy, ccMod.Name(), dirInApex, nativeSharedLib, ccMod)
|
androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
|
||||||
|
return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
|
||||||
}
|
}
|
||||||
|
|
||||||
func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
|
func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFile {
|
||||||
@@ -1631,7 +1634,8 @@ func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFil
|
|||||||
}
|
}
|
||||||
dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
|
dirInApex = filepath.Join(dirInApex, cc.RelativeInstallPath())
|
||||||
fileToCopy := cc.OutputFile().Path()
|
fileToCopy := cc.OutputFile().Path()
|
||||||
af := newApexFile(ctx, fileToCopy, cc.Name(), dirInApex, nativeExecutable, cc)
|
androidMkModuleName := cc.BaseModuleName() + cc.Properties.SubName
|
||||||
|
af := newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeExecutable, cc)
|
||||||
af.symlinks = cc.Symlinks()
|
af.symlinks = cc.Symlinks()
|
||||||
af.dataPaths = cc.DataPaths()
|
af.dataPaths = cc.DataPaths()
|
||||||
return af
|
return af
|
||||||
@@ -1640,7 +1644,7 @@ func apexFileForExecutable(ctx android.BaseModuleContext, cc *cc.Module) apexFil
|
|||||||
func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
|
func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexFile {
|
||||||
dirInApex := "bin"
|
dirInApex := "bin"
|
||||||
fileToCopy := py.HostToolPath().Path()
|
fileToCopy := py.HostToolPath().Path()
|
||||||
return newApexFile(ctx, fileToCopy, py.Name(), dirInApex, pyBinary, py)
|
return newApexFile(ctx, fileToCopy, py.BaseModuleName(), dirInApex, pyBinary, py)
|
||||||
}
|
}
|
||||||
func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
|
func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
|
||||||
dirInApex := "bin"
|
dirInApex := "bin"
|
||||||
@@ -1659,12 +1663,14 @@ func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb boots
|
|||||||
func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
|
func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
|
||||||
dirInApex := filepath.Join("bin", sh.SubDir())
|
dirInApex := filepath.Join("bin", sh.SubDir())
|
||||||
fileToCopy := sh.OutputFile()
|
fileToCopy := sh.OutputFile()
|
||||||
af := newApexFile(ctx, fileToCopy, sh.Name(), dirInApex, shBinary, sh)
|
af := newApexFile(ctx, fileToCopy, sh.BaseModuleName(), dirInApex, shBinary, sh)
|
||||||
af.symlinks = sh.Symlinks()
|
af.symlinks = sh.Symlinks()
|
||||||
return af
|
return af
|
||||||
}
|
}
|
||||||
|
|
||||||
type javaDependency interface {
|
type javaModule interface {
|
||||||
|
android.Module
|
||||||
|
BaseModuleName() string
|
||||||
DexJarBuildPath() android.Path
|
DexJarBuildPath() android.Path
|
||||||
JacocoReportClassesFile() android.Path
|
JacocoReportClassesFile() android.Path
|
||||||
LintDepSets() java.LintDepSets
|
LintDepSets() java.LintDepSets
|
||||||
@@ -1672,20 +1678,18 @@ type javaDependency interface {
|
|||||||
Stem() string
|
Stem() string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ javaDependency = (*java.Library)(nil)
|
var _ javaModule = (*java.Library)(nil)
|
||||||
var _ javaDependency = (*java.SdkLibrary)(nil)
|
var _ javaModule = (*java.SdkLibrary)(nil)
|
||||||
var _ javaDependency = (*java.DexImport)(nil)
|
var _ javaModule = (*java.DexImport)(nil)
|
||||||
var _ javaDependency = (*java.SdkLibraryImport)(nil)
|
var _ javaModule = (*java.SdkLibraryImport)(nil)
|
||||||
|
|
||||||
func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile {
|
func apexFileForJavaLibrary(ctx android.BaseModuleContext, module javaModule) apexFile {
|
||||||
dirInApex := "javalib"
|
dirInApex := "javalib"
|
||||||
fileToCopy := lib.DexJarBuildPath()
|
fileToCopy := module.DexJarBuildPath()
|
||||||
// Remove prebuilt_ if necessary so the source and prebuilt modules have the same name.
|
af := newApexFile(ctx, fileToCopy, module.BaseModuleName(), dirInApex, javaSharedLib, module)
|
||||||
name := strings.TrimPrefix(module.Name(), "prebuilt_")
|
af.jacocoReportClassesFile = module.JacocoReportClassesFile()
|
||||||
af := newApexFile(ctx, fileToCopy, name, dirInApex, javaSharedLib, module)
|
af.lintDepSets = module.LintDepSets()
|
||||||
af.jacocoReportClassesFile = lib.JacocoReportClassesFile()
|
af.stem = module.Stem() + ".jar"
|
||||||
af.lintDepSets = lib.LintDepSets()
|
|
||||||
af.stem = lib.Stem() + ".jar"
|
|
||||||
return af
|
return af
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1708,6 +1712,7 @@ func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
|
|||||||
OutputFile() android.Path
|
OutputFile() android.Path
|
||||||
JacocoReportClassesFile() android.Path
|
JacocoReportClassesFile() android.Path
|
||||||
Certificate() java.Certificate
|
Certificate() java.Certificate
|
||||||
|
BaseModuleName() string
|
||||||
}) apexFile {
|
}) apexFile {
|
||||||
appDir := "app"
|
appDir := "app"
|
||||||
if aapp.Privileged() {
|
if aapp.Privileged() {
|
||||||
@@ -1715,7 +1720,7 @@ func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp interface {
|
|||||||
}
|
}
|
||||||
dirInApex := filepath.Join(appDir, aapp.InstallApkName())
|
dirInApex := filepath.Join(appDir, aapp.InstallApkName())
|
||||||
fileToCopy := aapp.OutputFile()
|
fileToCopy := aapp.OutputFile()
|
||||||
af := newApexFile(ctx, fileToCopy, aapp.Name(), dirInApex, app, aapp)
|
af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp)
|
||||||
af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
|
af.jacocoReportClassesFile = aapp.JacocoReportClassesFile()
|
||||||
af.certificate = aapp.Certificate()
|
af.certificate = aapp.Certificate()
|
||||||
|
|
||||||
@@ -2040,7 +2045,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
case javaLibTag:
|
case javaLibTag:
|
||||||
switch child.(type) {
|
switch child.(type) {
|
||||||
case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
|
case *java.Library, *java.SdkLibrary, *java.DexImport, *java.SdkLibraryImport:
|
||||||
af := apexFileForJavaLibrary(ctx, child.(javaDependency), child.(android.Module))
|
af := apexFileForJavaLibrary(ctx, child.(javaModule))
|
||||||
if !af.Ok() {
|
if !af.Ok() {
|
||||||
ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
|
ctx.PropertyErrorf("java_libs", "%q is not configured to be compiled into dex", depName)
|
||||||
return false
|
return false
|
||||||
@@ -2063,7 +2068,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
if ap.Privileged() {
|
if ap.Privileged() {
|
||||||
appDir = "priv-app"
|
appDir = "priv-app"
|
||||||
}
|
}
|
||||||
af := newApexFile(ctx, ap.OutputFile(), ap.Name(),
|
af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(),
|
||||||
filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
|
filepath.Join(appDir, ap.BaseModuleName()), appSet, ap)
|
||||||
af.certificate = java.PresignedCertificate
|
af.certificate = java.PresignedCertificate
|
||||||
filesInfo = append(filesInfo, af)
|
filesInfo = append(filesInfo, af)
|
||||||
@@ -2173,7 +2178,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
// use the name of the generated test binary (`fileToCopy`) instead of the name
|
// use the name of the generated test binary (`fileToCopy`) instead of the name
|
||||||
// of the original test module (`depName`, shared by all `test_per_src`
|
// of the original test module (`depName`, shared by all `test_per_src`
|
||||||
// variations of that module).
|
// variations of that module).
|
||||||
af.moduleName = filepath.Base(af.builtFile.String())
|
af.androidMkModuleName = filepath.Base(af.builtFile.String())
|
||||||
// these are not considered transitive dep
|
// these are not considered transitive dep
|
||||||
af.transitiveDep = false
|
af.transitiveDep = false
|
||||||
filesInfo = append(filesInfo, af)
|
filesInfo = append(filesInfo, af)
|
||||||
|
@@ -5179,6 +5179,57 @@ func TestSymlinksFromApexToSystem(t *testing.T) {
|
|||||||
ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
|
ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) {
|
||||||
|
ctx, config := testApex(t, `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
key: "myapex.key",
|
||||||
|
native_shared_libs: ["mylib"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "mylib",
|
||||||
|
srcs: ["mylib.cpp"],
|
||||||
|
shared_libs: ["myotherlib"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
apex_available: [
|
||||||
|
"myapex",
|
||||||
|
"//apex_available:platform",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_prebuilt_library_shared {
|
||||||
|
name: "myotherlib",
|
||||||
|
srcs: ["prebuilt.so"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
apex_available: [
|
||||||
|
"myapex",
|
||||||
|
"//apex_available:platform",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
|
||||||
|
data := android.AndroidMkDataForTest(t, config, "", apexBundle)
|
||||||
|
var builder strings.Builder
|
||||||
|
data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data)
|
||||||
|
androidMk := builder.String()
|
||||||
|
// `myotherlib` is added to `myapex` as symlink
|
||||||
|
ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
|
||||||
|
ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n")
|
||||||
|
ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n")
|
||||||
|
// `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib`
|
||||||
|
ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex myotherlib apex_manifest.pb.myapex apex_pubkey.myapex\n")
|
||||||
|
}
|
||||||
|
|
||||||
func TestApexWithJniLibs(t *testing.T) {
|
func TestApexWithJniLibs(t *testing.T) {
|
||||||
ctx, _ := testApex(t, `
|
ctx, _ := testApex(t, `
|
||||||
apex {
|
apex {
|
||||||
|
Reference in New Issue
Block a user