Merge "Switch hiddenapi to use OutputPath instead of ModuleOutPath"
diff --git a/android/packaging.go b/android/packaging.go
index 601e0b3..9b901ce 100644
--- a/android/packaging.go
+++ b/android/packaging.go
@@ -49,6 +49,11 @@
return ""
}
+// Path relative to the root of the package
+func (p *PackagingSpec) RelPathInPackage() string {
+ return p.relPathInPackage
+}
+
type PackageModule interface {
Module
packagingBase() *PackagingBase
@@ -87,9 +92,17 @@
Lib64 depsProperty `android:"arch_variant"`
}
+type packagingArchProperties struct {
+ Arm64 depsProperty
+ Arm depsProperty
+ X86_64 depsProperty
+ X86 depsProperty
+}
+
type PackagingProperties struct {
Deps []string `android:"arch_variant"`
Multilib packagingMultilibProperties `android:"arch_variant"`
+ Arch packagingArchProperties
}
func InitPackageModule(p PackageModule) {
@@ -116,6 +129,7 @@
} else if arch == Common {
ret = append(ret, p.properties.Multilib.Common.Deps...)
}
+
for i, t := range ctx.MultiTargets() {
if t.Arch.ArchType == arch {
ret = append(ret, p.properties.Deps...)
@@ -124,6 +138,20 @@
}
}
}
+
+ if ctx.Arch().ArchType == Common {
+ switch arch {
+ case Arm64:
+ ret = append(ret, p.properties.Arch.Arm64.Deps...)
+ case Arm:
+ ret = append(ret, p.properties.Arch.Arm.Deps...)
+ case X86_64:
+ ret = append(ret, p.properties.Arch.X86_64.Deps...)
+ case X86:
+ ret = append(ret, p.properties.Arch.X86.Deps...)
+ }
+ }
+
return FirstUniqueStrings(ret)
}
diff --git a/android/packaging_test.go b/android/packaging_test.go
index 3d6fa43..2c99b97 100644
--- a/android/packaging_test.go
+++ b/android/packaging_test.go
@@ -61,13 +61,20 @@
entries []string
}
-func packageTestModuleFactory() Module {
+func packageMultiTargetTestModuleFactory() Module {
module := &packageTestModule{}
InitPackageModule(module)
InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon)
return module
}
+func packageTestModuleFactory() Module {
+ module := &packageTestModule{}
+ InitPackageModule(module)
+ InitAndroidArchModule(module, DeviceSupported, MultilibBoth)
+ return module
+}
+
func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) {
m.AddDeps(ctx, installDepTag{})
}
@@ -77,14 +84,22 @@
m.entries = m.CopyDepsToZip(ctx, zipFile)
}
-func runPackagingTest(t *testing.T, bp string, expected []string) {
+func runPackagingTest(t *testing.T, multitarget bool, bp string, expected []string) {
t.Helper()
config := TestArchConfig(buildDir, nil, bp, nil)
ctx := NewTestArchContext(config)
ctx.RegisterModuleType("component", componentTestModuleFactory)
- ctx.RegisterModuleType("package_module", packageTestModuleFactory)
+
+ var archVariant string
+ if multitarget {
+ archVariant = "android_common"
+ ctx.RegisterModuleType("package_module", packageMultiTargetTestModuleFactory)
+ } else {
+ archVariant = "android_arm64_armv8-a"
+ ctx.RegisterModuleType("package_module", packageTestModuleFactory)
+ }
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
@@ -92,7 +107,7 @@
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
- p := ctx.ModuleForTests("package", "android_common").Module().(*packageTestModule)
+ p := ctx.ModuleForTests("package", archVariant).Module().(*packageTestModule)
actual := p.entries
actual = SortedUniqueStrings(actual)
expected = SortedUniqueStrings(expected)
@@ -101,8 +116,9 @@
}
}
-func TestPackagingBase(t *testing.T) {
- runPackagingTest(t,
+func TestPackagingBaseMultiTarget(t *testing.T) {
+ multiTarget := true
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -114,7 +130,7 @@
}
`, []string{"lib64/foo"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -131,7 +147,7 @@
}
`, []string{"lib64/foo", "lib64/bar"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -149,7 +165,7 @@
}
`, []string{"lib32/foo", "lib32/bar", "lib64/foo", "lib64/bar"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -172,7 +188,7 @@
}
`, []string{"lib32/foo", "lib32/bar", "lib64/foo"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -193,4 +209,136 @@
compile_multilib: "both",
}
`, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ }
+
+ component {
+ name: "baz",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ arch: {
+ arm64: {
+ deps: ["bar"],
+ },
+ x86_64: {
+ deps: ["baz"],
+ },
+ },
+ compile_multilib: "both",
+ }
+ `, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
+}
+
+func TestPackagingBaseSingleTarget(t *testing.T) {
+ multiTarget := false
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ }
+ `, []string{"lib64/foo"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ deps: ["bar"],
+ }
+
+ component {
+ name: "bar",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ }
+ `, []string{"lib64/foo", "lib64/bar"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ compile_multilib: "32",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ multilib: {
+ lib32: {
+ deps: ["bar"],
+ },
+ },
+ }
+ `, []string{"lib64/foo"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ multilib: {
+ lib64: {
+ deps: ["bar"],
+ },
+ },
+ }
+ `, []string{"lib64/foo", "lib64/bar"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ }
+
+ component {
+ name: "baz",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ arch: {
+ arm64: {
+ deps: ["bar"],
+ },
+ x86_64: {
+ deps: ["baz"],
+ },
+ },
+ }
+ `, []string{"lib64/foo", "lib64/bar"})
}
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index a414f04..b89d0a0 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -28,7 +28,7 @@
ruleShims := CreateRuleShims(android.ModuleTypeFactories())
- buildToTargets := GenerateSoongModuleTargets(ctx.Context(), ctx.mode)
+ buildToTargets := GenerateBazelTargets(ctx.Context(), ctx.mode)
filesToWrite := CreateBazelFiles(ruleShims, buildToTargets, ctx.mode)
for _, f := range filesToWrite {
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 1af1d60..1fa3e06 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -159,7 +159,7 @@
return attributes
}
-func GenerateSoongModuleTargets(ctx bpToBuildContext, codegenMode CodegenMode) map[string]BazelTargets {
+func GenerateBazelTargets(ctx bpToBuildContext, codegenMode CodegenMode) map[string]BazelTargets {
buildFileToTargets := make(map[string]BazelTargets)
ctx.VisitAllModules(func(m blueprint.Module) {
dir := ctx.ModuleDir(m)
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index a01a7cd..df7dd17 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -201,7 +201,7 @@
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, QueryView)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, QueryView)[dir]
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount)
}
@@ -252,7 +252,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount)
}
@@ -408,7 +408,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount {
t.Fatalf("Expected %d bazel target, got %d", testCase.expectedBazelTargetCount, actualCount)
}
@@ -617,7 +617,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
}
@@ -815,7 +815,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount := len(bazelTargets); actualCount != 1 {
t.Fatalf("%s: Expected 1 bazel target, got %d", testCase.description, actualCount)
}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 9345728..ddb81d9 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -519,7 +519,7 @@
entries.SubName += ".cfi"
}
- entries.SubName += c.androidMkSuffix
+ entries.SubName += c.baseProperties.Androidmk_suffix
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
c.libraryDecorator.androidMkWriteExportedFlags(entries)
@@ -546,7 +546,7 @@
func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "EXECUTABLES"
- entries.SubName = c.androidMkSuffix
+ entries.SubName = c.baseProperties.Androidmk_suffix
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
entries.AddStrings("LOCAL_MODULE_SYMLINKS", c.Properties.Symlinks...)
@@ -555,7 +555,7 @@
func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "STATIC_LIBRARIES"
- entries.SubName = c.androidMkSuffix
+ entries.SubName = c.baseProperties.Androidmk_suffix
entries.ExtraFooters = append(entries.ExtraFooters,
func(w io.Writer, name, prefix, moduleDir string) {
diff --git a/cc/cc.go b/cc/cc.go
index afa6bf9..d282b6e 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -50,10 +50,6 @@
ctx.BottomUp("version", versionMutator).Parallel()
ctx.BottomUp("begin", BeginMutator).Parallel()
ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
- ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
- ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
- ctx.BottomUp("recovery_snapshot", RecoverySnapshotMutator).Parallel()
- ctx.BottomUp("recovery_snapshot_source", RecoverySnapshotSourceMutator).Parallel()
})
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
@@ -1237,7 +1233,7 @@
}
func (c *Module) isSnapshotPrebuilt() bool {
- if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
+ if p, ok := c.linker.(snapshotInterface); ok {
return p.isSnapshotPrebuilt()
}
return false
@@ -1937,6 +1933,40 @@
c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
+ var snapshotInfo *SnapshotInfo
+ getSnapshot := func() SnapshotInfo {
+ // Only modules with BOARD_VNDK_VERSION uses snapshot. Others use the zero value of
+ // SnapshotInfo, which provides no mappings.
+ if snapshotInfo == nil {
+ // Only retrieve the snapshot on demand in order to avoid circular dependencies
+ // between the modules in the snapshot and the snapshot itself.
+ var snapshotModule []blueprint.Module
+ if c.InVendor() && c.VndkVersion() == actx.DeviceConfig().VndkVersion() {
+ snapshotModule = ctx.AddVariationDependencies(nil, nil, "vendor_snapshot")
+ } else if recoverySnapshotVersion := actx.DeviceConfig().RecoverySnapshotVersion(); recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && c.InRecovery() {
+ snapshotModule = ctx.AddVariationDependencies(nil, nil, "recovery_snapshot")
+ }
+ if len(snapshotModule) > 0 {
+ snapshot := ctx.OtherModuleProvider(snapshotModule[0], SnapshotInfoProvider).(SnapshotInfo)
+ snapshotInfo = &snapshot
+ // republish the snapshot for use in later mutators on this module
+ ctx.SetProvider(SnapshotInfoProvider, snapshot)
+ } else {
+ snapshotInfo = &SnapshotInfo{}
+ }
+ }
+
+ return *snapshotInfo
+ }
+
+ rewriteSnapshotLib := func(lib string, snapshotMap map[string]string) string {
+ if snapshot, ok := snapshotMap[lib]; ok {
+ return snapshot
+ }
+
+ return lib
+ }
+
variantNdkLibs := []string{}
variantLateNdkLibs := []string{}
if ctx.Os() == android.Android {
@@ -1956,21 +1986,6 @@
// nonvariantLibs
vendorPublicLibraries := vendorPublicLibraries(actx.Config())
- vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
- recoverySnapshotSharedLibs := recoverySnapshotSharedLibs(actx.Config())
-
- rewriteVendorLibs := func(lib string) string {
- // only modules with BOARD_VNDK_VERSION uses snapshot.
- if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
- return lib
- }
-
- if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
- return snapshot
- }
-
- return lib
- }
rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
variantLibs = []string{}
@@ -1979,21 +1994,11 @@
// strip #version suffix out
name, _ := StubsLibNameAndVersion(entry)
if c.InRecovery() {
- recoverySnapshotVersion :=
- actx.DeviceConfig().RecoverySnapshotVersion()
- if recoverySnapshotVersion == "current" ||
- recoverySnapshotVersion == "" {
- nonvariantLibs = append(nonvariantLibs, name)
- } else if snapshot, ok := recoverySnapshotSharedLibs.get(
- name, actx.Arch().ArchType); ok {
- nonvariantLibs = append(nonvariantLibs, snapshot)
- } else {
- nonvariantLibs = append(nonvariantLibs, name)
- }
+ nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs))
} else if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) {
variantLibs = append(variantLibs, name+ndkLibrarySuffix)
} else if ctx.useVndk() {
- nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
+ nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs))
} else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
vendorPublicLib := name + vendorPublicLibrarySuffix
if actx.OtherModuleExists(vendorPublicLib) {
@@ -2015,56 +2020,19 @@
deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
- if ctx.useVndk() {
- for idx, lib := range deps.RuntimeLibs {
- deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
- }
+
+ for idx, lib := range deps.RuntimeLibs {
+ deps.RuntimeLibs[idx] = rewriteSnapshotLib(lib, getSnapshot().SharedLibs)
}
}
- rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
- // only modules with BOARD_VNDK_VERSION uses snapshot.
- if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
- return lib
- }
-
- if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
- return snapshot
- }
-
- return lib
- }
-
- snapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
- snapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
- snapshotObjects := vendorSnapshotObjects(actx.Config())
-
- if c.InRecovery() {
- rewriteSnapshotLibs = func(lib string, snapshotMap *snapshotMap) string {
- recoverySnapshotVersion :=
- actx.DeviceConfig().RecoverySnapshotVersion()
- if recoverySnapshotVersion == "current" ||
- recoverySnapshotVersion == "" {
- return lib
- } else if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
- return snapshot
- }
-
- return lib
- }
-
- snapshotHeaderLibs = recoverySnapshotHeaderLibs(actx.Config())
- snapshotStaticLibs = recoverySnapshotStaticLibs(actx.Config())
- snapshotObjects = recoverySnapshotObjects(actx.Config())
- }
-
for _, lib := range deps.HeaderLibs {
depTag := libraryDependencyTag{Kind: headerLibraryDependency}
if inList(lib, deps.ReexportHeaderLibHeaders) {
depTag.reexportFlags = true
}
- lib = rewriteSnapshotLibs(lib, snapshotHeaderLibs)
+ lib = rewriteSnapshotLib(lib, getSnapshot().HeaderLibs)
if c.IsStubs() {
actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
@@ -2087,7 +2055,7 @@
lib = impl
}
- lib = rewriteSnapshotLibs(lib, snapshotStaticLibs)
+ lib = rewriteSnapshotLib(lib, getSnapshot().StaticLibs)
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
@@ -2107,7 +2075,7 @@
lib = impl
}
- lib = rewriteSnapshotLibs(lib, snapshotStaticLibs)
+ lib = rewriteSnapshotLib(lib, getSnapshot().StaticLibs)
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
@@ -2121,14 +2089,14 @@
depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), snapshotStaticLibs))
+ }, depTag, rewriteSnapshotLib(staticUnwinder(actx), getSnapshot().StaticLibs))
}
for _, lib := range deps.LateStaticLibs {
depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, depTag, rewriteSnapshotLibs(lib, snapshotStaticLibs))
+ }, depTag, rewriteSnapshotLib(lib, getSnapshot().StaticLibs))
}
// shared lib names without the #version suffix
@@ -2192,11 +2160,11 @@
actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
if deps.CrtBegin != "" {
actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
- rewriteSnapshotLibs(deps.CrtBegin, snapshotObjects))
+ rewriteSnapshotLib(deps.CrtBegin, getSnapshot().Objects))
}
if deps.CrtEnd != "" {
actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
- rewriteSnapshotLibs(deps.CrtEnd, snapshotObjects))
+ rewriteSnapshotLib(deps.CrtEnd, getSnapshot().Objects))
}
if deps.LinkerFlagsFile != "" {
actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
@@ -2917,8 +2885,6 @@
}
func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
- vendorSuffixModules := vendorSuffixModules(ctx.Config())
- recoverySuffixModules := recoverySuffixModules(ctx.Config())
vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
libName := baseLibName(depName)
@@ -2929,20 +2895,10 @@
if c, ok := ccDep.(*Module); ok {
// Use base module name for snapshots when exporting to Makefile.
- if c.isSnapshotPrebuilt() {
+ if snapshotPrebuilt, ok := c.linker.(snapshotInterface); ok {
baseName := c.BaseModuleName()
- if c.IsVndk() {
- return baseName + ".vendor"
- }
-
- if c.InVendor() && vendorSuffixModules[baseName] {
- return baseName + ".vendor"
- } else if c.InRecovery() && recoverySuffixModules[baseName] {
- return baseName + ".recovery"
- } else {
- return baseName
- }
+ return baseName + snapshotPrebuilt.snapshotAndroidMkSuffix()
}
}
diff --git a/cc/image.go b/cc/image.go
index 231da7e..afe6a0e 100644
--- a/cc/image.go
+++ b/cc/image.go
@@ -318,9 +318,7 @@
} else if m.isSnapshotPrebuilt() {
// Make vendor variants only for the versions in BOARD_VNDK_VERSION and
// PRODUCT_EXTRA_VNDK_VERSIONS.
- if snapshot, ok := m.linker.(interface {
- version() string
- }); ok {
+ if snapshot, ok := m.linker.(snapshotInterface); ok {
if m.InstallInRecovery() {
recoveryVariantNeeded = true
} else {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 8eeb355..8218d97 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -1149,13 +1149,11 @@
// added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module
if c.staticBinary() {
deps := append(extraStaticDeps, runtimeLibrary)
- // If we're using snapshots and in vendor, redirect to snapshot whenever possible
- if c.VndkVersion() == mctx.DeviceConfig().VndkVersion() {
- snapshots := vendorSnapshotStaticLibs(mctx.Config())
- for idx, dep := range deps {
- if lib, ok := snapshots.get(dep, mctx.Arch().ArchType); ok {
- deps[idx] = lib
- }
+ // If we're using snapshots, redirect to snapshot whenever possible
+ snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo)
+ for idx, dep := range deps {
+ if lib, ok := snapshot.StaticLibs[dep]; ok {
+ deps[idx] = lib
}
}
@@ -1168,13 +1166,12 @@
}
mctx.AddFarVariationDependencies(variations, depTag, deps...)
} else if !c.static() && !c.Header() {
- // If we're using snapshots and in vendor, redirect to snapshot whenever possible
- if c.VndkVersion() == mctx.DeviceConfig().VndkVersion() {
- snapshots := vendorSnapshotSharedLibs(mctx.Config())
- if lib, ok := snapshots.get(runtimeLibrary, mctx.Arch().ArchType); ok {
- runtimeLibrary = lib
- }
+ // If we're using snapshots, redirect to snapshot whenever possible
+ snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo)
+ if lib, ok := snapshot.SharedLibs[runtimeLibrary]; ok {
+ runtimeLibrary = lib
}
+
// Skip apex dependency check for sharedLibraryDependency
// when sanitizer diags are enabled. Skipping the check will allow
// building with diag libraries without having to list the
diff --git a/cc/sdk.go b/cc/sdk.go
index 2c3fec3..aec950b 100644
--- a/cc/sdk.go
+++ b/cc/sdk.go
@@ -75,5 +75,7 @@
}
ctx.AliasVariation("")
}
+ case *snapshot:
+ ctx.CreateVariations("")
}
}
diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go
index 2003e03..ffaed8e 100644
--- a/cc/snapshot_prebuilt.go
+++ b/cc/snapshot_prebuilt.go
@@ -19,19 +19,15 @@
import (
"strings"
- "sync"
"android/soong/android"
- "github.com/google/blueprint/proptools"
+ "github.com/google/blueprint"
)
// Defines the specifics of different images to which the snapshot process is applicable, e.g.,
// vendor, recovery, ramdisk.
type snapshotImage interface {
- // Used to register callbacks with the build system.
- init()
-
// Returns true if a snapshot should be generated for this image.
shouldGenerateSnapshot(ctx android.SingletonContext) bool
@@ -61,46 +57,41 @@
// exclude_from_recovery_snapshot properties.
excludeFromSnapshot(m *Module) bool
- // Returns the snapshotMap to be used for a given module and config, or nil if the
- // module is not included in this image.
- getSnapshotMap(m *Module, cfg android.Config) *snapshotMap
-
- // Returns mutex used for mutual exclusion when updating the snapshot maps.
- getMutex() *sync.Mutex
-
- // For a given arch, a maps of which modules are included in this image.
- suffixModules(config android.Config) map[string]bool
-
- // Whether to add a given module to the suffix map.
- shouldBeAddedToSuffixModules(m *Module) bool
-
// Returns true if the build is using a snapshot for this image.
isUsingSnapshot(cfg android.DeviceConfig) bool
- // Whether to skip the module mutator for a module in a given context.
- skipModuleMutator(ctx android.BottomUpMutatorContext) bool
-
- // Whether to skip the source mutator for a given module.
- skipSourceMutator(ctx android.BottomUpMutatorContext) bool
+ // Returns a version of which the snapshot should be used in this target.
+ // This will only be meaningful when isUsingSnapshot is true.
+ targetSnapshotVersion(cfg android.DeviceConfig) string
// Whether to exclude a given module from the directed snapshot or not.
// If the makefile variable DIRECTED_{IMAGE}_SNAPSHOT is true, directed snapshot is turned on,
// and only modules listed in {IMAGE}_SNAPSHOT_MODULES will be captured.
excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool
+
+ // The image variant name for this snapshot image.
+ // For example, recovery snapshot image will return "recovery", and vendor snapshot image will
+ // return "vendor." + version.
+ imageVariantName(cfg android.DeviceConfig) string
+
+ // The variant suffix for snapshot modules. For example, vendor snapshot modules will have
+ // ".vendor" as their suffix.
+ moduleNameSuffix() string
}
type vendorSnapshotImage struct{}
type recoverySnapshotImage struct{}
-func (vendorSnapshotImage) init() {
- android.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
- android.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
- android.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
- android.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
- android.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
- android.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
+func (vendorSnapshotImage) init(ctx android.RegistrationContext) {
+ ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
+ ctx.RegisterModuleType("vendor_snapshot", vendorSnapshotFactory)
+ ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
+ ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
+ ctx.RegisterModuleType("vendor_snapshot_header", VendorSnapshotHeaderFactory)
+ ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
+ ctx.RegisterModuleType("vendor_snapshot_object", VendorSnapshotObjectFactory)
- android.RegisterSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton)
+ ctx.RegisterSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton)
}
func (vendorSnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool {
@@ -129,73 +120,13 @@
return m.ExcludeFromVendorSnapshot()
}
-func (vendorSnapshotImage) getSnapshotMap(m *Module, cfg android.Config) *snapshotMap {
- if lib, ok := m.linker.(libraryInterface); ok {
- if lib.static() {
- return vendorSnapshotStaticLibs(cfg)
- } else if lib.shared() {
- return vendorSnapshotSharedLibs(cfg)
- } else {
- // header
- return vendorSnapshotHeaderLibs(cfg)
- }
- } else if m.binary() {
- return vendorSnapshotBinaries(cfg)
- } else if m.object() {
- return vendorSnapshotObjects(cfg)
- } else {
- return nil
- }
-}
-
-func (vendorSnapshotImage) getMutex() *sync.Mutex {
- return &vendorSnapshotsLock
-}
-
-func (vendorSnapshotImage) suffixModules(config android.Config) map[string]bool {
- return vendorSuffixModules(config)
-}
-
-func (vendorSnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool {
- // vendor suffix should be added to snapshots if the source module isn't vendor: true.
- if module.SocSpecific() {
- return false
- }
-
- // But we can't just check SocSpecific() since we already passed the image mutator.
- // Check ramdisk and recovery to see if we are real "vendor: true" module.
- ramdiskAvailable := module.InRamdisk() && !module.OnlyInRamdisk()
- vendorRamdiskAvailable := module.InVendorRamdisk() && !module.OnlyInVendorRamdisk()
- recoveryAvailable := module.InRecovery() && !module.OnlyInRecovery()
-
- return !ramdiskAvailable && !recoveryAvailable && !vendorRamdiskAvailable
-}
-
func (vendorSnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool {
vndkVersion := cfg.VndkVersion()
return vndkVersion != "current" && vndkVersion != ""
}
-func (vendorSnapshotImage) skipModuleMutator(ctx android.BottomUpMutatorContext) bool {
- vndkVersion := ctx.DeviceConfig().VndkVersion()
- module, ok := ctx.Module().(*Module)
- return !ok || module.VndkVersion() != vndkVersion
-}
-
-func (vendorSnapshotImage) skipSourceMutator(ctx android.BottomUpMutatorContext) bool {
- vndkVersion := ctx.DeviceConfig().VndkVersion()
- module, ok := ctx.Module().(*Module)
- if !ok {
- return true
- }
- if module.VndkVersion() != vndkVersion {
- return true
- }
- // .. and also filter out llndk library
- if module.IsLlndk() {
- return true
- }
- return false
+func (vendorSnapshotImage) targetSnapshotVersion(cfg android.DeviceConfig) string {
+ return cfg.VndkVersion()
}
// returns true iff a given module SHOULD BE EXCLUDED, false if included
@@ -208,13 +139,22 @@
return !cfg.VendorSnapshotModules()[name]
}
-func (recoverySnapshotImage) init() {
- android.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
- android.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory)
- android.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory)
- android.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory)
- android.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory)
- android.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory)
+func (vendorSnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
+ return VendorVariationPrefix + cfg.VndkVersion()
+}
+
+func (vendorSnapshotImage) moduleNameSuffix() string {
+ return vendorSuffix
+}
+
+func (recoverySnapshotImage) init(ctx android.RegistrationContext) {
+ ctx.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
+ ctx.RegisterModuleType("recovery_snapshot", recoverySnapshotFactory)
+ ctx.RegisterModuleType("recovery_snapshot_shared", RecoverySnapshotSharedFactory)
+ ctx.RegisterModuleType("recovery_snapshot_static", RecoverySnapshotStaticFactory)
+ ctx.RegisterModuleType("recovery_snapshot_header", RecoverySnapshotHeaderFactory)
+ ctx.RegisterModuleType("recovery_snapshot_binary", RecoverySnapshotBinaryFactory)
+ ctx.RegisterModuleType("recovery_snapshot_object", RecoverySnapshotObjectFactory)
}
func (recoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool {
@@ -245,50 +185,13 @@
return m.ExcludeFromRecoverySnapshot()
}
-func (recoverySnapshotImage) getSnapshotMap(m *Module, cfg android.Config) *snapshotMap {
- if lib, ok := m.linker.(libraryInterface); ok {
- if lib.static() {
- return recoverySnapshotStaticLibs(cfg)
- } else if lib.shared() {
- return recoverySnapshotSharedLibs(cfg)
- } else {
- // header
- return recoverySnapshotHeaderLibs(cfg)
- }
- } else if m.binary() {
- return recoverySnapshotBinaries(cfg)
- } else if m.object() {
- return recoverySnapshotObjects(cfg)
- } else {
- return nil
- }
-}
-
-func (recoverySnapshotImage) getMutex() *sync.Mutex {
- return &recoverySnapshotsLock
-}
-
-func (recoverySnapshotImage) suffixModules(config android.Config) map[string]bool {
- return recoverySuffixModules(config)
-}
-
-func (recoverySnapshotImage) shouldBeAddedToSuffixModules(module *Module) bool {
- return proptools.BoolDefault(module.Properties.Recovery_available, false)
-}
-
func (recoverySnapshotImage) isUsingSnapshot(cfg android.DeviceConfig) bool {
recoverySnapshotVersion := cfg.RecoverySnapshotVersion()
return recoverySnapshotVersion != "current" && recoverySnapshotVersion != ""
}
-func (recoverySnapshotImage) skipModuleMutator(ctx android.BottomUpMutatorContext) bool {
- module, ok := ctx.Module().(*Module)
- return !ok || !module.InRecovery()
-}
-
-func (recoverySnapshotImage) skipSourceMutator(ctx android.BottomUpMutatorContext) bool {
- module, ok := ctx.Module().(*Module)
- return !ok || !module.InRecovery()
+func (recoverySnapshotImage) targetSnapshotVersion(cfg android.DeviceConfig) string {
+ return cfg.RecoverySnapshotVersion()
}
func (recoverySnapshotImage) excludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool {
@@ -296,130 +199,160 @@
return false
}
+func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string {
+ return android.RecoveryVariation
+}
+
+func (recoverySnapshotImage) moduleNameSuffix() string {
+ return recoverySuffix
+}
+
var vendorSnapshotImageSingleton vendorSnapshotImage
var recoverySnapshotImageSingleton recoverySnapshotImage
func init() {
- vendorSnapshotImageSingleton.init()
- recoverySnapshotImageSingleton.init()
+ vendorSnapshotImageSingleton.init(android.InitRegistrationContext)
+ recoverySnapshotImageSingleton.init(android.InitRegistrationContext)
}
const (
- vendorSnapshotHeaderSuffix = ".vendor_header."
- vendorSnapshotSharedSuffix = ".vendor_shared."
- vendorSnapshotStaticSuffix = ".vendor_static."
- vendorSnapshotBinarySuffix = ".vendor_binary."
- vendorSnapshotObjectSuffix = ".vendor_object."
+ snapshotHeaderSuffix = "_header."
+ snapshotSharedSuffix = "_shared."
+ snapshotStaticSuffix = "_static."
+ snapshotBinarySuffix = "_binary."
+ snapshotObjectSuffix = "_object."
)
-const (
- recoverySnapshotHeaderSuffix = ".recovery_header."
- recoverySnapshotSharedSuffix = ".recovery_shared."
- recoverySnapshotStaticSuffix = ".recovery_static."
- recoverySnapshotBinarySuffix = ".recovery_binary."
- recoverySnapshotObjectSuffix = ".recovery_object."
-)
-
-var (
- vendorSnapshotsLock sync.Mutex
- vendorSuffixModulesKey = android.NewOnceKey("vendorSuffixModules")
- vendorSnapshotHeaderLibsKey = android.NewOnceKey("vendorSnapshotHeaderLibs")
- vendorSnapshotStaticLibsKey = android.NewOnceKey("vendorSnapshotStaticLibs")
- vendorSnapshotSharedLibsKey = android.NewOnceKey("vendorSnapshotSharedLibs")
- vendorSnapshotBinariesKey = android.NewOnceKey("vendorSnapshotBinaries")
- vendorSnapshotObjectsKey = android.NewOnceKey("vendorSnapshotObjects")
-)
-
-var (
- recoverySnapshotsLock sync.Mutex
- recoverySuffixModulesKey = android.NewOnceKey("recoverySuffixModules")
- recoverySnapshotHeaderLibsKey = android.NewOnceKey("recoverySnapshotHeaderLibs")
- recoverySnapshotStaticLibsKey = android.NewOnceKey("recoverySnapshotStaticLibs")
- recoverySnapshotSharedLibsKey = android.NewOnceKey("recoverySnapshotSharedLibs")
- recoverySnapshotBinariesKey = android.NewOnceKey("recoverySnapshotBinaries")
- recoverySnapshotObjectsKey = android.NewOnceKey("recoverySnapshotObjects")
-)
-
-// vendorSuffixModules holds names of modules whose vendor variants should have the vendor suffix.
-// This is determined by source modules, and then this will be used when exporting snapshot modules
-// to Makefile.
-//
-// For example, if libbase has "vendor_available: true", the name of core variant will be "libbase"
-// while the name of vendor variant will be "libbase.vendor". In such cases, the vendor snapshot of
-// "libbase" should be exported with the name "libbase.vendor".
-//
-// Refer to VendorSnapshotSourceMutator and makeLibName which use this.
-func vendorSuffixModules(config android.Config) map[string]bool {
- return config.Once(vendorSuffixModulesKey, func() interface{} {
- return make(map[string]bool)
- }).(map[string]bool)
+type SnapshotProperties struct {
+ Header_libs []string `android:"arch_variant"`
+ Static_libs []string `android:"arch_variant"`
+ Shared_libs []string `android:"arch_variant"`
+ Vndk_libs []string `android:"arch_variant"`
+ Binaries []string `android:"arch_variant"`
+ Objects []string `android:"arch_variant"`
}
-// these are vendor snapshot maps holding names of vendor snapshot modules
-func vendorSnapshotHeaderLibs(config android.Config) *snapshotMap {
- return config.Once(vendorSnapshotHeaderLibsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+type snapshot struct {
+ android.ModuleBase
+
+ properties SnapshotProperties
+
+ baseSnapshot baseSnapshotDecorator
+
+ image snapshotImage
}
-func vendorSnapshotSharedLibs(config android.Config) *snapshotMap {
- return config.Once(vendorSnapshotSharedLibsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) ImageMutatorBegin(ctx android.BaseModuleContext) {
+ cfg := ctx.DeviceConfig()
+ if !s.image.isUsingSnapshot(cfg) || s.image.targetSnapshotVersion(cfg) != s.baseSnapshot.version() {
+ s.Disable()
+ }
}
-func vendorSnapshotStaticLibs(config android.Config) *snapshotMap {
- return config.Once(vendorSnapshotStaticLibsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
}
-func vendorSnapshotBinaries(config android.Config) *snapshotMap {
- return config.Once(vendorSnapshotBinariesKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
}
-func vendorSnapshotObjects(config android.Config) *snapshotMap {
- return config.Once(vendorSnapshotObjectsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
}
-func recoverySuffixModules(config android.Config) map[string]bool {
- return config.Once(recoverySuffixModulesKey, func() interface{} {
- return make(map[string]bool)
- }).(map[string]bool)
+func (s *snapshot) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
}
-func recoverySnapshotHeaderLibs(config android.Config) *snapshotMap {
- return config.Once(recoverySnapshotHeaderLibsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) ExtraImageVariations(ctx android.BaseModuleContext) []string {
+ return []string{s.image.imageVariantName(ctx.DeviceConfig())}
}
-func recoverySnapshotSharedLibs(config android.Config) *snapshotMap {
- return config.Once(recoverySnapshotSharedLibsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
}
-func recoverySnapshotStaticLibs(config android.Config) *snapshotMap {
- return config.Once(recoverySnapshotStaticLibsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ // Nothing, the snapshot module is only used to forward dependency information in DepsMutator.
}
-func recoverySnapshotBinaries(config android.Config) *snapshotMap {
- return config.Once(recoverySnapshotBinariesKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+func (s *snapshot) DepsMutator(ctx android.BottomUpMutatorContext) {
+ collectSnapshotMap := func(variations []blueprint.Variation, depTag blueprint.DependencyTag,
+ names []string, snapshotSuffix, moduleSuffix string) map[string]string {
+
+ decoratedNames := make([]string, 0, len(names))
+ for _, name := range names {
+ decoratedNames = append(decoratedNames, name+
+ snapshotSuffix+moduleSuffix+
+ s.baseSnapshot.version()+
+ "."+ctx.Arch().ArchType.Name)
+ }
+
+ deps := ctx.AddVariationDependencies(variations, depTag, decoratedNames...)
+ snapshotMap := make(map[string]string)
+ for _, dep := range deps {
+ if dep == nil {
+ continue
+ }
+
+ snapshotMap[dep.(*Module).BaseModuleName()] = ctx.OtherModuleName(dep)
+ }
+ return snapshotMap
+ }
+
+ snapshotSuffix := s.image.moduleNameSuffix()
+ headers := collectSnapshotMap(nil, HeaderDepTag(), s.properties.Header_libs, snapshotSuffix, snapshotHeaderSuffix)
+ binaries := collectSnapshotMap(nil, nil, s.properties.Binaries, snapshotSuffix, snapshotBinarySuffix)
+ objects := collectSnapshotMap(nil, nil, s.properties.Objects, snapshotSuffix, snapshotObjectSuffix)
+
+ staticLibs := collectSnapshotMap([]blueprint.Variation{
+ {Mutator: "link", Variation: "static"},
+ }, StaticDepTag(), s.properties.Static_libs, snapshotSuffix, snapshotStaticSuffix)
+
+ sharedLibs := collectSnapshotMap([]blueprint.Variation{
+ {Mutator: "link", Variation: "shared"},
+ }, SharedDepTag(), s.properties.Shared_libs, snapshotSuffix, snapshotSharedSuffix)
+
+ vndkLibs := collectSnapshotMap([]blueprint.Variation{
+ {Mutator: "link", Variation: "shared"},
+ }, SharedDepTag(), s.properties.Vndk_libs, "", vndkSuffix)
+
+ for k, v := range vndkLibs {
+ sharedLibs[k] = v
+ }
+ ctx.SetProvider(SnapshotInfoProvider, SnapshotInfo{
+ HeaderLibs: headers,
+ Binaries: binaries,
+ Objects: objects,
+ StaticLibs: staticLibs,
+ SharedLibs: sharedLibs,
+ })
}
-func recoverySnapshotObjects(config android.Config) *snapshotMap {
- return config.Once(recoverySnapshotObjectsKey, func() interface{} {
- return newSnapshotMap()
- }).(*snapshotMap)
+type SnapshotInfo struct {
+ HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs map[string]string
+}
+
+var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")
+
+var _ android.ImageInterface = (*snapshot)(nil)
+
+func vendorSnapshotFactory() android.Module {
+ return snapshotFactory(vendorSnapshotImageSingleton)
+}
+
+func recoverySnapshotFactory() android.Module {
+ return snapshotFactory(recoverySnapshotImageSingleton)
+}
+
+func snapshotFactory(image snapshotImage) android.Module {
+ snapshot := &snapshot{}
+ snapshot.image = image
+ snapshot.AddProperties(
+ &snapshot.properties,
+ &snapshot.baseSnapshot.baseProperties)
+ android.InitAndroidArchModule(snapshot, android.DeviceSupported, android.MultilibBoth)
+ return snapshot
}
type baseSnapshotDecoratorProperties struct {
@@ -429,9 +362,12 @@
// Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64')
Target_arch string
+ // Suffix to be added to the module name when exporting to Android.mk, e.g. ".vendor".
+ Androidmk_suffix string
+
// Suffix to be added to the module name, e.g., vendor_shared,
// recovery_shared, etc.
- Module_suffix string
+ ModuleSuffix string `blueprint:"mutated"`
}
// baseSnapshotDecorator provides common basic functions for all snapshot modules, such as snapshot
@@ -460,7 +396,7 @@
versionSuffix += "." + p.arch()
}
- return p.baseProperties.Module_suffix + versionSuffix
+ return p.baseProperties.ModuleSuffix + versionSuffix
}
func (p *baseSnapshotDecorator) version() string {
@@ -471,18 +407,22 @@
return p.baseProperties.Target_arch
}
-func (p *baseSnapshotDecorator) module_suffix() string {
- return p.baseProperties.Module_suffix
+func (p *baseSnapshotDecorator) moduleSuffix() string {
+ return p.baseProperties.ModuleSuffix
}
func (p *baseSnapshotDecorator) isSnapshotPrebuilt() bool {
return true
}
+func (p *baseSnapshotDecorator) snapshotAndroidMkSuffix() string {
+ return p.baseProperties.Androidmk_suffix
+}
+
// Call this with a module suffix after creating a snapshot module, such as
// vendorSnapshotSharedSuffix, recoverySnapshotBinarySuffix, etc.
-func (p *baseSnapshotDecorator) init(m *Module, suffix string) {
- p.baseProperties.Module_suffix = suffix
+func (p *baseSnapshotDecorator) init(m *Module, snapshotSuffix, moduleSuffix string) {
+ p.baseProperties.ModuleSuffix = snapshotSuffix + moduleSuffix
m.AddProperties(&p.baseProperties)
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
vendorSnapshotLoadHook(ctx, p)
@@ -542,7 +482,6 @@
// Library flags for cfi variant.
Cfi snapshotLibraryProperties `android:"arch_variant"`
}
- androidMkSuffix string
}
func (p *snapshotLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
@@ -565,14 +504,6 @@
// As snapshots are prebuilts, this just returns the prebuilt binary after doing things which are
// done by normal library decorator, e.g. exporting flags.
func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path {
- m := ctx.Module().(*Module)
-
- if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] {
- p.androidMkSuffix = vendorSuffix
- } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] {
- p.androidMkSuffix = recoverySuffix
- }
-
if p.header() {
return p.libraryDecorator.link(ctx, flags, deps, objs)
}
@@ -655,7 +586,7 @@
}
}
-func snapshotLibraryFactory(suffix string) (*Module, *snapshotLibraryDecorator) {
+func snapshotLibraryFactory(snapshotSuffix, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
module, library := NewLibrary(android.DeviceSupported)
module.stl = nil
@@ -678,7 +609,7 @@
module.linker = prebuilt
module.installer = prebuilt
- prebuilt.init(module, suffix)
+ prebuilt.init(module, snapshotSuffix, moduleSuffix)
module.AddProperties(
&prebuilt.properties,
&prebuilt.sanitizerProperties,
@@ -692,7 +623,7 @@
// overrides the vendor variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
// is set.
func VendorSnapshotSharedFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(vendorSnapshotSharedSuffix)
+ module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotSharedSuffix)
prebuilt.libraryDecorator.BuildOnlyShared()
return module.Init()
}
@@ -702,7 +633,7 @@
// overrides the recovery variant of the cc shared library with the same name, if BOARD_VNDK_VERSION
// is set.
func RecoverySnapshotSharedFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(recoverySnapshotSharedSuffix)
+ module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotSharedSuffix)
prebuilt.libraryDecorator.BuildOnlyShared()
return module.Init()
}
@@ -712,7 +643,7 @@
// overrides the vendor variant of the cc static library with the same name, if BOARD_VNDK_VERSION
// is set.
func VendorSnapshotStaticFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(vendorSnapshotStaticSuffix)
+ module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotStaticSuffix)
prebuilt.libraryDecorator.BuildOnlyStatic()
return module.Init()
}
@@ -722,7 +653,7 @@
// overrides the recovery variant of the cc static library with the same name, if BOARD_VNDK_VERSION
// is set.
func RecoverySnapshotStaticFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(recoverySnapshotStaticSuffix)
+ module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotStaticSuffix)
prebuilt.libraryDecorator.BuildOnlyStatic()
return module.Init()
}
@@ -732,7 +663,7 @@
// overrides the vendor variant of the cc header library with the same name, if BOARD_VNDK_VERSION
// is set.
func VendorSnapshotHeaderFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(vendorSnapshotHeaderSuffix)
+ module, prebuilt := snapshotLibraryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotHeaderSuffix)
prebuilt.libraryDecorator.HeaderOnly()
return module.Init()
}
@@ -742,7 +673,7 @@
// overrides the recovery variant of the cc header library with the same name, if BOARD_VNDK_VERSION
// is set.
func RecoverySnapshotHeaderFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(recoverySnapshotHeaderSuffix)
+ module, prebuilt := snapshotLibraryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotHeaderSuffix)
prebuilt.libraryDecorator.HeaderOnly()
return module.Init()
}
@@ -764,8 +695,7 @@
type snapshotBinaryDecorator struct {
baseSnapshotDecorator
*binaryDecorator
- properties snapshotBinaryProperties
- androidMkSuffix string
+ properties snapshotBinaryProperties
}
func (p *snapshotBinaryDecorator) matchesWithDevice(config android.DeviceConfig) bool {
@@ -789,14 +719,6 @@
p.unstrippedOutputFile = in
binName := in.Base()
- m := ctx.Module().(*Module)
- if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] {
- p.androidMkSuffix = vendorSuffix
- } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] {
- p.androidMkSuffix = recoverySuffix
-
- }
-
// use cpExecutable to make it executable
outputFile := android.PathForModuleOut(ctx, binName)
ctx.Build(pctx, android.BuildParams{
@@ -817,17 +739,17 @@
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_binary
// overrides the vendor variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
func VendorSnapshotBinaryFactory() android.Module {
- return snapshotBinaryFactory(vendorSnapshotBinarySuffix)
+ return snapshotBinaryFactory(vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotBinarySuffix)
}
// recovery_snapshot_binary is a special prebuilt executable binary which is auto-generated by
// development/vendor_snapshot/update.py. As a part of recovery snapshot, recovery_snapshot_binary
// overrides the recovery variant of the cc binary with the same name, if BOARD_VNDK_VERSION is set.
func RecoverySnapshotBinaryFactory() android.Module {
- return snapshotBinaryFactory(recoverySnapshotBinarySuffix)
+ return snapshotBinaryFactory(recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotBinarySuffix)
}
-func snapshotBinaryFactory(suffix string) android.Module {
+func snapshotBinaryFactory(snapshotSuffix, moduleSuffix string) android.Module {
module, binary := NewBinary(android.DeviceSupported)
binary.baseLinker.Properties.No_libcrt = BoolPtr(true)
binary.baseLinker.Properties.Nocrt = BoolPtr(true)
@@ -846,7 +768,7 @@
module.stl = nil
module.linker = prebuilt
- prebuilt.init(module, suffix)
+ prebuilt.init(module, snapshotSuffix, moduleSuffix)
module.AddProperties(&prebuilt.properties)
return module.Init()
}
@@ -866,8 +788,7 @@
type snapshotObjectLinker struct {
baseSnapshotDecorator
objectLinker
- properties vendorSnapshotObjectProperties
- androidMkSuffix string
+ properties vendorSnapshotObjectProperties
}
func (p *snapshotObjectLinker) matchesWithDevice(config android.DeviceConfig) bool {
@@ -887,14 +808,6 @@
return nil
}
- m := ctx.Module().(*Module)
-
- if m.InVendor() && vendorSuffixModules(ctx.Config())[m.BaseModuleName()] {
- p.androidMkSuffix = vendorSuffix
- } else if m.InRecovery() && recoverySuffixModules(ctx.Config())[m.BaseModuleName()] {
- p.androidMkSuffix = recoverySuffix
- }
-
return android.PathForModuleSrc(ctx, *p.properties.Src)
}
@@ -915,7 +828,7 @@
}
module.linker = prebuilt
- prebuilt.init(module, vendorSnapshotObjectSuffix)
+ prebuilt.init(module, vendorSnapshotImageSingleton.moduleNameSuffix(), snapshotObjectSuffix)
module.AddProperties(&prebuilt.properties)
return module.Init()
}
@@ -933,130 +846,19 @@
}
module.linker = prebuilt
- prebuilt.init(module, recoverySnapshotObjectSuffix)
+ prebuilt.init(module, recoverySnapshotImageSingleton.moduleNameSuffix(), snapshotObjectSuffix)
module.AddProperties(&prebuilt.properties)
return module.Init()
}
type snapshotInterface interface {
matchesWithDevice(config android.DeviceConfig) bool
+ isSnapshotPrebuilt() bool
+ version() string
+ snapshotAndroidMkSuffix() string
}
var _ snapshotInterface = (*vndkPrebuiltLibraryDecorator)(nil)
var _ snapshotInterface = (*snapshotLibraryDecorator)(nil)
var _ snapshotInterface = (*snapshotBinaryDecorator)(nil)
var _ snapshotInterface = (*snapshotObjectLinker)(nil)
-
-//
-// Mutators that helps vendor snapshot modules override source modules.
-//
-
-// VendorSnapshotMutator gathers all snapshots for vendor, and disable all snapshots which don't
-// match with device, e.g.
-// - snapshot version is different with BOARD_VNDK_VERSION
-// - snapshot arch is different with device's arch (e.g. arm vs x86)
-//
-// This also handles vndk_prebuilt_shared, except for they won't be disabled in any cases, given
-// that any versions of VNDK might be packed into vndk APEX.
-//
-// TODO(b/145966707): remove mutator and utilize android.Prebuilt to override source modules
-func VendorSnapshotMutator(ctx android.BottomUpMutatorContext) {
- snapshotMutator(ctx, vendorSnapshotImageSingleton)
-}
-
-func RecoverySnapshotMutator(ctx android.BottomUpMutatorContext) {
- snapshotMutator(ctx, recoverySnapshotImageSingleton)
-}
-
-func snapshotMutator(ctx android.BottomUpMutatorContext, image snapshotImage) {
- if !image.isUsingSnapshot(ctx.DeviceConfig()) {
- return
- }
- module, ok := ctx.Module().(*Module)
- if !ok || !module.Enabled() {
- return
- }
- if image.skipModuleMutator(ctx) {
- return
- }
- if !module.isSnapshotPrebuilt() {
- return
- }
-
- // isSnapshotPrebuilt ensures snapshotInterface
- if !module.linker.(snapshotInterface).matchesWithDevice(ctx.DeviceConfig()) {
- // Disable unnecessary snapshot module, but do not disable
- // vndk_prebuilt_shared because they might be packed into vndk APEX
- if !module.IsVndk() {
- module.Disable()
- }
- return
- }
-
- var snapshotMap *snapshotMap = image.getSnapshotMap(module, ctx.Config())
- if snapshotMap == nil {
- return
- }
-
- mutex := image.getMutex()
- mutex.Lock()
- defer mutex.Unlock()
- snapshotMap.add(module.BaseModuleName(), ctx.Arch().ArchType, ctx.ModuleName())
-}
-
-// VendorSnapshotSourceMutator disables source modules which have corresponding snapshots.
-func VendorSnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
- snapshotSourceMutator(ctx, vendorSnapshotImageSingleton)
-}
-
-func RecoverySnapshotSourceMutator(ctx android.BottomUpMutatorContext) {
- snapshotSourceMutator(ctx, recoverySnapshotImageSingleton)
-}
-
-func snapshotSourceMutator(ctx android.BottomUpMutatorContext, image snapshotImage) {
- if !ctx.Device() {
- return
- }
- if !image.isUsingSnapshot(ctx.DeviceConfig()) {
- return
- }
-
- module, ok := ctx.Module().(*Module)
- if !ok {
- return
- }
-
- if image.shouldBeAddedToSuffixModules(module) {
- mutex := image.getMutex()
- mutex.Lock()
- defer mutex.Unlock()
-
- image.suffixModules(ctx.Config())[ctx.ModuleName()] = true
- }
-
- if module.isSnapshotPrebuilt() {
- return
- }
- if image.skipSourceMutator(ctx) {
- return
- }
-
- var snapshotMap *snapshotMap = image.getSnapshotMap(module, ctx.Config())
- if snapshotMap == nil {
- return
- }
-
- if _, ok := snapshotMap.get(ctx.ModuleName(), ctx.Arch().ArchType); !ok {
- // Corresponding snapshot doesn't exist
- return
- }
-
- // Disables source modules if corresponding snapshot exists.
- if lib, ok := module.linker.(libraryInterface); ok && lib.buildStatic() && lib.buildShared() {
- // But do not disable because the shared variant depends on the static variant.
- module.HideFromMake()
- module.Properties.HideFromMake = true
- } else {
- module.Disable()
- }
-}
diff --git a/cc/testing.go b/cc/testing.go
index dc9a59d..3a5bd17 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -586,17 +586,13 @@
ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
- ctx.RegisterModuleType("vendor_snapshot_shared", VendorSnapshotSharedFactory)
- ctx.RegisterModuleType("vendor_snapshot_static", VendorSnapshotStaticFactory)
- ctx.RegisterModuleType("vendor_snapshot_binary", VendorSnapshotBinaryFactory)
+ vendorSnapshotImageSingleton.init(ctx)
+ recoverySnapshotImageSingleton.init(ctx)
RegisterVndkLibraryTxtTypes(ctx)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
android.RegisterPrebuiltMutators(ctx)
RegisterRequiredBuildComponentsForTest(ctx)
ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
- ctx.RegisterSingletonType("vendor-snapshot", VendorSnapshotSingleton)
- ctx.RegisterSingletonType("vendor-fake-snapshot", VendorFakeSnapshotSingleton)
- ctx.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
return ctx
}
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 7346aac..35fc1c1 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -291,6 +291,7 @@
type snapshotJsonFlags struct {
ModuleName string `json:",omitempty"`
RelativeInstallPath string `json:",omitempty"`
+ AndroidMkSuffix string `json:",omitempty"`
// library flags
ExportedDirs []string `json:",omitempty"`
@@ -403,6 +404,7 @@
} else {
prop.RelativeInstallPath = m.RelativeInstallPath()
}
+ prop.AndroidMkSuffix = m.Properties.SubName
prop.RuntimeLibs = m.Properties.SnapshotRuntimeLibs
prop.Required = m.RequiredModuleNames()
for _, path := range m.InitRc() {
diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go
index cce28b0..499d7ae 100644
--- a/cc/vendor_snapshot_test.go
+++ b/cc/vendor_snapshot_test.go
@@ -329,6 +329,24 @@
},
},
}
+
+ // old snapshot module which has to be ignored
+ vndk_prebuilt_shared {
+ name: "libvndk",
+ version: "OLD",
+ target_arch: "arm64",
+ vendor_available: true,
+ product_available: true,
+ vndk: {
+ enabled: true,
+ },
+ arch: {
+ arm64: {
+ srcs: ["libvndk.so"],
+ export_include_dirs: ["include/libvndk"],
+ },
+ },
+ }
`
vendorProprietaryBp := `
@@ -367,6 +385,27 @@
srcs: ["bin.cpp"],
}
+ vendor_snapshot {
+ name: "vendor_snapshot",
+ compile_multilib: "first",
+ version: "BOARD",
+ vndk_libs: [
+ "libvndk",
+ ],
+ static_libs: [
+ "libvendor",
+ "libvendor_available",
+ "libvndk",
+ ],
+ shared_libs: [
+ "libvendor",
+ "libvendor_available",
+ ],
+ binaries: [
+ "bin",
+ ],
+ }
+
vendor_snapshot_static {
name: "libvndk",
version: "BOARD",
@@ -408,6 +447,7 @@
vendor_snapshot_shared {
name: "libvendor_available",
+ androidmk_suffix: ".vendor",
version: "BOARD",
target_arch: "arm64",
vendor: true,
@@ -421,6 +461,7 @@
vendor_snapshot_static {
name: "libvendor_available",
+ androidmk_suffix: ".vendor",
version: "BOARD",
target_arch: "arm64",
vendor: true,
@@ -443,6 +484,19 @@
},
},
}
+
+ // old snapshot module which has to be ignored
+ vendor_snapshot_binary {
+ name: "bin",
+ version: "OLD",
+ target_arch: "arm64",
+ vendor: true,
+ arch: {
+ arm64: {
+ src: "bin",
+ },
+ },
+ }
`
depsBp := GatherRequiredDepsForTest(android.Android)
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index 04162cd..71e6427 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -107,6 +107,10 @@
return "64"
}
+func (p *vndkPrebuiltLibraryDecorator) snapshotAndroidMkSuffix() string {
+ return ".vendor"
+}
+
func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
return p.libraryDecorator.linkerFlags(ctx, flags)
diff --git a/cmd/soong_build/queryview.go b/cmd/soong_build/queryview.go
index 5d61d0c..dc0b323 100644
--- a/cmd/soong_build/queryview.go
+++ b/cmd/soong_build/queryview.go
@@ -24,7 +24,7 @@
func createBazelQueryView(ctx *android.Context, bazelQueryViewDir string) error {
ruleShims := bp2build.CreateRuleShims(android.ModuleTypeFactories())
- buildToTargets := bp2build.GenerateSoongModuleTargets(*ctx, bp2build.QueryView)
+ buildToTargets := bp2build.GenerateBazelTargets(*ctx, bp2build.QueryView)
filesToWrite := bp2build.CreateBazelFiles(ruleShims, buildToTargets, bp2build.QueryView)
for _, f := range filesToWrite {
diff --git a/filesystem/Android.bp b/filesystem/Android.bp
index 926df6e..9994241 100644
--- a/filesystem/Android.bp
+++ b/filesystem/Android.bp
@@ -7,6 +7,7 @@
"soong-android",
],
srcs: [
+ "bootimg.go",
"filesystem.go",
],
testSrcs: [
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
new file mode 100644
index 0000000..4bc1823
--- /dev/null
+++ b/filesystem/bootimg.go
@@ -0,0 +1,222 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package filesystem
+
+import (
+ "fmt"
+ "strconv"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+)
+
+func init() {
+ android.RegisterModuleType("bootimg", bootimgFactory)
+}
+
+type bootimg struct {
+ android.ModuleBase
+
+ properties bootimgProperties
+
+ output android.OutputPath
+ installDir android.InstallPath
+}
+
+type bootimgProperties struct {
+ // Path to the linux kernel prebuilt file
+ Kernel_prebuilt *string `android:"arch_variant,path"`
+
+ // Filesystem module that is used as ramdisk
+ Ramdisk_module *string
+
+ // Path to the device tree blob (DTB) prebuilt file to add to this boot image
+ Dtb_prebuilt *string `android:"arch_variant,path"`
+
+ // Header version number. Must be set to one of the version numbers that are currently
+ // supported. Refer to
+ // https://source.android.com/devices/bootloader/boot-image-header
+ Header_version *string
+
+ // Determines if this image is for the vendor_boot partition. Default is false. Refer to
+ // https://source.android.com/devices/bootloader/partitions/vendor-boot-partitions
+ Vendor_boot *bool
+
+ // Optional kernel commandline
+ Cmdline *string
+
+ // When set to true, sign the image with avbtool. Default is false.
+ Use_avb *bool
+
+ // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
+ Partition_name *string
+
+ // Path to the private key that avbtool will use to sign this filesystem image.
+ // TODO(jiyong): allow apex_key to be specified here
+ Avb_private_key *string `android:"path"`
+
+ // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
+ Avb_algorithm *string
+}
+
+// bootimg is the image for the boot partition. It consists of header, kernel, ramdisk, and dtb.
+func bootimgFactory() android.Module {
+ module := &bootimg{}
+ module.AddProperties(&module.properties)
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ return module
+}
+
+type bootimgDep struct {
+ blueprint.BaseDependencyTag
+ kind string
+}
+
+var bootimgRamdiskDep = bootimgDep{kind: "ramdisk"}
+
+func (b *bootimg) DepsMutator(ctx android.BottomUpMutatorContext) {
+ ramdisk := proptools.String(b.properties.Ramdisk_module)
+ if ramdisk != "" {
+ ctx.AddDependency(ctx.Module(), bootimgRamdiskDep, ramdisk)
+ }
+}
+
+func (b *bootimg) installFileName() string {
+ return b.BaseModuleName() + ".img"
+}
+
+func (b *bootimg) partitionName() string {
+ return proptools.StringDefault(b.properties.Partition_name, b.BaseModuleName())
+}
+
+func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ var unsignedOutput android.OutputPath
+ if proptools.Bool(b.properties.Vendor_boot) {
+ unsignedOutput = b.buildVendorBootImage(ctx)
+ } else {
+ // TODO(jiyong): fix this
+ ctx.PropertyErrorf("vendor_boot", "only vendor_boot:true is supported")
+ }
+
+ if proptools.Bool(b.properties.Use_avb) {
+ b.output = b.signImage(ctx, unsignedOutput)
+ } else {
+ b.output = unsignedOutput
+ }
+
+ b.installDir = android.PathForModuleInstall(ctx, "etc")
+ ctx.InstallFile(b.installDir, b.installFileName(), b.output)
+}
+
+func (b *bootimg) buildVendorBootImage(ctx android.ModuleContext) android.OutputPath {
+ output := android.PathForModuleOut(ctx, "unsigned.img").OutputPath
+ builder := android.NewRuleBuilder(pctx, ctx)
+ cmd := builder.Command().BuiltTool("mkbootimg")
+
+ kernel := android.OptionalPathForModuleSrc(ctx, b.properties.Kernel_prebuilt)
+ if kernel.Valid() {
+ ctx.PropertyErrorf("kernel_prebuilt", "vendor_boot partition can't have kernel")
+ return output
+ }
+
+ dtbName := proptools.String(b.properties.Dtb_prebuilt)
+ if dtbName == "" {
+ ctx.PropertyErrorf("dtb_prebuilt", "must be set")
+ return output
+ }
+ dtb := android.PathForModuleSrc(ctx, dtbName)
+ cmd.FlagWithInput("--dtb ", dtb)
+
+ cmdline := proptools.String(b.properties.Cmdline)
+ if cmdline != "" {
+ cmd.FlagWithArg("--vendor_cmdline ", "\""+cmdline+"\"")
+ }
+
+ headerVersion := proptools.String(b.properties.Header_version)
+ if headerVersion == "" {
+ ctx.PropertyErrorf("header_version", "must be set")
+ return output
+ }
+ verNum, err := strconv.Atoi(headerVersion)
+ if err != nil {
+ ctx.PropertyErrorf("header_version", "%q is not a number", headerVersion)
+ return output
+ }
+ if verNum < 3 {
+ ctx.PropertyErrorf("header_version", "must be 3 or higher for vendor_boot")
+ return output
+ }
+ cmd.FlagWithArg("--header_version ", headerVersion)
+
+ ramdiskName := proptools.String(b.properties.Ramdisk_module)
+ if ramdiskName == "" {
+ ctx.PropertyErrorf("ramdisk_module", "must be set")
+ return output
+ }
+ ramdisk := ctx.GetDirectDepWithTag(ramdiskName, bootimgRamdiskDep)
+ if filesystem, ok := ramdisk.(*filesystem); ok {
+ cmd.FlagWithInput("--vendor_ramdisk ", filesystem.OutputPath())
+ } else {
+ ctx.PropertyErrorf("ramdisk", "%q is not android_filesystem module", ramdisk.Name())
+ return output
+ }
+
+ cmd.FlagWithOutput("--vendor_boot ", output)
+
+ builder.Build("build_vendor_bootimg", fmt.Sprintf("Creating %s", b.BaseModuleName()))
+ return output
+}
+
+func (b *bootimg) signImage(ctx android.ModuleContext, unsignedImage android.OutputPath) android.OutputPath {
+ signedImage := android.PathForModuleOut(ctx, "signed.img").OutputPath
+ key := android.PathForModuleSrc(ctx, proptools.String(b.properties.Avb_private_key))
+
+ builder := android.NewRuleBuilder(pctx, ctx)
+ builder.Command().Text("cp").Input(unsignedImage).Output(signedImage)
+ builder.Command().
+ BuiltTool("avbtool").
+ Flag("add_hash_footer").
+ FlagWithArg("--partition_name ", b.partitionName()).
+ FlagWithInput("--key ", key).
+ FlagWithOutput("--image ", signedImage)
+
+ builder.Build("sign_bootimg", fmt.Sprintf("Signing %s", b.BaseModuleName()))
+
+ return signedImage
+}
+
+var _ android.AndroidMkEntriesProvider = (*bootimg)(nil)
+
+// Implements android.AndroidMkEntriesProvider
+func (b *bootimg) AndroidMkEntries() []android.AndroidMkEntries {
+ return []android.AndroidMkEntries{android.AndroidMkEntries{
+ Class: "ETC",
+ OutputFile: android.OptionalPathForPath(b.output),
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(entries *android.AndroidMkEntries) {
+ entries.SetString("LOCAL_MODULE_PATH", b.installDir.ToMakePath().String())
+ entries.SetString("LOCAL_INSTALLED_MODULE_STEM", b.installFileName())
+ },
+ },
+ }}
+}
+
+var _ Filesystem = (*bootimg)(nil)
+
+func (b *bootimg) OutputPath() android.Path {
+ return b.output
+}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 654617c..5092ad0 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -47,6 +47,10 @@
// Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
Avb_algorithm *string
+
+ // Type of the filesystem. Currently, ext4 and compressed_cpio are supported. Default is
+ // ext4.
+ Type *string
}
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
@@ -71,6 +75,27 @@
f.AddDeps(ctx, dependencyTag)
}
+type fsType int
+
+const (
+ ext4Type fsType = iota
+ compressedCpioType
+ unknown
+)
+
+func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
+ typeStr := proptools.StringDefault(f.properties.Type, "ext4")
+ switch typeStr {
+ case "ext4":
+ return ext4Type
+ case "compressed_cpio":
+ return compressedCpioType
+ default:
+ ctx.PropertyErrorf("type", "%q not supported", typeStr)
+ return unknown
+ }
+}
+
func (f *filesystem) installFileName() string {
return f.BaseModuleName() + ".img"
}
@@ -78,6 +103,20 @@
var pctx = android.NewPackageContext("android/soong/filesystem")
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ switch f.fsType(ctx) {
+ case ext4Type:
+ f.output = f.buildImageUsingBuildImage(ctx)
+ case compressedCpioType:
+ f.output = f.buildCompressedCpioImage(ctx)
+ default:
+ return
+ }
+
+ f.installDir = android.PathForModuleInstall(ctx, "etc")
+ ctx.InstallFile(f.installDir, f.installFileName(), f.output)
+}
+
+func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
f.CopyDepsToZip(ctx, zipFile)
@@ -89,19 +128,18 @@
Input(zipFile)
propFile, toolDeps := f.buildPropFile(ctx)
- f.output = android.PathForModuleOut(ctx, f.installFileName()).OutputPath
+ output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
builder.Command().BuiltTool("build_image").
Text(rootDir.String()). // input directory
Input(propFile).
Implicits(toolDeps).
- Output(f.output).
+ Output(output).
Text(rootDir.String()) // directory where to find fs_config_files|dirs
// rootDir is not deleted. Might be useful for quick inspection.
builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
- f.installDir = android.PathForModuleInstall(ctx, "etc")
- ctx.InstallFile(f.installDir, f.installFileName(), f.output)
+ return output
}
func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
@@ -120,8 +158,17 @@
deps = append(deps, path)
}
- // TODO(jiyong): support more filesystem types other than ext4
- addStr("fs_type", "ext4")
+ // Type string that build_image.py accepts.
+ fsTypeStr := func(t fsType) string {
+ switch t {
+ // TODO(jiyong): add more types like f2fs, erofs, etc.
+ case ext4Type:
+ return "ext4"
+ }
+ panic(fmt.Errorf("unsupported fs type %v", t))
+ }
+
+ addStr("fs_type", fsTypeStr(f.fsType(ctx)))
addStr("mount_point", "system")
addStr("use_dynamic_partition_size", "true")
addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
@@ -154,6 +201,39 @@
return propFile, deps
}
+func (f *filesystem) buildCompressedCpioImage(ctx android.ModuleContext) android.OutputPath {
+ if proptools.Bool(f.properties.Use_avb) {
+ ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
+ "Consider adding this to bootimg module and signing the entire boot image.")
+ }
+
+ zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
+ f.CopyDepsToZip(ctx, zipFile)
+
+ rootDir := android.PathForModuleOut(ctx, "root").OutputPath
+ builder := android.NewRuleBuilder(pctx, ctx)
+ builder.Command().
+ BuiltTool("zipsync").
+ FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
+ Input(zipFile)
+
+ output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
+ builder.Command().
+ BuiltTool("mkbootfs").
+ Text(rootDir.String()). // input directory
+ Text("|").
+ BuiltTool("lz4").
+ Flag("--favor-decSpeed"). // for faster boot
+ Flag("-12"). // maximum compression level
+ Flag("-l"). // legacy format for kernel
+ Text(">").Output(output)
+
+ // rootDir is not deleted. Might be useful for quick inspection.
+ builder.Build("build_compressed_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
+
+ return output
+}
+
var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
// Implements android.AndroidMkEntriesProvider
diff --git a/java/rro.go b/java/rro.go
index 98cd379..aafa88e 100644
--- a/java/rro.go
+++ b/java/rro.go
@@ -55,7 +55,11 @@
// only when the ro.boot.vendor.overlay.theme system property is set to the same value.
Theme *string
- // if not blank, set to the version of the sdk to compile against.
+ // If not blank, set to the version of the sdk to compile against. This
+ // can be either an API version (e.g. "29" for API level 29 AKA Android 10)
+ // or special subsets of the current platform, for example "none", "current",
+ // "core", "system", "test". See build/soong/java/sdk.go for the full and
+ // up-to-date list of possible values.
// Defaults to compiling against the current platform.
Sdk_version *string
diff --git a/kernel/Android.bp b/kernel/Android.bp
new file mode 100644
index 0000000..f8a48d9
--- /dev/null
+++ b/kernel/Android.bp
@@ -0,0 +1,18 @@
+bootstrap_go_package {
+ name: "soong-kernel",
+ pkgPath: "android/soong/kernel",
+ deps: [
+ "blueprint",
+ "soong",
+ "soong-android",
+ "soong-cc",
+ "soong-cc-config",
+ ],
+ srcs: [
+ "prebuilt_kernel_modules.go",
+ ],
+ testSrcs: [
+ "prebuilt_kernel_modules_test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/kernel/prebuilt_kernel_modules.go b/kernel/prebuilt_kernel_modules.go
new file mode 100644
index 0000000..94e04cb
--- /dev/null
+++ b/kernel/prebuilt_kernel_modules.go
@@ -0,0 +1,166 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kernel
+
+import (
+ "fmt"
+ "path/filepath"
+ "strings"
+
+ "android/soong/android"
+ _ "android/soong/cc/config"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+)
+
+func init() {
+ android.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
+ pctx.Import("android/soong/cc/config")
+}
+
+type prebuiltKernelModules struct {
+ android.ModuleBase
+
+ properties prebuiltKernelModulesProperties
+
+ installDir android.InstallPath
+}
+
+type prebuiltKernelModulesProperties struct {
+ // List or filegroup of prebuilt kernel module files. Should have .ko suffix.
+ Srcs []string `android:"path,arch_variant"`
+
+ // Kernel version that these modules are for. Kernel modules are installed to
+ // /lib/modules/<kernel_version> directory in the corresponding partition. Default is "".
+ Kernel_version *string
+}
+
+// prebuilt_kernel_modules installs a set of prebuilt kernel module files to the correct directory.
+// In addition, this module builds modules.load, modules.dep, modules.softdep and modules.alias
+// using depmod and installs them as well.
+func prebuiltKernelModulesFactory() android.Module {
+ module := &prebuiltKernelModules{}
+ module.AddProperties(&module.properties)
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ return module
+}
+
+func (pkm *prebuiltKernelModules) KernelVersion() string {
+ return proptools.StringDefault(pkm.properties.Kernel_version, "")
+}
+
+func (pkm *prebuiltKernelModules) DepsMutator(ctx android.BottomUpMutatorContext) {
+ // do nothing
+}
+
+func (pkm *prebuiltKernelModules) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ modules := android.PathsForModuleSrc(ctx, pkm.properties.Srcs)
+
+ depmodOut := runDepmod(ctx, modules)
+ strippedModules := stripDebugSymbols(ctx, modules)
+
+ installDir := android.PathForModuleInstall(ctx, "lib", "module")
+ if pkm.KernelVersion() != "" {
+ installDir = installDir.Join(ctx, pkm.KernelVersion())
+ }
+
+ for _, m := range strippedModules {
+ ctx.InstallFile(installDir, filepath.Base(m.String()), m)
+ }
+ ctx.InstallFile(installDir, "modules.load", depmodOut.modulesLoad)
+ ctx.InstallFile(installDir, "modules.dep", depmodOut.modulesDep)
+ ctx.InstallFile(installDir, "modules.softdep", depmodOut.modulesSoftdep)
+ ctx.InstallFile(installDir, "modules.alias", depmodOut.modulesAlias)
+}
+
+var (
+ pctx = android.NewPackageContext("android/soong/kernel")
+
+ stripRule = pctx.AndroidStaticRule("strip",
+ blueprint.RuleParams{
+ Command: "$stripCmd -o $out --strip-debug $in",
+ CommandDeps: []string{"$stripCmd"},
+ }, "stripCmd")
+)
+
+func stripDebugSymbols(ctx android.ModuleContext, modules android.Paths) android.OutputPaths {
+ dir := android.PathForModuleOut(ctx, "stripped").OutputPath
+ var outputs android.OutputPaths
+
+ for _, m := range modules {
+ stripped := dir.Join(ctx, filepath.Base(m.String()))
+ ctx.Build(pctx, android.BuildParams{
+ Rule: stripRule,
+ Input: m,
+ Output: stripped,
+ Args: map[string]string{
+ "stripCmd": "${config.ClangBin}/llvm-strip",
+ },
+ })
+ outputs = append(outputs, stripped)
+ }
+
+ return outputs
+}
+
+type depmodOutputs struct {
+ modulesLoad android.OutputPath
+ modulesDep android.OutputPath
+ modulesSoftdep android.OutputPath
+ modulesAlias android.OutputPath
+}
+
+func runDepmod(ctx android.ModuleContext, modules android.Paths) depmodOutputs {
+ baseDir := android.PathForModuleOut(ctx, "depmod").OutputPath
+ fakeVer := "0.0" // depmod demands this anyway
+ modulesDir := baseDir.Join(ctx, "lib", "modules", fakeVer)
+
+ builder := android.NewRuleBuilder(pctx, ctx)
+
+ // Copy the module files to a temporary dir
+ builder.Command().Text("rm").Flag("-rf").Text(modulesDir.String())
+ builder.Command().Text("mkdir").Flag("-p").Text(modulesDir.String())
+ for _, m := range modules {
+ builder.Command().Text("cp").Input(m).Text(modulesDir.String())
+ }
+
+ // Enumerate modules to load
+ modulesLoad := modulesDir.Join(ctx, "modules.load")
+ var basenames []string
+ for _, m := range modules {
+ basenames = append(basenames, filepath.Base(m.String()))
+ }
+ builder.Command().
+ Text("echo").Flag("\"" + strings.Join(basenames, " ") + "\"").
+ Text("|").Text("tr").Flag("\" \"").Flag("\"\\n\"").
+ Text(">").Output(modulesLoad)
+
+ // Run depmod to build modules.dep/softdep/alias files
+ modulesDep := modulesDir.Join(ctx, "modules.dep")
+ modulesSoftdep := modulesDir.Join(ctx, "modules.softdep")
+ modulesAlias := modulesDir.Join(ctx, "modules.alias")
+ builder.Command().
+ BuiltTool("depmod").
+ FlagWithArg("-b ", baseDir.String()).
+ Text(fakeVer).
+ ImplicitOutput(modulesDep).
+ ImplicitOutput(modulesSoftdep).
+ ImplicitOutput(modulesAlias)
+
+ builder.Build("depmod", fmt.Sprintf("depmod %s", ctx.ModuleName()))
+
+ return depmodOutputs{modulesLoad, modulesDep, modulesSoftdep, modulesAlias}
+}
diff --git a/kernel/prebuilt_kernel_modules_test.go b/kernel/prebuilt_kernel_modules_test.go
new file mode 100644
index 0000000..b49e167
--- /dev/null
+++ b/kernel/prebuilt_kernel_modules_test.go
@@ -0,0 +1,129 @@
+// Copyright 2021 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kernel
+
+import (
+ "io/ioutil"
+ "os"
+ "reflect"
+ "strings"
+ "testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+)
+
+func testKernelModules(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
+ bp = bp + `
+ cc_binary_host {
+ name: "depmod",
+ srcs: ["depmod.cpp"],
+ stl: "none",
+ static_executable: true,
+ system_shared_libs: [],
+ }
+ `
+ bp = bp + cc.GatherRequiredDepsForTest(android.Android)
+
+ fs["depmod.cpp"] = nil
+ cc.GatherRequiredFilesForTest(fs)
+
+ config := android.TestArchConfig(buildDir, nil, bp, fs)
+
+ ctx := android.NewTestArchContext(config)
+ ctx.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
+ ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
+ cc.RegisterRequiredBuildComponentsForTest(ctx)
+
+ ctx.Register()
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ android.FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ android.FailIfErrored(t, errs)
+
+ return ctx, config
+}
+
+func ensureListContains(t *testing.T, result []string, expected string) {
+ t.Helper()
+ if !android.InList(expected, result) {
+ t.Errorf("%q is not found in %v", expected, result)
+ }
+}
+
+func ensureContains(t *testing.T, result string, expected string) {
+ t.Helper()
+ if !strings.Contains(result, expected) {
+ t.Errorf("%q is not found in %q", expected, result)
+ }
+}
+
+func TestKernelModulesFilelist(t *testing.T) {
+ ctx, _ := testKernelModules(t, `
+ prebuilt_kernel_modules {
+ name: "foo",
+ srcs: ["*.ko"],
+ kernel_version: "5.10",
+ }
+ `,
+ map[string][]byte{
+ "mod1.ko": nil,
+ "mod2.ko": nil,
+ })
+
+ expected := []string{
+ "lib/module/5.10/mod1.ko",
+ "lib/module/5.10/mod2.ko",
+ "lib/module/5.10/modules.load",
+ "lib/module/5.10/modules.dep",
+ "lib/module/5.10/modules.softdep",
+ "lib/module/5.10/modules.alias",
+ }
+
+ var actual []string
+ for _, ps := range ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().PackagingSpecs() {
+ actual = append(actual, ps.RelPathInPackage())
+ }
+ actual = android.SortedUniqueStrings(actual)
+ expected = android.SortedUniqueStrings(expected)
+ if !reflect.DeepEqual(actual, expected) {
+ t.Errorf("\ngot: %v\nexpected: %v\n", actual, expected)
+ }
+}
+
+var buildDir string
+
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "soong_kernel_test")
+ if err != nil {
+ panic(err)
+ }
+}
+
+func tearDown() {
+ os.RemoveAll(buildDir)
+}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}
diff --git a/rust/config/global.go b/rust/config/global.go
index fb62278..182dc6a 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -47,6 +47,8 @@
"-C debuginfo=2",
"-C opt-level=3",
"-C relocation-model=pic",
+ // Use v0 mangling to distinguish from C++ symbols
+ "-Z symbol-mangling-version=v0",
}
deviceGlobalRustFlags = []string{