From a3fddf40cae111a676998fb1ca4a9150d3a64fcf Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 3 Sep 2024 13:22:21 +0900 Subject: Refactor around apex aconfig files (#2) Aconfig files are treated like other files in APEX. This way, we can dedup the code hanlding those files (copy commands, fs_config, etc). Bug: n/a Test: m nothing --no-skip-soong-tests Change-Id: Ia9f2186e4e54e92ad90c7a9c00474cb0f7519a31 --- apex/builder.go | 96 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 41 deletions(-) (limited to 'apex/builder.go') diff --git a/apex/builder.go b/apex/builder.go index 0d084834d..505ef8b59 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -262,6 +262,58 @@ var ( }, "tool_path", "unwanted") ) +func (a *apexBundle) buildAconfigFiles(ctx android.ModuleContext) []apexFile { + var aconfigFiles android.Paths + for _, file := range a.filesInfo { + if file.module == nil { + continue + } + if dep, ok := android.OtherModuleProvider(ctx, file.module, android.AconfigPropagatingProviderKey); ok { + if len(dep.AconfigFiles) > 0 && dep.AconfigFiles[ctx.ModuleName()] != nil { + aconfigFiles = append(aconfigFiles, dep.AconfigFiles[ctx.ModuleName()]...) + } + } + + validationFlag := ctx.DeviceConfig().AconfigContainerValidation() + if validationFlag == "error" || validationFlag == "warning" { + android.VerifyAconfigBuildMode(ctx, ctx.ModuleName(), file.module, validationFlag == "error") + } + } + aconfigFiles = android.FirstUniquePaths(aconfigFiles) + + var files []apexFile + if len(aconfigFiles) > 0 { + apexAconfigFile := android.PathForModuleOut(ctx, "aconfig_flags.pb") + ctx.Build(pctx, android.BuildParams{ + Rule: aconfig.AllDeclarationsRule, + Inputs: aconfigFiles, + Output: apexAconfigFile, + Description: "combine_aconfig_declarations", + Args: map[string]string{ + "cache_files": android.JoinPathsWithPrefix(aconfigFiles, "--cache "), + }, + }) + files = append(files, newApexFile(ctx, apexAconfigFile, "aconfig_flags", "etc", etc, nil)) + + for _, info := range createStorageInfo { + outputFile := android.PathForModuleOut(ctx, info.Output_file) + ctx.Build(pctx, android.BuildParams{ + Rule: aconfig.CreateStorageRule, + Inputs: aconfigFiles, + Output: outputFile, + Description: info.Desc, + Args: map[string]string{ + "container": ctx.ModuleName(), + "file_type": info.File_type, + "cache_files": android.JoinPathsWithPrefix(aconfigFiles, "--cache "), + }, + }) + files = append(files, newApexFile(ctx, outputFile, info.File_type, "etc", etc, nil)) + } + } + return files +} + // buildManifest creates buile rules to modify the input apex_manifest.json to add information // gathered by the build system such as provided/required native libraries. Two output files having // different formats are generated. a.manifestJsonOut is JSON format for Q devices, and @@ -644,48 +696,10 @@ func (a *apexBundle) buildApex(ctx android.ModuleContext) { outHostBinDir := ctx.Config().HostToolPath(ctx, "").String() prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") - defaultReadOnlyFiles := []string{"apex_manifest.json", "apex_manifest.pb"} - aconfigDest := imageDir.Join(ctx, "etc").String() - if len(a.aconfigFiles) > 0 { - apexAconfigFile := android.PathForModuleOut(ctx, "aconfig_flags.pb") - ctx.Build(pctx, android.BuildParams{ - Rule: aconfig.AllDeclarationsRule, - Inputs: a.aconfigFiles, - Output: apexAconfigFile, - Description: "combine_aconfig_declarations", - Args: map[string]string{ - "cache_files": android.JoinPathsWithPrefix(a.aconfigFiles, "--cache "), - }, - }) - - copyCommands = append(copyCommands, "cp -f "+apexAconfigFile.String()+" "+aconfigDest) - implicitInputs = append(implicitInputs, apexAconfigFile) - defaultReadOnlyFiles = append(defaultReadOnlyFiles, "etc/"+apexAconfigFile.Base()) - - for _, info := range createStorageInfo { - outputFile := android.PathForModuleOut(ctx, info.Output_file) - ctx.Build(pctx, android.BuildParams{ - Rule: aconfig.CreateStorageRule, - Inputs: a.aconfigFiles, - Output: outputFile, - Description: info.Desc, - Args: map[string]string{ - "container": ctx.ModuleName(), - "file_type": info.File_type, - "cache_files": android.JoinPathsWithPrefix(a.aconfigFiles, "--cache "), - }, - }) - - copyCommands = append(copyCommands, "cp -f "+outputFile.String()+" "+aconfigDest) - implicitInputs = append(implicitInputs, outputFile) - defaultReadOnlyFiles = append(defaultReadOnlyFiles, "etc/"+outputFile.Base()) - } - } - //////////////////////////////////////////////////////////////////////////////////// // Step 2: create canned_fs_config which encodes filemode,uid,gid of each files // in this APEX. The file will be used by apexer in later steps. - cannedFsConfig := a.buildCannedFsConfig(ctx, defaultReadOnlyFiles) + cannedFsConfig := a.buildCannedFsConfig(ctx) implicitInputs = append(implicitInputs, cannedFsConfig) //////////////////////////////////////////////////////////////////////////////////// @@ -1139,8 +1153,8 @@ func (a *apexBundle) buildLintReports(ctx android.ModuleContext) { a.lintReports = java.BuildModuleLintReportZips(ctx, depSetsBuilder.Build()) } -func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext, defaultReadOnlyFiles []string) android.OutputPath { - var readOnlyPaths = defaultReadOnlyFiles +func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext) android.OutputPath { + var readOnlyPaths = []string{"apex_manifest.json", "apex_manifest.pb"} var executablePaths []string // this also includes dirs var appSetDirs []string appSetFiles := make(map[string]android.Path) -- cgit v1.2.3-59-g8ed1b