blob: b4173d78441e411844339dcfdfbe668b31011b0e [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"
Marybeth Fairc8c74d62024-12-04 14:22:40 -050019 "strconv"
Justin Yun74f3f302024-05-07 14:32:14 +090020
Cole Faust34592c02024-12-13 11:20:24 -080021 "github.com/google/blueprint"
Justin Yun74f3f302024-05-07 14:32:14 +090022 "github.com/google/blueprint/proptools"
23)
24
Cole Faust781eff32025-02-14 14:21:57 -080025func init() {
26 pctx.HostBinToolVariable("aconfig", "aconfig")
27}
28
29var (
30 aconfigCreateStorage = pctx.AndroidStaticRule("aconfig_create_storage", blueprint.RuleParams{
31 Command: `$aconfig create-storage --container $container --file $fileType --out $out --cache $in --version $version`,
32 CommandDeps: []string{"$aconfig"},
33 }, "container", "fileType", "version")
34)
35
Cole Faust34592c02024-12-13 11:20:24 -080036type installedAconfigFlagsInfo struct {
37 aconfigFiles android.Paths
38}
Justin Yun74f3f302024-05-07 14:32:14 +090039
Cole Faust34592c02024-12-13 11:20:24 -080040var installedAconfigFlagsProvider = blueprint.NewProvider[installedAconfigFlagsInfo]()
41
42type importAconfigDepDag struct {
43 blueprint.BaseDependencyTag
44}
45
46var importAconfigDependencyTag = interPartitionDepTag{}
47
Cole Faust19fbb072025-01-30 18:19:29 -080048func (f *filesystem) buildAconfigFlagsFiles(
49 ctx android.ModuleContext,
50 builder *android.RuleBuilder,
51 specs map[string]android.PackagingSpec,
52 dir android.OutputPath,
53 fullInstallPaths *[]FullInstallPathInfo,
54) {
Cole Faustd7556eb2024-12-02 13:18:58 -080055 var caches []android.Path
Justin Yun74f3f302024-05-07 14:32:14 +090056 for _, ps := range specs {
Cole Faustd7556eb2024-12-02 13:18:58 -080057 caches = append(caches, ps.GetAconfigPaths()...)
Justin Yun74f3f302024-05-07 14:32:14 +090058 }
Cole Faust34592c02024-12-13 11:20:24 -080059
60 ctx.VisitDirectDepsWithTag(importAconfigDependencyTag, func(m android.Module) {
61 info, ok := android.OtherModuleProvider(ctx, m, installedAconfigFlagsProvider)
62 if !ok {
63 ctx.ModuleErrorf("expected dependency %s to have an installedAconfigFlagsProvider", m.Name())
64 return
65 }
66 caches = append(caches, info.aconfigFiles...)
67 })
Cole Faustd7556eb2024-12-02 13:18:58 -080068 caches = android.SortedUniquePaths(caches)
Justin Yun16209832024-05-14 14:51:03 +090069
Cole Faust34592c02024-12-13 11:20:24 -080070 android.SetProvider(ctx, installedAconfigFlagsProvider, installedAconfigFlagsInfo{
71 aconfigFiles: caches,
72 })
73
74 if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) {
75 return
76 }
77
78 container := f.PartitionType()
79
Cole Faust781eff32025-02-14 14:21:57 -080080 aconfigFlagsPb := android.PathForModuleOut(ctx, "aconfig", "aconfig_flags.pb")
81 aconfigFlagsPbBuilder := android.NewRuleBuilder(pctx, ctx)
82 cmd := aconfigFlagsPbBuilder.Command().
Cole Faustd7556eb2024-12-02 13:18:58 -080083 BuiltTool("aconfig").
84 Text(" dump-cache --dedup --format protobuf --out").
Cole Faust781eff32025-02-14 14:21:57 -080085 Output(aconfigFlagsPb).
Cole Faust34592c02024-12-13 11:20:24 -080086 Textf("--filter container:%s+state:ENABLED", container).
87 Textf("--filter container:%s+permission:READ_WRITE", container)
Cole Faustd7556eb2024-12-02 13:18:58 -080088 for _, cache := range caches {
89 cmd.FlagWithInput("--cache ", cache)
90 }
Cole Faust781eff32025-02-14 14:21:57 -080091 aconfigFlagsPbBuilder.Build("aconfig_flags_pb", "build aconfig_flags.pb")
92
93 installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb")
94 builder.Command().Text("mkdir -p ").Text(dir.Join(ctx, "etc").String())
95 builder.Command().Text("cp").Input(aconfigFlagsPb).Text(installAconfigFlagsPath.String())
Cole Faust19fbb072025-01-30 18:19:29 -080096 *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{
97 FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc/aconfig_flags.pb"),
Cole Faust781eff32025-02-14 14:21:57 -080098 SourcePath: aconfigFlagsPb,
Cole Faust19fbb072025-01-30 18:19:29 -080099 })
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900100 f.appendToEntry(ctx, installAconfigFlagsPath)
Justin Yun16209832024-05-14 14:51:03 +0900101
Marybeth Fairc8c74d62024-12-04 14:22:40 -0500102 // To enable fingerprint, we need to have v2 storage files. The default version is 1.
103 storageFilesVersion := 1
104 if ctx.Config().ReleaseFingerprintAconfigPackages() {
105 storageFilesVersion = 2
106 }
107
Cole Faust781eff32025-02-14 14:21:57 -0800108 installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig")
109 builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String())
110
Justin Yun16209832024-05-14 14:51:03 +0900111 generatePartitionAconfigStorageFile := func(fileType, fileName string) {
Cole Faust781eff32025-02-14 14:21:57 -0800112 outPath := android.PathForModuleOut(ctx, "aconfig", fileName)
113 installPath := installAconfigStorageDir.Join(ctx, fileName)
114 ctx.Build(pctx, android.BuildParams{
115 Rule: aconfigCreateStorage,
116 Input: aconfigFlagsPb,
117 Output: outPath,
118 Args: map[string]string{
119 "container": container,
120 "fileType": fileType,
121 "version": strconv.Itoa(storageFilesVersion),
122 },
Cole Faust19fbb072025-01-30 18:19:29 -0800123 })
Cole Faust781eff32025-02-14 14:21:57 -0800124 builder.Command().
125 Text("cp").Input(outPath).Text(installPath.String())
126 *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{
127 SourcePath: outPath,
128 FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc/aconfig", fileName),
129 })
130 f.appendToEntry(ctx, installPath)
Justin Yun16209832024-05-14 14:51:03 +0900131 }
Spandan Das3d9b69e2024-10-07 19:03:45 +0000132
133 if ctx.Config().ReleaseCreateAconfigStorageFile() {
134 generatePartitionAconfigStorageFile("package_map", "package.map")
135 generatePartitionAconfigStorageFile("flag_map", "flag.map")
136 generatePartitionAconfigStorageFile("flag_val", "flag.val")
137 generatePartitionAconfigStorageFile("flag_info", "flag.info")
138 }
Justin Yun74f3f302024-05-07 14:32:14 +0900139}