blob: 8daee850e79a593aecf264b249788665d888c23b [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"
19 "path/filepath"
20 "strings"
21
22 "github.com/google/blueprint/proptools"
23)
24
Justin Yun16209832024-05-14 14:51:03 +090025func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.OutputPath) {
Justin Yun74f3f302024-05-07 14:32:14 +090026 if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) {
27 return
28 }
29
30 aconfigFlagsBuilderPath := android.PathForModuleOut(ctx, "aconfig_flags_builder.sh")
31 aconfigToolPath := ctx.Config().HostToolPath(ctx, "aconfig")
32 cmd := builder.Command().Tool(aconfigFlagsBuilderPath).Implicit(aconfigToolPath)
33
Justin Yun74f3f302024-05-07 14:32:14 +090034 var caches []string
35 for _, ps := range specs {
36 cmd.Implicits(ps.GetAconfigPaths())
37 caches = append(caches, ps.GetAconfigPaths().Strings()...)
38 }
39 caches = android.SortedUniqueStrings(caches)
40
Justin Yun16209832024-05-14 14:51:03 +090041 var sbCaches strings.Builder
Justin Yun74f3f302024-05-07 14:32:14 +090042 for _, cache := range caches {
Justin Yun16209832024-05-14 14:51:03 +090043 sbCaches.WriteString(" --cache ")
44 sbCaches.WriteString(cache)
45 sbCaches.WriteString(" \\\n")
Justin Yun74f3f302024-05-07 14:32:14 +090046 }
Justin Yun16209832024-05-14 14:51:03 +090047 sbCaches.WriteRune('\n')
48
49 var sb strings.Builder
50 sb.WriteString("set -e\n")
51
52 installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb")
53 sb.WriteString(aconfigToolPath.String())
54 sb.WriteString(" dump-cache --dedup --format protobuf --out ")
55 sb.WriteString(installAconfigFlagsPath.String())
56 sb.WriteString(" \\\n")
57 sb.WriteString(sbCaches.String())
58 cmd.ImplicitOutput(installAconfigFlagsPath)
59
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) {
66 sb.WriteString(aconfigToolPath.String())
67 sb.WriteString(" create-storage --container ")
68 sb.WriteString(f.PartitionType())
69 sb.WriteString(" --file ")
70 sb.WriteString(fileType)
71 sb.WriteString(" --out ")
72 sb.WriteString(filepath.Join(installAconfigStorageDir.String(), fileName))
73 sb.WriteString(" \\\n")
74 sb.WriteString(sbCaches.String())
75 cmd.ImplicitOutput(installAconfigStorageDir.Join(ctx, fileName))
76 }
77 generatePartitionAconfigStorageFile("package_map", "package.map")
78 generatePartitionAconfigStorageFile("flag_map", "flag.map")
79 generatePartitionAconfigStorageFile("flag_val", "flag.val")
80
Justin Yun74f3f302024-05-07 14:32:14 +090081 android.WriteExecutableFileRuleVerbatim(ctx, aconfigFlagsBuilderPath, sb.String())
82}