Add limited target-specific configuration to apex.

Some apex targets need to be able to change their contents based on if
they are host or target or what libc they are using. This adds support
for doing this using the standard 'target: {...}' idiom.

Test: m com.android.runtime.host
Test: ./art/tools/build_linux_bionic.sh com.android.runtime.host
Bug: 123591866
Change-Id: If73bee650cdeb277c0e603763aa0b0108656bfdd
This commit is contained in:
Alex Light
2019-01-29 18:07:33 -08:00
parent 3b1746a212
commit 9670d332b6
2 changed files with 140 additions and 28 deletions

View File

@@ -177,6 +177,29 @@ func apexMutator(mctx android.BottomUpMutatorContext) {
}
}
type apexNativeDependencies struct {
// List of native libraries
Native_shared_libs []string
// List of native executables
Binaries []string
}
type apexMultilibProperties struct {
// Native dependencies whose compile_multilib is "first"
First apexNativeDependencies
// Native dependencies whose compile_multilib is "both"
Both apexNativeDependencies
// Native dependencies whose compile_multilib is "prefer32"
Prefer32 apexNativeDependencies
// Native dependencies whose compile_multilib is "32"
Lib32 apexNativeDependencies
// Native dependencies whose compile_multilib is "64"
Lib64 apexNativeDependencies
}
type apexBundleProperties struct {
// Json manifest file describing meta info of this APEX bundle. Default:
// "apex_manifest.json"
@@ -218,36 +241,26 @@ type apexBundleProperties struct {
// Default is false.
Use_vendor *bool
Multilib struct {
First struct {
// List of native libraries whose compile_multilib is "first"
Native_shared_libs []string
// List of native executables whose compile_multilib is "first"
Binaries []string
Multilib apexMultilibProperties
}
type apexTargetBundleProperties struct {
Target struct {
// Multilib properties only for android.
Android struct {
Multilib apexMultilibProperties
}
Both struct {
// List of native libraries whose compile_multilib is "both"
Native_shared_libs []string
// List of native executables whose compile_multilib is "both"
Binaries []string
// Multilib properties only for host.
Host struct {
Multilib apexMultilibProperties
}
Prefer32 struct {
// List of native libraries whose compile_multilib is "prefer32"
Native_shared_libs []string
// List of native executables whose compile_multilib is "prefer32"
Binaries []string
// Multilib properties only for host linux_bionic.
Linux_bionic struct {
Multilib apexMultilibProperties
}
Lib32 struct {
// List of native libraries whose compile_multilib is "32"
Native_shared_libs []string
// List of native executables whose compile_multilib is "32"
Binaries []string
}
Lib64 struct {
// List of native libraries whose compile_multilib is "64"
Native_shared_libs []string
// List of native executables whose compile_multilib is "64"
Binaries []string
// Multilib properties only for host linux_glibc.
Linux_glibc struct {
Multilib apexMultilibProperties
}
}
}
@@ -339,7 +352,8 @@ type apexBundle struct {
android.ModuleBase
android.DefaultableModuleBase
properties apexBundleProperties
properties apexBundleProperties
targetProperties apexTargetBundleProperties
apexTypes apexPackaging
@@ -372,9 +386,26 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
}, executableTag, binaries...)
}
func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
if ctx.Os().Class == android.Device {
proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Android.Multilib, nil)
} else {
proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Host.Multilib, nil)
if ctx.Os().Bionic() {
proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_bionic.Multilib, nil)
} else {
proptools.AppendProperties(&a.properties.Multilib, &a.targetProperties.Target.Linux_glibc.Multilib, nil)
}
}
}
func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
targets := ctx.MultiTargets()
config := ctx.DeviceConfig()
a.combineProperties(ctx)
has32BitTarget := false
for _, target := range targets {
if target.Arch.ArchType.Multilib == "lib32" {
@@ -1028,6 +1059,7 @@ func ApexBundleFactory() android.Module {
outputFiles: map[apexPackaging]android.WritablePath{},
}
module.AddProperties(&module.properties)
module.AddProperties(&module.targetProperties)
module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
return class == android.Device && ctx.Config().DevicePrefer32BitExecutables()
})

View File

@@ -864,3 +864,83 @@ func TestHeaderLibsDependency(t *testing.T) {
// Ensure that the include path of the header lib is exported to 'otherlib'
ensureContains(t, cFlags, "-Imy_include")
}
func TestApexWithTarget(t *testing.T) {
ctx := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
multilib: {
first: {
native_shared_libs: ["mylib_common"],
}
},
target: {
android: {
multilib: {
first: {
native_shared_libs: ["mylib"],
}
}
},
host: {
multilib: {
first: {
native_shared_libs: ["mylib2"],
}
}
}
}
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
cc_library {
name: "mylib",
srcs: ["mylib.cpp"],
system_shared_libs: [],
stl: "none",
}
cc_library {
name: "mylib_common",
srcs: ["mylib.cpp"],
system_shared_libs: [],
stl: "none",
compile_multilib: "first",
}
cc_library {
name: "mylib2",
srcs: ["mylib.cpp"],
system_shared_libs: [],
stl: "none",
compile_multilib: "first",
}
`)
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
copyCmds := apexRule.Args["copy_commands"]
// Ensure that main rule creates an output
ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
// Ensure that apex variant is created for the direct dep
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
// Ensure that both direct and indirect deps are copied into apex
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
// Ensure that the platform variant ends with _core_shared
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
}