Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 1 | // Copyright (C) 2024 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package filesystem |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Marybeth Fair | c8c74d6 | 2024-12-04 14:22:40 -0500 | [diff] [blame] | 19 | "strconv" |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 20 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 21 | "github.com/google/blueprint" |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | ) |
| 24 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 25 | type installedAconfigFlagsInfo struct { |
| 26 | aconfigFiles android.Paths |
| 27 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 28 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 29 | var installedAconfigFlagsProvider = blueprint.NewProvider[installedAconfigFlagsInfo]() |
| 30 | |
| 31 | type importAconfigDepDag struct { |
| 32 | blueprint.BaseDependencyTag |
| 33 | } |
| 34 | |
| 35 | var importAconfigDependencyTag = interPartitionDepTag{} |
| 36 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame^] | 37 | func (f *filesystem) buildAconfigFlagsFiles( |
| 38 | ctx android.ModuleContext, |
| 39 | builder *android.RuleBuilder, |
| 40 | specs map[string]android.PackagingSpec, |
| 41 | dir android.OutputPath, |
| 42 | fullInstallPaths *[]FullInstallPathInfo, |
| 43 | ) { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 44 | var caches []android.Path |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 45 | for _, ps := range specs { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 46 | caches = append(caches, ps.GetAconfigPaths()...) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 47 | } |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 48 | |
| 49 | ctx.VisitDirectDepsWithTag(importAconfigDependencyTag, func(m android.Module) { |
| 50 | info, ok := android.OtherModuleProvider(ctx, m, installedAconfigFlagsProvider) |
| 51 | if !ok { |
| 52 | ctx.ModuleErrorf("expected dependency %s to have an installedAconfigFlagsProvider", m.Name()) |
| 53 | return |
| 54 | } |
| 55 | caches = append(caches, info.aconfigFiles...) |
| 56 | }) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 57 | caches = android.SortedUniquePaths(caches) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 58 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 59 | android.SetProvider(ctx, installedAconfigFlagsProvider, installedAconfigFlagsInfo{ |
| 60 | aconfigFiles: caches, |
| 61 | }) |
| 62 | |
| 63 | if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) { |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | container := f.PartitionType() |
| 68 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 69 | installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb") |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 70 | cmd := builder.Command(). |
| 71 | BuiltTool("aconfig"). |
| 72 | Text(" dump-cache --dedup --format protobuf --out"). |
| 73 | Output(installAconfigFlagsPath). |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 74 | Textf("--filter container:%s+state:ENABLED", container). |
| 75 | Textf("--filter container:%s+permission:READ_WRITE", container) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 76 | for _, cache := range caches { |
| 77 | cmd.FlagWithInput("--cache ", cache) |
| 78 | } |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame^] | 79 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 80 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc/aconfig_flags.pb"), |
| 81 | SourcePath: installAconfigFlagsPath, |
| 82 | }) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 83 | f.appendToEntry(ctx, installAconfigFlagsPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 84 | |
| 85 | installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig") |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 86 | builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String()) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 87 | |
Marybeth Fair | c8c74d6 | 2024-12-04 14:22:40 -0500 | [diff] [blame] | 88 | // To enable fingerprint, we need to have v2 storage files. The default version is 1. |
| 89 | storageFilesVersion := 1 |
| 90 | if ctx.Config().ReleaseFingerprintAconfigPackages() { |
| 91 | storageFilesVersion = 2 |
| 92 | } |
| 93 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 94 | generatePartitionAconfigStorageFile := func(fileType, fileName string) { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 95 | outputPath := installAconfigStorageDir.Join(ctx, fileName) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 96 | builder.Command(). |
| 97 | BuiltTool("aconfig"). |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 98 | FlagWithArg("create-storage --container ", container). |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 99 | FlagWithArg("--file ", fileType). |
| 100 | FlagWithOutput("--out ", outputPath). |
Marybeth Fair | c8c74d6 | 2024-12-04 14:22:40 -0500 | [diff] [blame] | 101 | FlagWithArg("--cache ", installAconfigFlagsPath.String()). |
| 102 | FlagWithArg("--version ", strconv.Itoa(storageFilesVersion)) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame^] | 103 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 104 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc/aconfig", fileName), |
| 105 | SourcePath: outputPath, |
| 106 | }) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 107 | f.appendToEntry(ctx, outputPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 108 | } |
Spandan Das | 3d9b69e | 2024-10-07 19:03:45 +0000 | [diff] [blame] | 109 | |
| 110 | if ctx.Config().ReleaseCreateAconfigStorageFile() { |
| 111 | generatePartitionAconfigStorageFile("package_map", "package.map") |
| 112 | generatePartitionAconfigStorageFile("flag_map", "flag.map") |
| 113 | generatePartitionAconfigStorageFile("flag_val", "flag.val") |
| 114 | generatePartitionAconfigStorageFile("flag_info", "flag.info") |
| 115 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 116 | } |