Merge changes from topic "libraries-txt-to-soong"

* changes:
  VNDK APEX contains related *.libraries.txt files
  Make vndk*.libraries.txt as soong modules
This commit is contained in:
Treehugger Robot 2019-11-08 04:04:14 +00:00 committed by Gerrit Code Review
commit 3e38230af7
6 changed files with 333 additions and 155 deletions

View File

@ -54,6 +54,12 @@ type prebuiltEtcProperties struct {
Installable *bool
}
type PrebuiltEtcModule interface {
Module
SubDir() string
OutputFile() OutputPath
}
type PrebuiltEtc struct {
ModuleBase

View File

@ -249,6 +249,9 @@ func apexVndkDepsMutator(mctx android.BottomUpMutatorContext) {
if vndkApex, ok := vndkApexList[vndkVersion]; ok {
mctx.AddReverseDependency(mctx.Module(), sharedLibTag, vndkApex)
}
} else if a, ok := mctx.Module().(*apexBundle); ok && a.vndkApex {
vndkVersion := proptools.StringDefault(a.vndkProperties.Vndk_version, "current")
mctx.AddDependency(mctx.Module(), prebuiltTag, cc.VndkLibrariesTxtModules(vndkVersion)...)
}
}
@ -975,7 +978,7 @@ func getCopyManifestForPrebuiltJavaLibrary(java *java.Import) (fileToCopy androi
return
}
func getCopyManifestForPrebuiltEtc(prebuilt *android.PrebuiltEtc) (fileToCopy android.Path, dirInApex string) {
func getCopyManifestForPrebuiltEtc(prebuilt android.PrebuiltEtcModule) (fileToCopy android.Path, dirInApex string) {
dirInApex = filepath.Join("etc", prebuilt.SubDir())
fileToCopy = prebuilt.OutputFile()
return
@ -1131,7 +1134,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
}
case prebuiltTag:
if prebuilt, ok := child.(*android.PrebuiltEtc); ok {
if prebuilt, ok := child.(android.PrebuiltEtcModule); ok {
fileToCopy, dirInApex := getCopyManifestForPrebuiltEtc(prebuilt)
filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, etc, prebuilt, nil})
return true

View File

@ -17,6 +17,7 @@ package apex
import (
"io/ioutil"
"os"
"path"
"reflect"
"sort"
"strings"
@ -117,6 +118,7 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr
ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
ctx.RegisterModuleType("vndk_libraries_txt", android.ModuleFactoryAdaptor(cc.VndkLibrariesTxtFactory))
ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
@ -298,6 +300,7 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr
"framework/aidl/a.aidl": nil,
"build/make/core/proguard.flags": nil,
"build/make/core/proguard_basic_keeps.flags": nil,
"dummy.txt": nil,
}
for _, handler := range handlers {
@ -1319,7 +1322,18 @@ func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName stri
apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule")
copyCmds := apexRule.Args["copy_commands"]
imageApexDir := "/image.apex/"
dstFiles := []string{}
var failed bool
var surplus []string
filesMatched := make(map[string]bool)
addContent := func(content string) {
for _, expected := range files {
if matched, _ := path.Match(expected, content); matched {
filesMatched[expected] = true
return
}
}
surplus = append(surplus, content)
}
for _, cmd := range strings.Split(copyCmds, "&&") {
cmd = strings.TrimSpace(cmd)
if cmd == "" {
@ -1338,42 +1352,26 @@ func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName stri
t.Fatal("copyCmds should copy a file to image.apex/", cmd)
}
dstFile := dst[index+len(imageApexDir):]
dstFiles = append(dstFiles, dstFile)
addContent(dstFile)
default:
t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
}
}
sort.Strings(dstFiles)
sort.Strings(files)
missing := []string{}
surplus := []string{}
i := 0
j := 0
for i < len(dstFiles) && j < len(files) {
if dstFiles[i] == files[j] {
i++
j++
} else if dstFiles[i] < files[j] {
surplus = append(surplus, dstFiles[i])
i++
} else {
missing = append(missing, files[j])
j++
}
}
if i < len(dstFiles) {
surplus = append(surplus, dstFiles[i:]...)
}
if j < len(files) {
missing = append(missing, files[j:]...)
}
failed := false
if len(surplus) > 0 {
sort.Strings(surplus)
t.Log("surplus files", surplus)
failed = true
}
if len(missing) > 0 {
if len(files) > len(filesMatched) {
var missing []string
for _, expected := range files {
if !filesMatched[expected] {
missing = append(missing, expected)
}
}
sort.Strings(missing)
t.Log("missing files", missing)
failed = true
}
@ -1418,13 +1416,18 @@ func TestVndkApexCurrent(t *testing.T) {
system_shared_libs: [],
stl: "none",
}
`)
`+vndkLibrariesTxtFiles("current"))
ensureExactContents(t, ctx, "myapex", []string{
"lib/libvndk.so",
"lib/libvndksp.so",
"lib64/libvndk.so",
"lib64/libvndksp.so",
"etc/llndk.libraries.VER.txt",
"etc/vndkcore.libraries.VER.txt",
"etc/vndksp.libraries.VER.txt",
"etc/vndkprivate.libraries.VER.txt",
"etc/vndkcorevariant.libraries.VER.txt",
})
}
@ -1469,18 +1472,44 @@ func TestVndkApexWithPrebuilt(t *testing.T) {
system_shared_libs: [],
stl: "none",
}
`, withFiles(map[string][]byte{
"libvndk.so": nil,
"libvndk.arm.so": nil,
}))
`+vndkLibrariesTxtFiles("current"),
withFiles(map[string][]byte{
"libvndk.so": nil,
"libvndk.arm.so": nil,
}))
ensureExactContents(t, ctx, "myapex", []string{
"lib/libvndk.so",
"lib/libvndk.arm.so",
"lib64/libvndk.so",
"etc/*",
})
}
func vndkLibrariesTxtFiles(vers ...string) (result string) {
for _, v := range vers {
if v == "current" {
for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkcorevariant"} {
result += `
vndk_libraries_txt {
name: "` + txt + `.libraries.txt",
}
`
}
} else {
for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
result += `
prebuilt_etc {
name: "` + txt + `.libraries.` + v + `.txt",
src: "dummy.txt",
}
`
}
}
}
return
}
func TestVndkApexVersion(t *testing.T) {
ctx, _ := testApex(t, `
apex_vndk {
@ -1530,17 +1559,19 @@ func TestVndkApexVersion(t *testing.T) {
srcs: ["libvndk27_x86_64.so"],
},
},
}
`, withFiles(map[string][]byte{
"libvndk27_arm.so": nil,
"libvndk27_arm64.so": nil,
"libvndk27_x86.so": nil,
"libvndk27_x86_64.so": nil,
}))
}
`+vndkLibrariesTxtFiles("27"),
withFiles(map[string][]byte{
"libvndk27_arm.so": nil,
"libvndk27_arm64.so": nil,
"libvndk27_x86.so": nil,
"libvndk27_x86_64.so": nil,
}))
ensureExactContents(t, ctx, "myapex_v27", []string{
"lib/libvndk27_arm.so",
"lib64/libvndk27_arm64.so",
"etc/*",
})
}
@ -1607,7 +1638,7 @@ func TestVndkApexNameRule(t *testing.T) {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}`)
}`+vndkLibrariesTxtFiles("28", "current"))
assertApexName := func(expected, moduleName string) {
bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle)
@ -1647,18 +1678,20 @@ func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
system_shared_libs: [],
stl: "none",
}
`, withTargets(map[android.OsType][]android.Target{
android.Android: []android.Target{
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
{Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
{Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
},
}))
`+vndkLibrariesTxtFiles("current"),
withTargets(map[android.OsType][]android.Target{
android.Android: []android.Target{
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
{Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
{Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
},
}))
ensureExactContents(t, ctx, "myapex", []string{
"lib/libvndk.so",
"lib64/libvndk.so",
"etc/*",
})
}
@ -1693,8 +1726,7 @@ func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
}
func TestVndkApexWithBinder32(t *testing.T) {
ctx, _ := testApex(t,
`
ctx, _ := testApex(t, `
apex_vndk {
name: "myapex_v27",
key: "myapex.key",
@ -1738,7 +1770,7 @@ func TestVndkApexWithBinder32(t *testing.T) {
}
},
}
`,
`+vndkLibrariesTxtFiles("27"),
withFiles(map[string][]byte{
"libvndk27.so": nil,
"libvndk27binder32.so": nil,
@ -1753,6 +1785,7 @@ func TestVndkApexWithBinder32(t *testing.T) {
ensureExactContents(t, ctx, "myapex_v27", []string{
"lib/libvndk27binder32.so",
"etc/*",
})
}

View File

@ -248,27 +248,45 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string
}
}
func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, name, subDir, variant string) {
func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, moduleName, snapshotFilename, subDir, variant string) {
vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
mod := ctx.ModuleForTests(name, variant).Module().(*Module)
if !mod.outputFile.Valid() {
t.Errorf("%q must have output\n", name)
mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
if !ok {
t.Errorf("%q must have output\n", moduleName)
return
}
snapshotPath := filepath.Join(subDir, mod.outputFile.Path().Base())
outputFiles, err := mod.OutputFiles("")
if err != nil || len(outputFiles) != 1 {
t.Errorf("%q must have single output\n", moduleName)
return
}
snapshotPath := filepath.Join(subDir, snapshotFilename)
out := vndkSnapshot.Output(snapshotPath)
if out.Input != mod.outputFile.Path() {
t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), mod.outputFile.String())
if out.Input.String() != outputFiles[0].String() {
t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), outputFiles[0])
}
}
func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
t.Helper()
assertString(t, params.Rule.String(), android.WriteFile.String())
actual := strings.FieldsFunc(strings.ReplaceAll(params.Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' })
assertArrayString(t, actual, expected)
}
func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
t.Helper()
vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
actual := strings.FieldsFunc(strings.ReplaceAll(vndkSnapshot.Output(output).Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' })
assertArrayString(t, actual, expected)
checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
}
func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
t.Helper()
vndkLibraries := ctx.ModuleForTests(module, "")
output := insertVndkVersion(module, "VER")
checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
}
func TestVndk(t *testing.T) {
@ -321,6 +339,21 @@ func TestVndk(t *testing.T) {
},
},
}
vndk_libraries_txt {
name: "llndk.libraries.txt",
}
vndk_libraries_txt {
name: "vndkcore.libraries.txt",
}
vndk_libraries_txt {
name: "vndksp.libraries.txt",
}
vndk_libraries_txt {
name: "vndkprivate.libraries.txt",
}
vndk_libraries_txt {
name: "vndkcorevariant.libraries.txt",
}
`, config)
checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
@ -346,17 +379,17 @@ func TestVndk(t *testing.T) {
variant := "android_arm64_armv8-a_vendor.VER_shared"
variant2nd := "android_arm_armv7-a-neon_vendor.VER_shared"
checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLibPath, variant)
checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLib2ndPath, variant2nd)
checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLibPath, variant)
checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLib2ndPath, variant2nd)
checkVndkSnapshot(t, ctx, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
checkVndkSnapshot(t, ctx, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
checkVndkSnapshot(t, ctx, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
checkVndkSnapshot(t, ctx, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
checkVndkSnapshot(t, ctx, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
checkVndkSnapshot(t, ctx, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
checkVndkSnapshot(t, ctx, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
checkVndkSnapshot(t, ctx, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
checkVndkOutput(t, ctx, "vndk/llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
checkVndkOutput(t, ctx, "vndk/vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
checkVndkOutput(t, ctx, "vndk/vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
checkVndkOutput(t, ctx, "vndk/vndkcorevariant.libraries.txt", nil)
// merged & tagged & filtered-out(libclang_rt)
checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
"LLNDK: libc.so",
"LLNDK: libdl.so",
@ -371,19 +404,25 @@ func TestVndk(t *testing.T) {
"VNDK-private: libvndk-private.so",
"VNDK-private: libvndk_sp_private-x.so",
})
checkVndkOutput(t, ctx, "vndk/llndk.libraries.txt", []string{
"libc.so", "libdl.so", "libft2.so", "libm.so",
})
checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{
"libvndk-private.so", "libvndk.so",
})
checkVndkOutput(t, ctx, "vndk/vndksp.libraries.txt", []string{
"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so",
})
checkVndkOutput(t, ctx, "vndk/vndkprivate.libraries.txt", []string{
"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so",
})
checkVndkOutput(t, ctx, "vndk/vndkcorevariant.libraries.txt", []string{})
checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
}
func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
config := android.TestArchConfig(buildDir, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
ctx := testCcWithConfig(t, `
vndk_libraries_txt {
name: "llndk.libraries.txt",
}`, config)
module := ctx.ModuleForTests("llndk.libraries.txt", "")
entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())
assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
}
func TestVndkUsingCoreVariant(t *testing.T) {
@ -422,20 +461,17 @@ func TestVndkUsingCoreVariant(t *testing.T) {
},
nocrt: true,
}
vndk_libraries_txt {
name: "vndkcorevariant.libraries.txt",
}
`, config)
checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{"libvndk.so", "libvndk2.so"})
checkVndkOutput(t, ctx, "vndk/vndkcorevariant.libraries.txt", []string{
"libc++.so", "libvndk2.so", "libvndk_sp.so",
})
checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
}
func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
config := android.TestArchConfig(buildDir, nil)
config.TestProductVariables.DeviceVndkVersion = nil
config.TestProductVariables.Platform_vndk_version = nil
ctx := testCcWithConfig(t, `
ctx := testCcNoVndk(t, `
cc_library {
name: "libvndk",
vendor_available: true,
@ -444,7 +480,7 @@ func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
},
nocrt: true,
}
`, config)
`)
checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
"LLNDK: libc.so",

View File

@ -269,6 +269,7 @@ func CreateTestContext(bp string, fs map[string][]byte,
ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory))
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(VndkPrebuiltSharedFactory))
ctx.RegisterModuleType("vndk_libraries_txt", android.ModuleFactoryAdaptor(VndkLibrariesTxtFactory))
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("image", ImageMutator).Parallel()
ctx.BottomUp("link", LinkageMutator).Parallel()

View File

@ -27,6 +27,34 @@ import (
"android/soong/cc/config"
)
const (
llndkLibrariesTxt = "llndk.libraries.txt"
vndkCoreLibrariesTxt = "vndkcore.libraries.txt"
vndkSpLibrariesTxt = "vndksp.libraries.txt"
vndkPrivateLibrariesTxt = "vndkprivate.libraries.txt"
vndkUsingCoreVariantLibrariesTxt = "vndkcorevariant.libraries.txt"
)
func VndkLibrariesTxtModules(vndkVersion string) []string {
if vndkVersion == "current" {
return []string{
llndkLibrariesTxt,
vndkCoreLibrariesTxt,
vndkSpLibrariesTxt,
vndkPrivateLibrariesTxt,
vndkUsingCoreVariantLibrariesTxt,
}
}
// Snapshot vndks have their own *.libraries.VER.txt files.
// Note that snapshots don't have "vndkcorevariant.libraries.VER.txt"
return []string{
insertVndkVersion(llndkLibrariesTxt, vndkVersion),
insertVndkVersion(vndkCoreLibrariesTxt, vndkVersion),
insertVndkVersion(vndkSpLibrariesTxt, vndkVersion),
insertVndkVersion(vndkPrivateLibrariesTxt, vndkVersion),
}
}
type VndkProperties struct {
Vndk struct {
// declared as a VNDK or VNDK-SP module. The vendor variant
@ -360,22 +388,109 @@ func VndkMutator(mctx android.BottomUpMutatorContext) {
}
func init() {
android.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory)
android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
}
type vndkLibrariesTxt struct {
android.ModuleBase
outputFile android.OutputPath
}
var _ android.PrebuiltEtcModule = &vndkLibrariesTxt{}
var _ android.OutputFileProducer = &vndkLibrariesTxt{}
// vndk_libraries_txt is a special kind of module type in that it name is one of
// - llndk.libraries.txt
// - vndkcore.libraries.txt
// - vndksp.libraries.txt
// - vndkprivate.libraries.txt
// - vndkcorevariant.libraries.txt
// A module behaves like a prebuilt_etc but its content is generated by soong.
// By being a soong module, these files can be referenced by other soong modules.
// For example, apex_vndk can depend on these files as prebuilt.
func VndkLibrariesTxtFactory() android.Module {
m := &vndkLibrariesTxt{}
android.InitAndroidModule(m)
return m
}
func insertVndkVersion(filename string, vndkVersion string) string {
if index := strings.LastIndex(filename, "."); index != -1 {
return filename[:index] + "." + vndkVersion + filename[index:]
}
return filename
}
func (txt *vndkLibrariesTxt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var list []string
switch txt.Name() {
case llndkLibrariesTxt:
for _, filename := range android.SortedStringMapValues(llndkLibraries(ctx.Config())) {
if strings.HasPrefix(filename, "libclang_rt.hwasan-") {
continue
}
list = append(list, filename)
}
case vndkCoreLibrariesTxt:
list = android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
case vndkSpLibrariesTxt:
list = android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
case vndkPrivateLibrariesTxt:
list = android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
case vndkUsingCoreVariantLibrariesTxt:
list = android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
default:
ctx.ModuleErrorf("name(%s) is unknown.", txt.Name())
return
}
filename := insertVndkVersion(txt.Name(), ctx.DeviceConfig().PlatformVndkVersion())
txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile,
Output: txt.outputFile,
Description: "Writing " + txt.outputFile.String(),
Args: map[string]string{
"content": strings.Join(list, "\\n"),
},
})
installPath := android.PathForModuleInstall(ctx, "etc")
ctx.InstallFile(installPath, filename, txt.outputFile)
}
func (txt *vndkLibrariesTxt) AndroidMkEntries() android.AndroidMkEntries {
return android.AndroidMkEntries{
Class: "ETC",
OutputFile: android.OptionalPathForPath(txt.outputFile),
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(entries *android.AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_STEM", txt.outputFile.Base())
},
},
}
}
func (txt *vndkLibrariesTxt) OutputFile() android.OutputPath {
return txt.outputFile
}
func (txt *vndkLibrariesTxt) OutputFiles(tag string) (android.Paths, error) {
return android.Paths{txt.outputFile}, nil
}
func (txt *vndkLibrariesTxt) SubDir() string {
return ""
}
func VndkSnapshotSingleton() android.Singleton {
return &vndkSnapshotSingleton{}
}
type vndkSnapshotSingleton struct {
installedLlndkLibraries []string
llndkLibrariesFile android.Path
vndkSpLibrariesFile android.Path
vndkCoreLibrariesFile android.Path
vndkPrivateLibrariesFile android.Path
vndkCoreVariantLibrariesFile android.Path
vndkLibrariesFile android.Path
vndkSnapshotZipFile android.OptionalPath
vndkLibrariesFile android.OutputPath
vndkSnapshotZipFile android.OptionalPath
}
func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
@ -650,12 +765,14 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
}
}
snapshotOutputs = append(snapshotOutputs,
installSnapshotFileFromPath(c.vndkCoreLibrariesFile, filepath.Join(configsDir, "vndkcore.libraries.txt")),
installSnapshotFileFromPath(c.vndkPrivateLibrariesFile, filepath.Join(configsDir, "vndkprivate.libraries.txt")),
installSnapshotFileFromPath(c.vndkSpLibrariesFile, filepath.Join(configsDir, "vndksp.libraries.txt")),
installSnapshotFileFromPath(c.llndkLibrariesFile, filepath.Join(configsDir, "llndk.libraries.txt")),
)
// install *.libraries.txt except vndkcorevariant.libraries.txt
ctx.VisitAllModules(func(module android.Module) {
m, ok := module.(*vndkLibrariesTxt)
if !ok || !m.Enabled() || m.Name() == vndkUsingCoreVariantLibrariesTxt {
return
}
snapshotOutputs = append(snapshotOutputs, installSnapshotFileFromPath(m.OutputFile(), filepath.Join(configsDir, m.Name())))
})
/*
Dump a map to a list file as:
@ -737,46 +854,12 @@ func getVndkFileName(m *Module) (string, error) {
}
func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.SingletonContext) {
// Make uses LLNDK_LIBRARIES to determine which libraries to install.
// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
// Therefore, by removing the library here, we cause it to only be installed if libc
// depends on it.
installedLlndkLibraries := make(map[string]string)
for lib, filename := range llndkLibraries(ctx.Config()) {
if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
continue
}
installedLlndkLibraries[lib] = filename
}
installListFile := func(list []string, fileName string) android.Path {
out := android.PathForOutput(ctx, "vndk", fileName)
ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile,
Output: out,
Description: "Writing " + out.String(),
Args: map[string]string{
"content": strings.Join(list, "\\n"),
},
})
return out
}
c.installedLlndkLibraries = android.SortedStringKeys(installedLlndkLibraries)
llndk := android.SortedStringMapValues(installedLlndkLibraries)
llndk := android.SortedStringMapValues(llndkLibraries(ctx.Config()))
vndkcore := android.SortedStringMapValues(vndkCoreLibraries(ctx.Config()))
vndksp := android.SortedStringMapValues(vndkSpLibraries(ctx.Config()))
vndkprivate := android.SortedStringMapValues(vndkPrivateLibraries(ctx.Config()))
vndkcorevariant := android.SortedStringMapValues(vndkUsingCoreVariantLibraries(ctx.Config()))
c.llndkLibrariesFile = installListFile(llndk, "llndk.libraries.txt")
c.vndkCoreLibrariesFile = installListFile(vndkcore, "vndkcore.libraries.txt")
c.vndkSpLibrariesFile = installListFile(vndksp, "vndksp.libraries.txt")
c.vndkPrivateLibrariesFile = installListFile(vndkprivate, "vndkprivate.libraries.txt")
c.vndkCoreVariantLibrariesFile = installListFile(vndkcorevariant, "vndkcorevariant.libraries.txt")
// merged & tagged & filtered-out(libclang_rt)
// Build list of vndk libs as merged & tagged & filter-out(libclang_rt):
// Since each target have different set of libclang_rt.* files,
// keep the common set of files in vndk.libraries.txt
var merged []string
@ -792,32 +875,48 @@ func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.Singleton
merged = append(merged, addPrefix(vndksp, "VNDK-SP: ")...)
merged = append(merged, addPrefix(filterOutLibClangRt(vndkcore), "VNDK-core: ")...)
merged = append(merged, addPrefix(vndkprivate, "VNDK-private: ")...)
c.vndkLibrariesFile = installListFile(merged, "vndk.libraries.txt")
c.vndkLibrariesFile = android.PathForOutput(ctx, "vndk", "vndk.libraries.txt")
ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile,
Output: c.vndkLibrariesFile,
Description: "Writing " + c.vndkLibrariesFile.String(),
Args: map[string]string{
"content": strings.Join(merged, "\\n"),
},
})
}
func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
// Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
// they been moved to an apex.
movedToApexLlndkLibraries := []string{}
for _, lib := range c.installedLlndkLibraries {
for lib := range llndkLibraries(ctx.Config()) {
// Skip bionic libs, they are handled in different manner
if android.DirectlyInAnyApex(&notOnHostContext{}, lib) && !isBionic(lib) {
movedToApexLlndkLibraries = append(movedToApexLlndkLibraries, lib)
}
}
ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(movedToApexLlndkLibraries, " "))
ctx.Strict("LLNDK_LIBRARIES", strings.Join(c.installedLlndkLibraries, " "))
// Make uses LLNDK_LIBRARIES to determine which libraries to install.
// HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
// Therefore, by removing the library here, we cause it to only be installed if libc
// depends on it.
installedLlndkLibraries := []string{}
for lib := range llndkLibraries(ctx.Config()) {
if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
continue
}
installedLlndkLibraries = append(installedLlndkLibraries, lib)
}
sort.Strings(installedLlndkLibraries)
ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkCoreLibraries(ctx.Config())), " "))
ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(android.SortedStringKeys(vndkSpLibraries(ctx.Config())), " "))
ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(android.SortedStringKeys(vndkPrivateLibraries(ctx.Config())), " "))
ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(android.SortedStringKeys(vndkUsingCoreVariantLibraries(ctx.Config())), " "))
ctx.Strict("LLNDK_LIBRARIES_FILE", c.llndkLibrariesFile.String())
ctx.Strict("VNDKCORE_LIBRARIES_FILE", c.vndkCoreLibrariesFile.String())
ctx.Strict("VNDKSP_LIBRARIES_FILE", c.vndkSpLibrariesFile.String())
ctx.Strict("VNDKPRIVATE_LIBRARIES_FILE", c.vndkPrivateLibrariesFile.String())
ctx.Strict("VNDKCOREVARIANT_LIBRARIES_FILE", c.vndkCoreVariantLibrariesFile.String())
ctx.Strict("VNDK_LIBRARIES_FILE", c.vndkLibrariesFile.String())
ctx.Strict("SOONG_VNDK_SNAPSHOT_ZIP", c.vndkSnapshotZipFile.String())
}