blob: 608fccdadcc92773d556e17d1f1478769c26a200 [file] [log] [blame]
Justin Yun74f3f302024-05-07 14:32:14 +09001// 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
15package filesystem
16
17import (
18 "android/soong/android"
Justin Yun74f3f302024-05-07 14:32:14 +090019 "strings"
20
21 "github.com/google/blueprint/proptools"
22)
23
Justin Yun16209832024-05-14 14:51:03 +090024func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.OutputPath) {
Justin Yun74f3f302024-05-07 14:32:14 +090025 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 Yun74f3f302024-05-07 14:32:14 +090033 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 Yun16209832024-05-14 14:51:03 +090040 var sbCaches strings.Builder
Justin Yun74f3f302024-05-07 14:32:14 +090041 for _, cache := range caches {
Justin Yun16209832024-05-14 14:51:03 +090042 sbCaches.WriteString(" --cache ")
43 sbCaches.WriteString(cache)
44 sbCaches.WriteString(" \\\n")
Justin Yun74f3f302024-05-07 14:32:14 +090045 }
Justin Yun16209832024-05-14 14:51:03 +090046 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 Kim99a954d2024-06-21 14:22:20 +090058 f.appendToEntry(ctx, installAconfigFlagsPath)
Justin Yun16209832024-05-14 14:51:03 +090059
60 installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig")
61 sb.WriteString("mkdir -p ")
62 sb.WriteString(installAconfigStorageDir.String())
Justin Yun74f3f302024-05-07 14:32:14 +090063 sb.WriteRune('\n')
64
Justin Yun16209832024-05-14 14:51:03 +090065 generatePartitionAconfigStorageFile := func(fileType, fileName string) {
Kiyoung Kim99a954d2024-06-21 14:22:20 +090066 outputPath := installAconfigStorageDir.Join(ctx, fileName)
Justin Yun16209832024-05-14 14:51:03 +090067 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 Kim99a954d2024-06-21 14:22:20 +090073 sb.WriteString(outputPath.String())
Justin Yun16209832024-05-14 14:51:03 +090074 sb.WriteString(" \\\n")
75 sb.WriteString(sbCaches.String())
Kiyoung Kim99a954d2024-06-21 14:22:20 +090076 cmd.ImplicitOutput(outputPath)
77 f.appendToEntry(ctx, outputPath)
Justin Yun16209832024-05-14 14:51:03 +090078 }
Spandan Das3d9b69e2024-10-07 19:03:45 +000079
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 Yun16209832024-05-14 14:51:03 +090086
Justin Yun74f3f302024-05-07 14:32:14 +090087 android.WriteExecutableFileRuleVerbatim(ctx, aconfigFlagsBuilderPath, sb.String())
88}