From 74ee4e0adc7fb37d648b86852cae93746556e02e Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 16 Jan 2025 14:55:35 -0800 Subject: Build system_other image in soong-only builds This just builds an empty system_other image for now, the dexpreopt files will be added in a followup change. Bug: 390269431 Test: m --soong-only Change-Id: Ic4a9bcb8b7ba1eb4444b3339d6c0b0cdfd485714 --- filesystem/filesystem.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'filesystem/filesystem.go') diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index ad19cc6e0..e485e4fdb 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -378,6 +378,11 @@ type FilesystemInfo struct { // Name of the module that produced this FilesystemInfo origionally. (though it may be // re-exported by super images or boot images) ModuleName string + // The property file generated by this module and passed to build_image. + // It's exported here so that system_other can reuse system's property file. + BuildImagePropFile android.Path + // Paths to all the tools referenced inside of the build image property file. + BuildImagePropFileDeps android.Paths } var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]() @@ -484,9 +489,11 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { var mapFile android.Path var outputHermetic android.Path + var buildImagePropFile android.Path + var buildImagePropFileDeps android.Paths switch f.fsType(ctx) { case ext4Type, erofsType, f2fsType: - f.output, outputHermetic = f.buildImageUsingBuildImage(ctx, builder, rootDir, rebasedDir) + f.output, outputHermetic, buildImagePropFile, buildImagePropFileDeps = f.buildImageUsingBuildImage(ctx, builder, rootDir, rebasedDir) mapFile = f.getMapFile(ctx) case compressedCpioType: f.output = f.buildCpioImage(ctx, builder, rootDir, true) @@ -508,17 +515,15 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { android.WriteFileRule(ctx, fileListFile, f.installedFilesList()) fsInfo := FilesystemInfo{ - Output: f.output, - FileListFile: fileListFile, - RootDir: rootDir, - RebasedDir: rebasedDir, - ModuleName: ctx.ModuleName(), - } - if mapFile != nil { - fsInfo.MapFile = mapFile - } - if outputHermetic != nil { - fsInfo.OutputHermetic = outputHermetic + Output: f.output, + OutputHermetic: outputHermetic, + FileListFile: fileListFile, + RootDir: rootDir, + RebasedDir: rebasedDir, + MapFile: mapFile, + ModuleName: ctx.ModuleName(), + BuildImagePropFile: buildImagePropFile, + BuildImagePropFileDeps: buildImagePropFileDeps, } android.SetProvider(ctx, FilesystemProvider, fsInfo) @@ -670,7 +675,7 @@ func (f *filesystem) buildImageUsingBuildImage( builder *android.RuleBuilder, rootDir android.OutputPath, rebasedDir android.OutputPath, -) (android.Path, android.Path) { +) (android.Path, android.Path, android.Path, android.Paths) { // run host_init_verifier // Ideally we should have a concept of pluggable linters that verify the generated image. // While such concept is not implement this will do. @@ -721,7 +726,7 @@ func (f *filesystem) buildImageUsingBuildImage( // rootDir is not deleted. Might be useful for quick inspection. builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) - return output, outputHermetic + return output, outputHermetic, propFile, toolDeps } func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path { -- cgit v1.2.3-59-g8ed1b From b8e280f886c1095c8a7e35cf88c4265c2b55f173 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 16 Jan 2025 16:33:26 -0800 Subject: Install odex/vdex files into soong-built system_other This makes system_other almost identical to the make-built one, but there's still a diff in just one file: system_other/system/priv-app/CredentialManager/oat/x86_64/CredentialManager.art Bug: 390269431 Test: m --soong-only Change-Id: I440097cead56a20d0268f4e766ac1be8fe11b34b --- filesystem/filesystem.go | 20 ++++++++++++++++++-- filesystem/system_other.go | 21 ++++++++++++++++++--- fsgen/filesystem_creator.go | 7 ++++++- 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'filesystem/filesystem.go') diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index e485e4fdb..822ba43ad 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -383,6 +383,8 @@ type FilesystemInfo struct { BuildImagePropFile android.Path // Paths to all the tools referenced inside of the build image property file. BuildImagePropFileDeps android.Paths + // Packaging specs to be installed on the system_other image, for the initial boot's dexpreopt. + SpecsForSystemOther map[string]android.PackagingSpec } var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]() @@ -524,6 +526,7 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { ModuleName: ctx.ModuleName(), BuildImagePropFile: buildImagePropFile, BuildImagePropFileDeps: buildImagePropFileDeps, + SpecsForSystemOther: f.systemOtherFiles(ctx), } android.SetProvider(ctx, FilesystemProvider, fsInfo) @@ -1070,8 +1073,21 @@ func (f *filesystem) SignedOutputPath() android.Path { // Note that "apex" module installs its contents to "apex"(fake partition) as well // for symbol lookup by imitating "activated" paths. func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { - specs := f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec) - return specs + return f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec) +} + +// Dexpreopt files are installed to system_other. Collect the packaingSpecs for the dexpreopt files +// from this partition to export to the system_other partition later. +func (f *filesystem) systemOtherFiles(ctx android.ModuleContext) map[string]android.PackagingSpec { + filter := func(spec android.PackagingSpec) bool { + // For some reason system_other packaging specs don't set the partition field. + return strings.HasPrefix(spec.RelPathInPackage(), "system_other/") + } + modifier := func(spec *android.PackagingSpec) { + spec.SetRelPathInPackage(strings.TrimPrefix(spec.RelPathInPackage(), "system_other/")) + spec.SetPartition("system_other") + } + return f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, filter, modifier) } func sha1sum(values []string) string { diff --git a/filesystem/system_other.go b/filesystem/system_other.go index cad426337..28fe1ce49 100644 --- a/filesystem/system_other.go +++ b/filesystem/system_other.go @@ -49,7 +49,7 @@ type systemOtherImage struct { func SystemOtherImageFactory() android.Module { module := &systemOtherImage{} module.AddProperties(&module.properties) - android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) return module } @@ -89,14 +89,29 @@ func (m *systemOtherImage) GenerateAndroidBuildActions(ctx android.ModuleContext builder := android.NewRuleBuilder(pctx, ctx) builder.Command().Textf("rm -rf %s && mkdir -p %s", stagingDir, stagingDir) + specs := make(map[string]android.PackagingSpec) for _, otherPartition := range m.properties.Preinstall_dexpreopt_files_from { dexModule := ctx.GetDirectDepProxyWithTag(otherPartition, dexpreoptDependencyTag) - _, ok := android.OtherModuleProvider(ctx, dexModule, FilesystemProvider) + fsInfo, ok := android.OtherModuleProvider(ctx, dexModule, FilesystemProvider) if !ok { ctx.PropertyErrorf("preinstall_dexpreopt_files_from", "Expected module %q to provide FilesystemProvider", otherPartition) return } - // TODO(b/390269431): Install dex files to the staging dir + // Merge all the packaging specs into 1 map + for k := range fsInfo.SpecsForSystemOther { + if _, ok := specs[k]; ok { + ctx.ModuleErrorf("Packaging spec %s given by two different partitions", k) + continue + } + specs[k] = fsInfo.SpecsForSystemOther[k] + } + } + + // TOOD: CopySpecsToDir only exists on PackagingBase, but doesn't use any fields from it. Clean this up. + (&android.PackagingBase{}).CopySpecsToDir(ctx, builder, specs, stagingDir) + + if len(m.properties.Preinstall_dexpreopt_files_from) > 0 { + builder.Command().Textf("touch %s", filepath.Join(stagingDir.String(), "system-other-odex-marker")) } // Most of the time, if build_image were to call a host tool, it accepts the path to the diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go index 616607468..44ae953f4 100644 --- a/fsgen/filesystem_creator.go +++ b/fsgen/filesystem_creator.go @@ -128,6 +128,10 @@ func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) } } + finalSoongGeneratedPartitionNames := make([]string, 0, len(finalSoongGeneratedPartitions)) + for _, partitionType := range finalSoongGeneratedPartitions { + finalSoongGeneratedPartitionNames = append(finalSoongGeneratedPartitionNames, generatedModuleNameForPartition(ctx.Config(), partitionType)) + } // Create android_info.prop f.createAndroidInfo(ctx) @@ -163,7 +167,8 @@ func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { ctx.CreateModule( filesystem.SystemOtherImageFactory, &filesystem.SystemOtherImageProperties{ - System_image: &systemModule, + System_image: &systemModule, + Preinstall_dexpreopt_files_from: finalSoongGeneratedPartitionNames, }, &struct { Name *string -- cgit v1.2.3-59-g8ed1b