Merge "Do not propagate transitive required deps of apexes" into main
diff --git a/android/module.go b/android/module.go
index 3bf4f0c..67dab4f 100644
--- a/android/module.go
+++ b/android/module.go
@@ -117,6 +117,7 @@
HostRequiredModuleNames() []string
TargetRequiredModuleNames() []string
VintfFragmentModuleNames(ctx ConfigurableEvaluatorContext) []string
+ VintfFragments(ctx ConfigurableEvaluatorContext) []string
ConfigurableEvaluator(ctx ConfigurableEvaluatorContext) proptools.ConfigurableEvaluator
@@ -1384,6 +1385,8 @@
}
} else if m.InstallInRamdisk() {
partition = "ramdisk"
+ } else if m.InstallInVendorRamdisk() {
+ partition = "vendor_ramdisk"
}
return partition
}
@@ -1626,6 +1629,10 @@
return m.base().commonProperties.Vintf_fragment_modules.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)
}
+func (m *ModuleBase) VintfFragments(ctx ConfigurableEvaluatorContext) []string {
+ return m.base().commonProperties.Vintf_fragments.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)
+}
+
func (m *ModuleBase) generateVariantTarget(ctx *moduleContext) {
namespacePrefix := ctx.Namespace().id
if namespacePrefix != "" {
diff --git a/android/module_proxy.go b/android/module_proxy.go
index 1f96799..30459b9 100644
--- a/android/module_proxy.go
+++ b/android/module_proxy.go
@@ -9,6 +9,8 @@
module blueprint.ModuleProxy
}
+var _ Module = (*ModuleProxy)(nil)
+
func (m ModuleProxy) Name() string {
return m.module.Name()
}
@@ -225,3 +227,7 @@
func (m ModuleProxy) Overrides() []string {
panic("method is not implemented on ModuleProxy")
}
+
+func (m ModuleProxy) VintfFragments(ctx ConfigurableEvaluatorContext) []string {
+ panic("method is not implemented on ModuleProxy")
+}
diff --git a/android/neverallow.go b/android/neverallow.go
index 2215504..b55baae 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -64,6 +64,7 @@
AddNeverAllowRules(createFilesystemIsAutoGeneratedRule())
AddNeverAllowRules(createKotlinPluginRule()...)
AddNeverAllowRules(createPrebuiltEtcBpDefineRule())
+ AddNeverAllowRules(createAutogenRroBpDefineRule())
}
// Add a NeverAllow rule to the set of rules to apply.
@@ -345,6 +346,15 @@
Because("module type not allowed to be defined in bp file")
}
+func createAutogenRroBpDefineRule() Rule {
+ return NeverAllow().
+ ModuleType(
+ "autogen_runtime_resource_overlay",
+ ).
+ DefinedInBpFile().
+ Because("Module type will be autogenerated by soong. Use runtime_resource_overlay instead")
+}
+
func neverallowMutator(ctx BottomUpMutatorContext) {
m, ok := ctx.Module().(Module)
if !ok {
diff --git a/android/variable.go b/android/variable.go
index 36ddc1c..50d1fcd 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -629,6 +629,8 @@
InitBootSecurityPatch string `json:",omitempty"`
BoardIncludeDtbInBootimg bool `json:",omitempty"`
InternalKernelCmdline []string `json:",omitempty"`
+ InternalBootconfig []string `json:",omitempty"`
+ InternalBootconfigFile string `json:",omitempty"`
// Avb (android verified boot) stuff
BoardAvbEnable bool `json:",omitempty"`
@@ -658,6 +660,10 @@
BuildingOdmDlkmImage bool `json:",omitempty"`
OdmKernelModules []string `json:",omitempty"`
OdmKernelBlocklistFile string `json:",omitempty"`
+
+ VendorRamdiskKernelModules []string `json:",omitempty"`
+ VendorRamdiskKernelBlocklistFile string `json:",omitempty"`
+ VendorRamdiskKernelLoadModules []string `json:",omitempty"`
}
func boolPtr(v bool) *bool {
diff --git a/apex/apex.go b/apex/apex.go
index 6611fbf..72a0455 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1752,7 +1752,13 @@
}
func (a *apexBundle) isCompressable() bool {
- return proptools.BoolDefault(a.overridableProperties.Compressible, false) && !a.testApex
+ if a.testApex {
+ return false
+ }
+ if a.payloadFsType == erofs {
+ return false
+ }
+ return proptools.Bool(a.overridableProperties.Compressible)
}
func (a *apexBundle) commonBuildActions(ctx android.ModuleContext) bool {
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 423288a..6cdb225 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -9054,6 +9054,33 @@
ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n")
}
+func TestCompressedApexIsDisabledWhenUsingErofs(t *testing.T) {
+ t.Parallel()
+ ctx := testApex(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ compressible: true,
+ updatable: false,
+ payload_fs_type: "erofs",
+ }
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+ `,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.CompressedApex = proptools.BoolPtr(true)
+ }),
+ )
+
+ compressRule := ctx.ModuleForTests("myapex", "android_common_myapex").MaybeRule("compressRule")
+ if compressRule.Rule != nil {
+ t.Error("erofs apex should not be compressed")
+ }
+}
+
func TestApexSet_ShouldRespectCompressedApexFlag(t *testing.T) {
t.Parallel()
for _, compressionEnabled := range []bool{true, false} {
diff --git a/cc/config/global.go b/cc/config/global.go
index 27aac95..dcc7719 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -238,6 +238,7 @@
// opting into the warning.
noOverrideGlobalCflags = []string{
"-Werror=bool-operation",
+ "-Werror=dangling",
"-Werror=format-insufficient-args",
"-Werror=implicit-int-float-conversion",
"-Werror=int-in-bool-context",
diff --git a/filesystem/Android.bp b/filesystem/Android.bp
index 23ec3da..bbb3ea7 100644
--- a/filesystem/Android.bp
+++ b/filesystem/Android.bp
@@ -20,6 +20,7 @@
"avb_add_hash_footer.go",
"avb_gen_vbmeta_image.go",
"bootimg.go",
+ "bootconfig.go",
"filesystem.go",
"fsverity_metadata.go",
"logical_partition.go",
diff --git a/filesystem/bootconfig.go b/filesystem/bootconfig.go
new file mode 100644
index 0000000..b125824
--- /dev/null
+++ b/filesystem/bootconfig.go
@@ -0,0 +1,80 @@
+// Copyright 2024 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 filesystem
+
+import (
+ "android/soong/android"
+ "strings"
+
+ "github.com/google/blueprint/proptools"
+)
+
+func init() {
+ android.RegisterModuleType("bootconfig", BootconfigModuleFactory)
+ pctx.Import("android/soong/android")
+}
+
+type bootconfigProperty struct {
+ // List of bootconfig parameters that will be written as a line separated list in the output
+ // file.
+ Boot_config []string
+ // Path to the file that contains the list of bootconfig parameters. This will be appended
+ // to the output file, after the entries in boot_config.
+ Boot_config_file *string `android:"path"`
+}
+
+type BootconfigModule struct {
+ android.ModuleBase
+
+ properties bootconfigProperty
+}
+
+// bootconfig module generates the `vendor-bootconfig.img` file, which lists the bootconfig
+// parameters and can be passed as a `--vendor_bootconfig` value in mkbootimg invocation.
+func BootconfigModuleFactory() android.Module {
+ module := &BootconfigModule{}
+ module.AddProperties(&module.properties)
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
+ return module
+}
+
+func (m *BootconfigModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ bootConfig := m.properties.Boot_config
+ bootConfigFileStr := proptools.String(m.properties.Boot_config_file)
+ if len(bootConfig) == 0 && len(bootConfigFileStr) == 0 {
+ return
+ }
+
+ var bootConfigFile android.Path
+ if len(bootConfigFileStr) > 0 {
+ bootConfigFile = android.PathForModuleSrc(ctx, bootConfigFileStr)
+ }
+
+ outputPath := android.PathForModuleOut(ctx, ctx.ModuleName(), "vendor-bootconfig.img")
+ bootConfigOutput := android.PathForModuleOut(ctx, ctx.ModuleName(), "bootconfig.txt")
+ android.WriteFileRule(ctx, bootConfigOutput, strings.Join(bootConfig, "\n"))
+
+ bcFiles := android.Paths{bootConfigOutput}
+ if bootConfigFile != nil {
+ bcFiles = append(bcFiles, bootConfigFile)
+ }
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cat,
+ Description: "concatenate bootconfig parameters",
+ Inputs: bcFiles,
+ Output: outputPath,
+ })
+ ctx.SetOutputFiles(android.Paths{outputPath}, "")
+}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index dadacae..5b217ae 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -71,6 +71,10 @@
// For example, GSI system.img contains system_ext and product artifacts and their
// relPathInPackage need to be rebased to system/system_ext and system/system_product.
ModifyPackagingSpec(spec *android.PackagingSpec)
+
+ // Function to check if the filesystem should not use `vintf_fragments` property,
+ // but use `vintf_fragment` module type instead
+ ShouldUseVintfFragmentModuleOnly() bool
}
var _ filesystemBuilder = (*filesystem)(nil)
@@ -343,6 +347,9 @@
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
validatePartitionType(ctx, f)
+ if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() {
+ f.validateVintfFragments(ctx)
+ }
switch f.fsType(ctx) {
case ext4Type, erofsType, f2fsType:
f.output = f.buildImageUsingBuildImage(ctx)
@@ -371,6 +378,43 @@
}
}
+func (f *filesystem) validateVintfFragments(ctx android.ModuleContext) {
+ visitedModule := map[string]bool{}
+ packagingSpecs := f.gatherFilteredPackagingSpecs(ctx)
+
+ moduleInFileSystem := func(mod android.Module) bool {
+ for _, ps := range android.OtherModuleProviderOrDefault(
+ ctx, mod, android.InstallFilesProvider).PackagingSpecs {
+ if _, ok := packagingSpecs[ps.RelPathInPackage()]; ok {
+ return true
+ }
+ }
+ return false
+ }
+
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ if visitedModule[child.Name()] {
+ return false
+ }
+ if !moduleInFileSystem(child) {
+ visitedModule[child.Name()] = true
+ return true
+ }
+ if vintfFragments := child.VintfFragments(ctx); vintfFragments != nil {
+ ctx.PropertyErrorf(
+ "vintf_fragments",
+ "Module %s is referenced by soong-defined filesystem %s with property vintf_fragments(%s) in use."+
+ " Use vintf_fragment_modules property instead.",
+ child.Name(),
+ f.BaseModuleName(),
+ strings.Join(vintfFragments, ", "),
+ )
+ }
+ visitedModule[child.Name()] = true
+ return true
+ })
+}
+
func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) {
partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/"
@@ -594,6 +638,13 @@
addStr("hash_seed", uuid)
}
+ // TODO(b/381120092): This should only be added if none of the size-related properties are set,
+ // but currently soong built partitions don't have size properties. Make code:
+ // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2262;drc=39cd33701c9278db0e7e481a090605f428d5b12d
+ // Make uses system_disable_sparse but disable_sparse has the same effect, and we shouldn't need
+ // to qualify it because each partition gets its own property file built.
+ addStr("disable_sparse", "true")
+
fst := f.fsType(ctx)
switch fst {
case erofsType:
@@ -779,6 +830,10 @@
f.appendToEntry(ctx, output)
}
+func (f *filesystem) ShouldUseVintfFragmentModuleOnly() bool {
+ return false
+}
+
type partition interface {
PartitionType() string
}
diff --git a/filesystem/system_image.go b/filesystem/system_image.go
index d03eab4..60a5133 100644
--- a/filesystem/system_image.go
+++ b/filesystem/system_image.go
@@ -63,3 +63,7 @@
(ps.Partition() == "system" || ps.Partition() == "root" ||
strings.HasPrefix(ps.Partition(), "system/"))
}
+
+func (s *systemImage) ShouldUseVintfFragmentModuleOnly() bool {
+ return true
+}
diff --git a/fsgen/boot_imgs.go b/fsgen/boot_imgs.go
index 799dbc9..4e80720 100644
--- a/fsgen/boot_imgs.go
+++ b/fsgen/boot_imgs.go
@@ -104,6 +104,11 @@
cmdline := partitionVariables.InternalKernelCmdline
+ var vendorBootConfigImg *string
+ if name, ok := createVendorBootConfigImg(ctx); ok {
+ vendorBootConfigImg = proptools.StringPtr(":" + name)
+ }
+
ctx.CreateModule(
filesystem.BootimgFactory,
&filesystem.BootimgProperties{
@@ -117,6 +122,7 @@
Avb_algorithm: avbInfo.avbAlgorithm,
Dtb_prebuilt: dtbPrebuilt,
Cmdline: cmdline,
+ Bootconfig: vendorBootConfigImg,
},
&struct {
Name *string
@@ -283,3 +289,29 @@
}
return dtbImg{include: false}
}
+
+func createVendorBootConfigImg(ctx android.LoadHookContext) (string, bool) {
+ partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
+ bootconfig := partitionVars.InternalBootconfig
+ bootconfigFile := partitionVars.InternalBootconfigFile
+ if len(bootconfig) == 0 && len(bootconfigFile) == 0 {
+ return "", false
+ }
+
+ vendorBootconfigImgModuleName := generatedModuleName(ctx.Config(), "vendor_bootconfig_image")
+
+ ctx.CreateModule(
+ filesystem.BootconfigModuleFactory,
+ &struct {
+ Name *string
+ Boot_config []string
+ Boot_config_file *string
+ }{
+ Name: proptools.StringPtr(vendorBootconfigImgModuleName),
+ Boot_config: bootconfig,
+ Boot_config_file: proptools.StringPtr(bootconfigFile),
+ },
+ )
+
+ return vendorBootconfigImgModuleName, true
+}
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index e8b0a4f..556c4dc 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -222,9 +222,80 @@
"framework/oat/*/*", // framework/oat/{arch}
}
fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
+ // Most of the symlinks and directories listed here originate from create_root_structure.mk,
+ // but the handwritten generic system image also recreates them:
+ // https://cs.android.com/android/platform/superproject/main/+/main:build/make/target/product/generic/Android.bp;l=33;drc=db08311f1b6ef6cb0a4fbcc6263b89849360ce04
// TODO(b/377734331): only generate the symlinks if the relevant partitions exist
fsProps.Symlinks = []filesystem.SymlinkDefinition{
filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/system/bin/init"),
+ Name: proptools.StringPtr("init"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/system/etc"),
+ Name: proptools.StringPtr("etc"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/system/bin"),
+ Name: proptools.StringPtr("bin"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/data/user_de/0/com.android.shell/files/bugreports"),
+ Name: proptools.StringPtr("bugreports"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/sys/kernel/debug"),
+ Name: proptools.StringPtr("d"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/storage/self/primary"),
+ Name: proptools.StringPtr("sdcard"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/product/etc/security/adb_keys"),
+ Name: proptools.StringPtr("adb_keys"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/app"),
+ Name: proptools.StringPtr("odm/app"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/bin"),
+ Name: proptools.StringPtr("odm/bin"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/etc"),
+ Name: proptools.StringPtr("odm/etc"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/firmware"),
+ Name: proptools.StringPtr("odm/firmware"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/framework"),
+ Name: proptools.StringPtr("odm/framework"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/lib"),
+ Name: proptools.StringPtr("odm/lib"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/lib64"),
+ Name: proptools.StringPtr("odm/lib64"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/overlay"),
+ Name: proptools.StringPtr("odm/overlay"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/priv-app"),
+ Name: proptools.StringPtr("odm/priv-app"),
+ },
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/vendor/odm/usr"),
+ Name: proptools.StringPtr("odm/usr"),
+ },
+ filesystem.SymlinkDefinition{
Target: proptools.StringPtr("/product"),
Name: proptools.StringPtr("system/product"),
},
@@ -240,7 +311,42 @@
Target: proptools.StringPtr("/system_dlkm/lib/modules"),
Name: proptools.StringPtr("system/lib/modules"),
},
+ filesystem.SymlinkDefinition{
+ Target: proptools.StringPtr("/data/cache"),
+ Name: proptools.StringPtr("cache"),
+ },
}
+ fsProps.Dirs = proptools.NewSimpleConfigurable([]string{
+ // From generic_rootdirs in build/make/target/product/generic/Android.bp
+ "acct",
+ "apex",
+ "bootstrap-apex",
+ "config",
+ "data",
+ "data_mirror",
+ "debug_ramdisk",
+ "dev",
+ "linkerconfig",
+ "metadata",
+ "mnt",
+ "odm",
+ "odm_dlkm",
+ "oem",
+ "postinstall",
+ "proc",
+ "second_stage_resources",
+ "storage",
+ "sys",
+ "system",
+ "system_dlkm",
+ "tmp",
+ "vendor",
+ "vendor_dlkm",
+
+ // from android_rootdirs in build/make/target/product/generic/Android.bp
+ "system_ext",
+ "product",
+ })
case "system_ext":
fsProps.Fsverity.Inputs = []string{
"framework/*",
@@ -321,7 +427,7 @@
}
}
- if android.InList(partitionType, dlkmPartitions) {
+ if android.InList(partitionType, append(dlkmPartitions, "vendor_ramdisk")) {
f.createPrebuiltKernelModules(ctx, partitionType)
}
@@ -398,6 +504,7 @@
System_dlkm_specific *bool
Vendor_dlkm_specific *bool
Odm_dlkm_specific *bool
+ Vendor_ramdisk *bool
Load_by_default *bool
Blocklist_file *string
}{
@@ -430,6 +537,12 @@
if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" {
props.Blocklist_file = proptools.StringPtr(blocklistFile)
}
+ case "vendor_ramdisk":
+ props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorRamdiskKernelModules).Strings()
+ props.Vendor_ramdisk = proptools.BoolPtr(true)
+ if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorRamdiskKernelBlocklistFile; blocklistFile != "" {
+ props.Blocklist_file = proptools.StringPtr(blocklistFile)
+ }
default:
ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType)
}
diff --git a/fsgen/fsgen_mutators.go b/fsgen/fsgen_mutators.go
index 9472a50..0cc643e 100644
--- a/fsgen/fsgen_mutators.go
+++ b/fsgen/fsgen_mutators.go
@@ -95,15 +95,18 @@
fsDeps: map[string]*multilibDeps{
// These additional deps are added according to the cuttlefish system image bp.
"system": {
+ // keep-sorted start
"com.android.apex.cts.shim.v1_prebuilt": defaultDepCandidateProps(ctx.Config()),
"dex_bootjars": defaultDepCandidateProps(ctx.Config()),
"framework_compatibility_matrix.device.xml": defaultDepCandidateProps(ctx.Config()),
+ "init.environ.rc-soong": defaultDepCandidateProps(ctx.Config()),
"libcompiler_rt": defaultDepCandidateProps(ctx.Config()),
"libdmabufheap": defaultDepCandidateProps(ctx.Config()),
"libgsi": defaultDepCandidateProps(ctx.Config()),
"llndk.libraries.txt": defaultDepCandidateProps(ctx.Config()),
"logpersist.start": defaultDepCandidateProps(ctx.Config()),
"update_engine_sideload": defaultDepCandidateProps(ctx.Config()),
+ // keep-sorted end
},
"vendor": {
"fs_config_files_vendor": defaultDepCandidateProps(ctx.Config()),
diff --git a/java/aar.go b/java/aar.go
index b5cdde3..e0e642e 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -417,6 +417,25 @@
extraLinkFlags []string
aconfigTextFiles android.Paths
usesLibrary *usesLibrary
+ // If rroDirs is provided, it will be used to generate package-res.apk
+ rroDirs *android.Paths
+ // If manifestForAapt is not nil, it will be used for aapt instead of the default source manifest.
+ manifestForAapt android.Path
+}
+
+func filterRRO(rroDirsDepSet depset.DepSet[rroDir], filter overlayType) android.Paths {
+ var paths android.Paths
+ seen := make(map[android.Path]bool)
+ for _, d := range rroDirsDepSet.ToList() {
+ if d.overlayType == filter {
+ if seen[d.path] {
+ continue
+ }
+ seen[d.path] = true
+ paths = append(paths, d.path)
+ }
+ }
+ return paths
}
func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptions) {
@@ -428,10 +447,15 @@
opts.classLoaderContexts = opts.classLoaderContexts.ExcludeLibs(opts.excludedLibs)
// App manifest file
- manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
- manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
+ var manifestFilePath android.Path
+ if opts.manifestForAapt != nil {
+ manifestFilePath = opts.manifestForAapt
+ } else {
+ manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
+ manifestFilePath = android.PathForModuleSrc(ctx, manifestFile)
+ }
- manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{
+ manifestPath := ManifestFixer(ctx, manifestFilePath, ManifestFixerParams{
SdkContext: opts.sdkContext,
ClassLoaderContexts: opts.classLoaderContexts,
IsLibrary: a.isLibrary,
@@ -472,6 +496,10 @@
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, opts.sdkContext, manifestPath)
+ a.rroDirsDepSet = depset.NewBuilder[rroDir](depset.TOPOLOGICAL).
+ Direct(rroDirs...).
+ Transitive(staticRRODirsDepSet).Build()
+
linkFlags = append(linkFlags, libFlags...)
linkDeps = append(linkDeps, sharedExportPackages...)
linkDeps = append(linkDeps, staticDeps.resPackages()...)
@@ -565,6 +593,11 @@
compileFlags, a.filterProduct(), opts.aconfigTextFiles).Paths()...)
}
+ var compiledRro, compiledRroOverlay android.Paths
+ if opts.rroDirs != nil {
+ compiledRro, compiledRroOverlay = a.compileResInDir(ctx, *opts.rroDirs, compileFlags, opts.aconfigTextFiles)
+ }
+
var splitPackages android.WritablePaths
var splits []split
@@ -591,10 +624,20 @@
if !a.isLibrary {
transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets())
}
- aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt,
- linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, splitPackages,
- opts.aconfigTextFiles)
- ctx.CheckbuildFile(packageRes)
+ if opts.rroDirs == nil { // link resources and overlay
+ aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt,
+ linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, splitPackages,
+ opts.aconfigTextFiles)
+ ctx.CheckbuildFile(packageRes)
+ } else { // link autogenerated rro
+ if len(compiledRro) == 0 {
+ return
+ }
+ aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt,
+ linkFlags, linkDeps, compiledRro, compiledRroOverlay, nil, nil,
+ opts.aconfigTextFiles)
+ ctx.CheckbuildFile(packageRes)
+ }
// Extract assets from the resource package output so that they can be used later in aapt2link
// for modules that depend on this one.
@@ -652,15 +695,46 @@
usedResourceProcessor: a.useResourceProcessorBusyBox(ctx),
}).
Transitive(staticResourcesNodesDepSet).Build()
- a.rroDirsDepSet = depset.NewBuilder[rroDir](depset.TOPOLOGICAL).
- Direct(rroDirs...).
- Transitive(staticRRODirsDepSet).Build()
a.manifestsDepSet = depset.NewBuilder[android.Path](depset.TOPOLOGICAL).
Direct(a.manifestPath).
DirectSlice(additionalManifests).
Transitive(staticManifestsDepSet).Build()
}
+// comileResInDir finds the resource files in dirs by globbing and then compiles them using aapt2
+// returns the file paths of compiled resources
+// dirs[0] is used as compileRes
+// dirs[1:] is used as compileOverlay
+func (a *aapt) compileResInDir(ctx android.ModuleContext, dirs android.Paths, compileFlags []string, aconfig android.Paths) (android.Paths, android.Paths) {
+ filesInDir := func(dir android.Path) android.Paths {
+ files, err := ctx.GlobWithDeps(filepath.Join(dir.String(), "**/*"), androidResourceIgnoreFilenames)
+ if err != nil {
+ ctx.ModuleErrorf("failed to glob overlay resource dir %q: %s", dir, err.Error())
+ return nil
+ }
+ var filePaths android.Paths
+ for _, file := range files {
+ if strings.HasSuffix(file, "/") {
+ continue // ignore directories
+ }
+ filePaths = append(filePaths, android.PathForSource(ctx, file))
+ }
+ return filePaths
+ }
+
+ var compiledRes, compiledOverlay android.Paths
+ if len(dirs) == 0 {
+ return nil, nil
+ }
+ compiledRes = append(compiledRes, aapt2Compile(ctx, dirs[0], filesInDir(dirs[0]), compileFlags, a.filterProduct(), aconfig).Paths()...)
+ if len(dirs) > 0 {
+ for _, dir := range dirs[1:] {
+ compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir, filesInDir(dir), compileFlags, a.filterProduct(), aconfig).Paths()...)
+ }
+ }
+ return compiledRes, compiledOverlay
+}
+
var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox",
blueprint.RuleParams{
Command: "${config.JavaCmd} -cp ${config.ResourceProcessorBusyBox} " +
@@ -805,7 +879,7 @@
switch depTag {
case instrumentationForTag:
// Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
- case sdkLibTag, libTag:
+ case sdkLibTag, libTag, rroDepTag:
if exportPackage != nil {
sharedResourcesNodeDepSets = append(sharedResourcesNodeDepSets, aarDep.ResourcesNodeDepSet())
sharedLibs = append(sharedLibs, exportPackage)
diff --git a/java/androidmk.go b/java/androidmk.go
index bacd925..2ad30b1 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -425,6 +425,24 @@
}
}
+func (a *AutogenRuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries {
+ if a.IsHideFromMake() || a.outputFile == nil {
+ return []android.AndroidMkEntries{android.AndroidMkEntries{
+ Disabled: true,
+ }}
+ }
+ return []android.AndroidMkEntries{android.AndroidMkEntries{
+ Class: "APPS",
+ OutputFile: android.OptionalPathForPath(a.outputFile),
+ Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
+ entries.SetString("LOCAL_CERTIFICATE", "presigned") // The apk will be signed by soong
+ },
+ },
+ }}
+}
+
func (a *AndroidApp) getOverriddenPackages() []string {
var overridden []string
if len(a.overridableAppProperties.Overrides) > 0 {
diff --git a/java/rro.go b/java/rro.go
index f225e1f..d277e4a 100644
--- a/java/rro.go
+++ b/java/rro.go
@@ -20,6 +20,7 @@
import (
"android/soong/android"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -29,6 +30,7 @@
func RegisterRuntimeResourceOverlayBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory)
+ ctx.RegisterModuleType("autogen_runtime_resource_overlay", AutogenRuntimeResourceOverlayFactory)
ctx.RegisterModuleType("override_runtime_resource_overlay", OverrideRuntimeResourceOverlayModuleFactory)
}
@@ -269,3 +271,145 @@
android.InitOverrideModule(m)
return m
}
+
+var (
+ generateOverlayManifestFile = pctx.AndroidStaticRule("generate_overlay_manifest",
+ blueprint.RuleParams{
+ Command: "build/make/tools/generate-enforce-rro-android-manifest.py " +
+ "--package-info $in " +
+ "--partition ${partition} " +
+ "--priority ${priority} -o $out",
+ CommandDeps: []string{"build/make/tools/generate-enforce-rro-android-manifest.py"},
+ }, "partition", "priority",
+ )
+)
+
+type AutogenRuntimeResourceOverlay struct {
+ android.ModuleBase
+ aapt
+
+ properties AutogenRuntimeResourceOverlayProperties
+
+ outputFile android.Path
+}
+
+type AutogenRuntimeResourceOverlayProperties struct {
+ Base *string
+ Sdk_version *string
+ Manifest *string `android:"path"`
+}
+
+func AutogenRuntimeResourceOverlayFactory() android.Module {
+ m := &AutogenRuntimeResourceOverlay{}
+ m.AddProperties(&m.properties)
+ android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
+
+ return m
+}
+
+type rroDependencyTag struct {
+ blueprint.DependencyTag
+}
+
+// Autogenerated RROs should always depend on the source android_app that created it.
+func (tag rroDependencyTag) ReplaceSourceWithPrebuilt() bool {
+ return false
+}
+
+var rroDepTag = rroDependencyTag{}
+
+func (a *AutogenRuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
+ sdkDep := decodeSdkDep(ctx, android.SdkContext(a))
+ if sdkDep.hasFrameworkLibs() {
+ a.aapt.deps(ctx, sdkDep)
+ }
+ ctx.AddDependency(ctx.Module(), rroDepTag, proptools.String(a.properties.Base))
+}
+
+func (a *AutogenRuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if !a.Enabled(ctx) {
+ return
+ }
+ var rroDirs android.Paths
+ // Get rro dirs of the base app
+ ctx.VisitDirectDepsWithTag(rroDepTag, func(m android.Module) {
+ aarDep, _ := m.(AndroidLibraryDependency)
+ if ctx.InstallInProduct() {
+ rroDirs = filterRRO(aarDep.RRODirsDepSet(), product)
+ } else {
+ rroDirs = filterRRO(aarDep.RRODirsDepSet(), device)
+ }
+ })
+
+ if len(rroDirs) == 0 {
+ return
+ }
+
+ // Generate a manifest file
+ genManifest := android.PathForModuleGen(ctx, "AndroidManifest.xml")
+ partition := "vendor"
+ priority := "0"
+ if ctx.InstallInProduct() {
+ partition = "product"
+ priority = "1"
+ }
+ ctx.Build(pctx, android.BuildParams{
+ Rule: generateOverlayManifestFile,
+ Input: android.PathForModuleSrc(ctx, proptools.String(a.properties.Manifest)),
+ Output: genManifest,
+ Args: map[string]string{
+ "partition": partition,
+ "priority": priority,
+ },
+ })
+
+ // Compile and link resources into package-res.apk
+ a.aapt.hasNoCode = true
+ aaptLinkFlags := []string{"--auto-add-overlay", "--keep-raw-values", "--no-resource-deduping", "--no-resource-removal"}
+
+ a.aapt.buildActions(ctx,
+ aaptBuildActionOptions{
+ sdkContext: a,
+ extraLinkFlags: aaptLinkFlags,
+ rroDirs: &rroDirs,
+ manifestForAapt: genManifest,
+ },
+ )
+
+ if a.exportPackage == nil {
+ return
+ }
+ // Sign the built package
+ _, certificates := processMainCert(a.ModuleBase, "", nil, ctx)
+ signed := android.PathForModuleOut(ctx, "signed", a.Name()+".apk")
+ SignAppPackage(ctx, signed, a.exportPackage, certificates, nil, nil, "")
+ a.outputFile = signed
+
+ // Install the signed apk
+ installDir := android.PathForModuleInstall(ctx, "overlay")
+ ctx.InstallFile(installDir, signed.Base(), signed)
+}
+
+func (a *AutogenRuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+ return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version))
+}
+
+func (a *AutogenRuntimeResourceOverlay) SystemModules() string {
+ return ""
+}
+
+func (a *AutogenRuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
+ return a.SdkVersion(ctx).ApiLevel
+}
+
+func (r *AutogenRuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
+ return android.SdkSpecPrivate.ApiLevel
+}
+
+func (a *AutogenRuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
+ return a.SdkVersion(ctx).ApiLevel
+}
+
+func (a *AutogenRuntimeResourceOverlay) InstallInProduct() bool {
+ return a.ProductSpecific()
+}
diff --git a/kernel/prebuilt_kernel_modules.go b/kernel/prebuilt_kernel_modules.go
index 13d6482..001a1e7 100644
--- a/kernel/prebuilt_kernel_modules.go
+++ b/kernel/prebuilt_kernel_modules.go
@@ -58,6 +58,9 @@
Blocklist_file *string `android:"path"`
+ // Path to the kernel module options file
+ Options_file *string `android:"path"`
+
// 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
@@ -100,6 +103,13 @@
strippedModules := stripDebugSymbols(ctx, modules)
installDir := android.PathForModuleInstall(ctx, "lib", "modules")
+ // Kernel module is installed to vendor_ramdisk/lib/modules regardless of product
+ // configuration. This matches the behavior in make and prevents the files from being
+ // installed in `vendor_ramdisk/first_stage_ramdisk`.
+ if pkm.InstallInVendorRamdisk() {
+ installDir = android.PathForModuleInPartitionInstall(ctx, "vendor_ramdisk", "lib", "modules")
+ }
+
if pkm.KernelVersion() != "" {
installDir = installDir.Join(ctx, pkm.KernelVersion())
}
@@ -112,6 +122,7 @@
ctx.InstallFile(installDir, "modules.softdep", depmodOut.modulesSoftdep)
ctx.InstallFile(installDir, "modules.alias", depmodOut.modulesAlias)
pkm.installBlocklistFile(ctx, installDir)
+ pkm.installOptionsFile(ctx, installDir)
ctx.SetOutputFiles(modules, ".modules")
}
@@ -130,6 +141,20 @@
ctx.InstallFile(installDir, "modules.blocklist", blocklistOut)
}
+func (pkm *prebuiltKernelModules) installOptionsFile(ctx android.ModuleContext, installDir android.InstallPath) {
+ if pkm.properties.Options_file == nil {
+ return
+ }
+ optionsOut := android.PathForModuleOut(ctx, "modules.options")
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: processOptionsFile,
+ Input: android.PathForModuleSrc(ctx, proptools.String(pkm.properties.Options_file)),
+ Output: optionsOut,
+ })
+ ctx.InstallFile(installDir, "modules.options", optionsOut)
+}
+
var (
pctx = android.NewPackageContext("android/soong/kernel")
@@ -189,6 +214,19 @@
` END { exit exit_status }'`,
},
)
+ // Remove empty lines. Raise an exception if line is _not_ formatted as `options $name.ko`
+ processOptionsFile = pctx.AndroidStaticRule("process_options_file",
+ blueprint.RuleParams{
+ Command: `rm -rf $out && awk <$in > $out` +
+ ` '/^#/ { print; next }` +
+ ` NF == 0 { next }` +
+ ` NF < 2 || $$1 != "options"` +
+ ` { print "Invalid options line " FNR ": " $$0 >"/dev/stderr";` +
+ ` exit_status = 1; next }` +
+ ` { $$1 = $$1; print }` +
+ ` END { exit exit_status }'`,
+ },
+ )
)
// This is the path in soong intermediates where the .ko files will be copied.
diff --git a/sdk/update.go b/sdk/update.go
index 7f4f80a..5a899a2 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -1201,7 +1201,7 @@
// the snapshot.
func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) string {
if _, ok := s.allMembersByName[name]; !ok {
- if required {
+ if required && !s.ctx.Config().AllowMissingDependencies() {
s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", name)
}
return name