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" |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 19 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 20 | "github.com/google/blueprint" |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 21 | "github.com/google/blueprint/proptools" |
| 22 | ) |
| 23 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 24 | type installedAconfigFlagsInfo struct { |
| 25 | aconfigFiles android.Paths |
| 26 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 27 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 28 | var installedAconfigFlagsProvider = blueprint.NewProvider[installedAconfigFlagsInfo]() |
| 29 | |
| 30 | type importAconfigDepDag struct { |
| 31 | blueprint.BaseDependencyTag |
| 32 | } |
| 33 | |
| 34 | var importAconfigDependencyTag = interPartitionDepTag{} |
| 35 | |
| 36 | func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.OutputPath) { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 37 | var caches []android.Path |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 38 | for _, ps := range specs { |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 39 | caches = append(caches, ps.GetAconfigPaths()...) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 40 | } |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 41 | |
| 42 | ctx.VisitDirectDepsWithTag(importAconfigDependencyTag, func(m android.Module) { |
| 43 | info, ok := android.OtherModuleProvider(ctx, m, installedAconfigFlagsProvider) |
| 44 | if !ok { |
| 45 | ctx.ModuleErrorf("expected dependency %s to have an installedAconfigFlagsProvider", m.Name()) |
| 46 | return |
| 47 | } |
| 48 | caches = append(caches, info.aconfigFiles...) |
| 49 | }) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 50 | caches = android.SortedUniquePaths(caches) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 51 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 52 | android.SetProvider(ctx, installedAconfigFlagsProvider, installedAconfigFlagsInfo{ |
| 53 | aconfigFiles: caches, |
| 54 | }) |
| 55 | |
| 56 | if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) { |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | container := f.PartitionType() |
| 61 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 62 | installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb") |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 63 | cmd := builder.Command(). |
| 64 | BuiltTool("aconfig"). |
| 65 | Text(" dump-cache --dedup --format protobuf --out"). |
| 66 | Output(installAconfigFlagsPath). |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 67 | Textf("--filter container:%s+state:ENABLED", container). |
| 68 | Textf("--filter container:%s+permission:READ_WRITE", container) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 69 | for _, cache := range caches { |
| 70 | cmd.FlagWithInput("--cache ", cache) |
| 71 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 72 | f.appendToEntry(ctx, installAconfigFlagsPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 73 | |
| 74 | installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig") |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 75 | builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String()) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 76 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 77 | generatePartitionAconfigStorageFile := func(fileType, fileName string) { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 78 | outputPath := installAconfigStorageDir.Join(ctx, fileName) |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 79 | builder.Command(). |
| 80 | BuiltTool("aconfig"). |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame^] | 81 | FlagWithArg("create-storage --container ", container). |
Cole Faust | d7556eb | 2024-12-02 13:18:58 -0800 | [diff] [blame] | 82 | FlagWithArg("--file ", fileType). |
| 83 | FlagWithOutput("--out ", outputPath). |
| 84 | FlagWithArg("--cache ", installAconfigFlagsPath.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 85 | f.appendToEntry(ctx, outputPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 86 | } |
Spandan Das | 3d9b69e | 2024-10-07 19:03:45 +0000 | [diff] [blame] | 87 | |
| 88 | if ctx.Config().ReleaseCreateAconfigStorageFile() { |
| 89 | generatePartitionAconfigStorageFile("package_map", "package.map") |
| 90 | generatePartitionAconfigStorageFile("flag_map", "flag.map") |
| 91 | generatePartitionAconfigStorageFile("flag_val", "flag.val") |
| 92 | generatePartitionAconfigStorageFile("flag_info", "flag.info") |
| 93 | } |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 94 | } |