blob: 44de20237151c77f79e367b816f33c4af5be88fa [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
25func (f *filesystem) buildAconfigFlagsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, dir android.Path) {
26 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
34 installAconfigFlags := filepath.Join(dir.String(), "etc", "aconfig_flags_"+f.partitionName()+".pb")
35
36 var sb strings.Builder
37 sb.WriteString("set -e\n")
38 sb.WriteString(aconfigToolPath.String())
39 sb.WriteString(" dump-cache --dedup --format protobuf --out ")
40 sb.WriteString(installAconfigFlags)
41 sb.WriteString(" \\\n")
42
43 var caches []string
44 for _, ps := range specs {
45 cmd.Implicits(ps.GetAconfigPaths())
46 caches = append(caches, ps.GetAconfigPaths().Strings()...)
47 }
48 caches = android.SortedUniqueStrings(caches)
49
50 for _, cache := range caches {
51 sb.WriteString(" --cache ")
52 sb.WriteString(cache)
53 sb.WriteString(" \\\n")
54 }
55 sb.WriteRune('\n')
56
57 android.WriteExecutableFileRuleVerbatim(ctx, aconfigFlagsBuilderPath, sb.String())
58}