xref: /aosp_15_r20/build/soong/filesystem/aconfig_files.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
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
15package filesystem
16
17import (
18	"android/soong/android"
19
20	"github.com/google/blueprint/proptools"
21)
22
23func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.OutputPath) {
24	if !proptools.Bool(f.properties.Gen_aconfig_flags_pb) {
25		return
26	}
27
28	var caches []android.Path
29	for _, ps := range specs {
30		caches = append(caches, ps.GetAconfigPaths()...)
31	}
32	caches = android.SortedUniquePaths(caches)
33
34	installAconfigFlagsPath := dir.Join(ctx, "etc", "aconfig_flags.pb")
35	cmd := builder.Command().
36		BuiltTool("aconfig").
37		Text(" dump-cache --dedup --format protobuf --out").
38		Output(installAconfigFlagsPath).
39		Textf("--filter container:%s", f.PartitionType())
40	for _, cache := range caches {
41		cmd.FlagWithInput("--cache ", cache)
42	}
43	f.appendToEntry(ctx, installAconfigFlagsPath)
44
45	installAconfigStorageDir := dir.Join(ctx, "etc", "aconfig")
46	builder.Command().Text("mkdir -p").Text(installAconfigStorageDir.String())
47
48	generatePartitionAconfigStorageFile := func(fileType, fileName string) {
49		outputPath := installAconfigStorageDir.Join(ctx, fileName)
50		builder.Command().
51			BuiltTool("aconfig").
52			FlagWithArg("create-storage --container ", f.PartitionType()).
53			FlagWithArg("--file ", fileType).
54			FlagWithOutput("--out ", outputPath).
55			FlagWithArg("--cache ", installAconfigFlagsPath.String())
56		f.appendToEntry(ctx, outputPath)
57	}
58
59	if ctx.Config().ReleaseCreateAconfigStorageFile() {
60		generatePartitionAconfigStorageFile("package_map", "package.map")
61		generatePartitionAconfigStorageFile("flag_map", "flag.map")
62		generatePartitionAconfigStorageFile("flag_val", "flag.val")
63		generatePartitionAconfigStorageFile("flag_info", "flag.info")
64	}
65}
66