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 | "strings" |
| 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 | |
| 29 | aconfigFlagsBuilderPath := android.PathForModuleOut(ctx, "aconfig_flags_builder.sh") |
| 30 | aconfigToolPath := ctx.Config().HostToolPath(ctx, "aconfig") |
| 31 | cmd := builder.Command().Tool(aconfigFlagsBuilderPath).Implicit(aconfigToolPath) |
| 32 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 33 | var caches []string |
| 34 | for _, ps := range specs { |
| 35 | cmd.Implicits(ps.GetAconfigPaths()) |
| 36 | caches = append(caches, ps.GetAconfigPaths().Strings()...) |
| 37 | } |
| 38 | caches = android.SortedUniqueStrings(caches) |
| 39 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 40 | var sbCaches strings.Builder |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 41 | for _, cache := range caches { |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 42 | sbCaches.WriteString(" --cache ") |
| 43 | sbCaches.WriteString(cache) |
| 44 | sbCaches.WriteString(" \\\n") |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 45 | } |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 46 | sbCaches.WriteRune('\n') |
| 47 | |
| 48 | var sb strings.Builder |
| 49 | sb.WriteString("set -e\n") |
| 50 | |
| 51 | installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb") |
| 52 | sb.WriteString(aconfigToolPath.String()) |
| 53 | sb.WriteString(" dump-cache --dedup --format protobuf --out ") |
| 54 | sb.WriteString(installAconfigFlagsPath.String()) |
| 55 | sb.WriteString(" \\\n") |
| 56 | sb.WriteString(sbCaches.String()) |
| 57 | cmd.ImplicitOutput(installAconfigFlagsPath) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 58 | f.appendToEntry(ctx, installAconfigFlagsPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 59 | |
| 60 | installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig") |
| 61 | sb.WriteString("mkdir -p ") |
| 62 | sb.WriteString(installAconfigStorageDir.String()) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 63 | sb.WriteRune('\n') |
| 64 | |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 65 | generatePartitionAconfigStorageFile := func(fileType, fileName string) { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 66 | outputPath := installAconfigStorageDir.Join(ctx, fileName) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 67 | sb.WriteString(aconfigToolPath.String()) |
| 68 | sb.WriteString(" create-storage --container ") |
| 69 | sb.WriteString(f.PartitionType()) |
| 70 | sb.WriteString(" --file ") |
| 71 | sb.WriteString(fileType) |
| 72 | sb.WriteString(" --out ") |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 73 | sb.WriteString(outputPath.String()) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 74 | sb.WriteString(" \\\n") |
| 75 | sb.WriteString(sbCaches.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 76 | cmd.ImplicitOutput(outputPath) |
| 77 | f.appendToEntry(ctx, outputPath) |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 78 | } |
Spandan Das | 3d9b69e | 2024-10-07 19:03:45 +0000 | [diff] [blame^] | 79 | |
| 80 | if ctx.Config().ReleaseCreateAconfigStorageFile() { |
| 81 | generatePartitionAconfigStorageFile("package_map", "package.map") |
| 82 | generatePartitionAconfigStorageFile("flag_map", "flag.map") |
| 83 | generatePartitionAconfigStorageFile("flag_val", "flag.val") |
| 84 | generatePartitionAconfigStorageFile("flag_info", "flag.info") |
| 85 | } |
Justin Yun | 1620983 | 2024-05-14 14:51:03 +0900 | [diff] [blame] | 86 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 87 | android.WriteExecutableFileRuleVerbatim(ctx, aconfigFlagsBuilderPath, sb.String()) |
| 88 | } |