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 "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.OutputPath) { 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 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 41 var sbCaches strings.Builder 42 for _, cache := range caches { 43 sbCaches.WriteString(" --cache ") 44 sbCaches.WriteString(cache) 45 sbCaches.WriteString(" \\\n") 46 } 47 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()) 63 sb.WriteRune('\n') 64 65 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 81 android.WriteExecutableFileRuleVerbatim(ctx, aconfigFlagsBuilderPath, sb.String()) 82} 83