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 | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 25 | func init() { |
| 26 | pctx.HostBinToolVariable("aconfig", "aconfig") |
| 27 | } |
| 28 | |
| 29 | var ( |
| 30 | aconfigCreateStorage = pctx.AndroidStaticRule("aconfig_create_storage", blueprint.RuleParams{ |
| 31 | Command: `$aconfig create-storage --container $container --file $fileType --out $out --cache $in --version $version`, |
| 32 | CommandDeps: []string{"$aconfig"}, |
| 33 | }, "container", "fileType", "version") |
| 34 | ) |
| 35 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 36 | type installedAconfigFlagsInfo struct { |
| 37 | aconfigFiles android.Paths |
| 38 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 39 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 40 | var installedAconfigFlagsProvider = blueprint.NewProvider[installedAconfigFlagsInfo]() |
| 41 | |
| 42 | type importAconfigDepDag struct { |
| 43 | blueprint.BaseDependencyTag |
| 44 | } |
| 45 | |
| 46 | var importAconfigDependencyTag = interPartitionDepTag{} |
| 47 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 48 | func (f *filesystem) buildAconfigFlagsFiles( |
| 49 | ctx android.ModuleContext, |
| 50 | builder *android.RuleBuilder, |
| 51 | specs map[string]android.PackagingSpec, |
| 52 | dir android.OutputPath, |
| 53 | fullInstallPaths *[]FullInstallPathInfo, |
| 54 | ) { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 55 | var caches []android.Path |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 56 | for _, ps := range specs { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 57 | caches = append(caches, ps.GetAconfigPaths()...) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 58 | } |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 59 | |
| 60 | ctx.VisitDirectDepsWithTag(importAconfigDependencyTag, func(m android.Module) { |
| 61 | info, ok := android.OtherModuleProvider(ctx, m, installedAconfigFlagsProvider) |
| 62 | if !ok { |
| 63 | ctx.ModuleErrorf("expected dependency %s to have an installedAconfigFlagsProvider", m.Name()) |
| 64 | return |
| 65 | } |
| 66 | caches = append(caches, info.aconfigFiles...) |
| 67 | }) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 68 | caches = android.SortedUniquePaths(caches) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 69 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 70 | android.SetProvider(ctx, installedAconfigFlagsProvider, installedAconfigFlagsInfo{ |
| 71 | aconfigFiles: caches, |
| 72 | }) |
| 73 | |
| 74 | if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) { |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | container := f.PartitionType() |
| 79 | |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 80 | aconfigFlagsPb := android.PathForModuleOut(ctx, "aconfig", "aconfig_flags.pb") |
| 81 | aconfigFlagsPbBuilder := android.NewRuleBuilder(pctx, ctx) |
| 82 | cmd := aconfigFlagsPbBuilder.Command(). |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 83 | BuiltTool("aconfig"). |
| 84 | Text(" dump-cache --dedup --format protobuf --out"). |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 85 | Output(aconfigFlagsPb). |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 86 | Textf("--filter container:%s+state:ENABLED", container). |
| 87 | Textf("--filter container:%s+permission:READ_WRITE", container) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 88 | for _, cache := range caches { |
| 89 | cmd.FlagWithInput("--cache ", cache) |
| 90 | } |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 91 | aconfigFlagsPbBuilder.Build("aconfig_flags_pb", "build aconfig_flags.pb") |
| 92 | |
| 93 | installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb") |
| 94 | builder.Command().Text("mkdir -p ").Text(dir.Join(ctx, "etc").String()) |
| 95 | builder.Command().Text("cp").Input(aconfigFlagsPb).Text(installAconfigFlagsPath.String()) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 96 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 97 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc/aconfig_flags.pb"), |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 98 | SourcePath: aconfigFlagsPb, |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 99 | }) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 100 | f.appendToEntry(ctx, installAconfigFlagsPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 101 | |
Marybeth Fair | c8c74d6 | 2024-12-04 14:22:40 -0500 | [diff] [blame] | 102 | // To enable fingerprint, we need to have v2 storage files. The default version is 1. |
| 103 | storageFilesVersion := 1 |
| 104 | if ctx.Config().ReleaseFingerprintAconfigPackages() { |
| 105 | storageFilesVersion = 2 |
| 106 | } |
| 107 | |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 108 | installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig") |
| 109 | builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String()) |
| 110 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 111 | generatePartitionAconfigStorageFile := func(fileType, fileName string) { |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 112 | outPath := android.PathForModuleOut(ctx, "aconfig", fileName) |
| 113 | installPath := installAconfigStorageDir.Join(ctx, fileName) |
| 114 | ctx.Build(pctx, android.BuildParams{ |
| 115 | Rule: aconfigCreateStorage, |
| 116 | Input: aconfigFlagsPb, |
| 117 | Output: outPath, |
| 118 | Args: map[string]string{ |
| 119 | "container": container, |
| 120 | "fileType": fileType, |
| 121 | "version": strconv.Itoa(storageFilesVersion), |
| 122 | }, |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 123 | }) |
Cole Faust | 781eff3 | 2025-02-14 14:21:57 -0800 | [diff] [blame^] | 124 | builder.Command(). |
| 125 | Text("cp").Input(outPath).Text(installPath.String()) |
| 126 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 127 | SourcePath: outPath, |
| 128 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc/aconfig", fileName), |
| 129 | }) |
| 130 | f.appendToEntry(ctx, installPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 131 | } |
Spandan Das | 3d9b69e | 2024-10-07 19:03:45 +0000 | [diff] [blame] | 132 | |
| 133 | if ctx.Config().ReleaseCreateAconfigStorageFile() { |
| 134 | generatePartitionAconfigStorageFile("package_map", "package.map") |
| 135 | generatePartitionAconfigStorageFile("flag_map", "flag.map") |
| 136 | generatePartitionAconfigStorageFile("flag_val", "flag.val") |
| 137 | generatePartitionAconfigStorageFile("flag_info", "flag.info") |
| 138 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 139 | } |