blob: 9a3ca54085a4ea7536bad112a38d64c23fbe584d [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 Faust34592c02024-12-13 11:20:24 -080025type installedAconfigFlagsInfo struct {
26 aconfigFiles android.Paths
27}
Justin Yun74f3f302024-05-07 14:32:14 +090028
Cole Faust34592c02024-12-13 11:20:24 -080029var installedAconfigFlagsProvider = blueprint.NewProvider[installedAconfigFlagsInfo]()
30
31type importAconfigDepDag struct {
32 blueprint.BaseDependencyTag
33}
34
35var importAconfigDependencyTag = interPartitionDepTag{}
36
37func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.OutputPath) {
Cole Faustd7556eb2024-12-02 13:18:58 -080038 var caches []android.Path
Justin Yun74f3f302024-05-07 14:32:14 +090039 for _, ps := range specs {
Cole Faustd7556eb2024-12-02 13:18:58 -080040 caches = append(caches, ps.GetAconfigPaths()...)
Justin Yun74f3f302024-05-07 14:32:14 +090041 }
Cole Faust34592c02024-12-13 11:20:24 -080042
43 ctx.VisitDirectDepsWithTag(importAconfigDependencyTag, func(m android.Module) {
44 info, ok := android.OtherModuleProvider(ctx, m, installedAconfigFlagsProvider)
45 if !ok {
46 ctx.ModuleErrorf("expected dependency %s to have an installedAconfigFlagsProvider", m.Name())
47 return
48 }
49 caches = append(caches, info.aconfigFiles...)
50 })
Cole Faustd7556eb2024-12-02 13:18:58 -080051 caches = android.SortedUniquePaths(caches)
Justin Yun16209832024-05-14 14:51:03 +090052
Cole Faust34592c02024-12-13 11:20:24 -080053 android.SetProvider(ctx, installedAconfigFlagsProvider, installedAconfigFlagsInfo{
54 aconfigFiles: caches,
55 })
56
57 if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) {
58 return
59 }
60
61 container := f.PartitionType()
62
Justin Yun16209832024-05-14 14:51:03 +090063 installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb")
Cole Faustd7556eb2024-12-02 13:18:58 -080064 cmd := builder.Command().
65 BuiltTool("aconfig").
66 Text(" dump-cache --dedup --format protobuf --out").
67 Output(installAconfigFlagsPath).
Cole Faust34592c02024-12-13 11:20:24 -080068 Textf("--filter container:%s+state:ENABLED", container).
69 Textf("--filter container:%s+permission:READ_WRITE", container)
Cole Faustd7556eb2024-12-02 13:18:58 -080070 for _, cache := range caches {
71 cmd.FlagWithInput("--cache ", cache)
72 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +090073 f.appendToEntry(ctx, installAconfigFlagsPath)
Justin Yun16209832024-05-14 14:51:03 +090074
75 installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig")
Cole Faustd7556eb2024-12-02 13:18:58 -080076 builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String())
Justin Yun74f3f302024-05-07 14:32:14 +090077
Marybeth Fairc8c74d62024-12-04 14:22:40 -050078 // To enable fingerprint, we need to have v2 storage files. The default version is 1.
79 storageFilesVersion := 1
80 if ctx.Config().ReleaseFingerprintAconfigPackages() {
81 storageFilesVersion = 2
82 }
83
Justin Yun16209832024-05-14 14:51:03 +090084 generatePartitionAconfigStorageFile := func(fileType, fileName string) {
Kiyoung Kim99a954d2024-06-21 14:22:20 +090085 outputPath := installAconfigStorageDir.Join(ctx, fileName)
Cole Faustd7556eb2024-12-02 13:18:58 -080086 builder.Command().
87 BuiltTool("aconfig").
Cole Faust34592c02024-12-13 11:20:24 -080088 FlagWithArg("create-storage --container ", container).
Cole Faustd7556eb2024-12-02 13:18:58 -080089 FlagWithArg("--file ", fileType).
90 FlagWithOutput("--out ", outputPath).
Marybeth Fairc8c74d62024-12-04 14:22:40 -050091 FlagWithArg("--cache ", installAconfigFlagsPath.String()).
92 FlagWithArg("--version ", strconv.Itoa(storageFilesVersion))
Kiyoung Kim99a954d2024-06-21 14:22:20 +090093 f.appendToEntry(ctx, outputPath)
Justin Yun16209832024-05-14 14:51:03 +090094 }
Spandan Das3d9b69e2024-10-07 19:03:45 +000095
96 if ctx.Config().ReleaseCreateAconfigStorageFile() {
97 generatePartitionAconfigStorageFile("package_map", "package.map")
98 generatePartitionAconfigStorageFile("flag_map", "flag.map")
99 generatePartitionAconfigStorageFile("flag_val", "flag.val")
100 generatePartitionAconfigStorageFile("flag_info", "flag.info")
101 }
Justin Yun74f3f302024-05-07 14:32:14 +0900102}