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 | |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | ) |
| 23 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 24 | func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.OutputPath) { |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 25 | if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) { |
| 26 | return |
| 27 | } |
| 28 | |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 29 | var caches []android.Path |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 30 | for _, ps := range specs { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 31 | caches = append(caches, ps.GetAconfigPaths()...) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 32 | } |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 33 | caches = android.SortedUniquePaths(caches) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 34 | |
| 35 | installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb") |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 36 | cmd := builder.Command(). |
| 37 | BuiltTool("aconfig"). |
| 38 | Text(" dump-cache --dedup --format protobuf --out"). |
| 39 | Output(installAconfigFlagsPath). |
| 40 | Textf("--filter container:%s", f.PartitionType()) |
| 41 | for _, cache := range caches { |
| 42 | cmd.FlagWithInput("--cache ", cache) |
| 43 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 44 | f.appendToEntry(ctx, installAconfigFlagsPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 45 | |
| 46 | installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig") |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 47 | builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String()) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 48 | |
Marybeth Fair | c8c74d6 | 2024-12-04 14:22:40 -0500 | [diff] [blame^] | 49 | // To enable fingerprint, we need to have v2 storage files. The default version is 1. |
| 50 | storageFilesVersion := 1 |
| 51 | if ctx.Config().ReleaseFingerprintAconfigPackages() { |
| 52 | storageFilesVersion = 2 |
| 53 | } |
| 54 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 55 | generatePartitionAconfigStorageFile := func(fileType, fileName string) { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 56 | outputPath := installAconfigStorageDir.Join(ctx, fileName) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 57 | builder.Command(). |
| 58 | BuiltTool("aconfig"). |
| 59 | FlagWithArg("create-storage --container ", f.PartitionType()). |
| 60 | FlagWithArg("--file ", fileType). |
| 61 | FlagWithOutput("--out ", outputPath). |
Marybeth Fair | c8c74d6 | 2024-12-04 14:22:40 -0500 | [diff] [blame^] | 62 | FlagWithArg("--cache ", installAconfigFlagsPath.String()). |
| 63 | FlagWithArg("--version ", strconv.Itoa(storageFilesVersion)) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 64 | f.appendToEntry(ctx, outputPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 65 | } |
Spandan Das | 3d9b69e | 2024-10-07 19:03:45 +0000 | [diff] [blame] | 66 | |
| 67 | if ctx.Config().ReleaseCreateAconfigStorageFile() { |
| 68 | generatePartitionAconfigStorageFile("package_map", "package.map") |
| 69 | generatePartitionAconfigStorageFile("flag_map", "flag.map") |
| 70 | generatePartitionAconfigStorageFile("flag_val", "flag.val") |
| 71 | generatePartitionAconfigStorageFile("flag_info", "flag.info") |
| 72 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 73 | } |