Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 1 | // Copyright 2024 Google Inc. All rights reserved. |
| 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Nick Chalko | b905931 | 2024-11-11 15:05:12 -0800 | [diff] [blame] | 18 | "fmt" |
| 19 | |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 20 | "github.com/google/blueprint/proptools" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 24 | registerBuildPropComponents(InitRegistrationContext) |
| 25 | } |
| 26 | |
| 27 | func registerBuildPropComponents(ctx RegistrationContext) { |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 28 | ctx.RegisterModuleType("build_prop", BuildPropFactory) |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 29 | ctx.RegisterModuleType("android_info", AndroidInfoFactory) |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | type buildPropProperties struct { |
| 33 | // Output file name. Defaults to "build.prop" |
| 34 | Stem *string |
| 35 | |
| 36 | // List of prop names to exclude. This affects not only common build properties but also |
| 37 | // properties in prop_files. |
| 38 | Block_list []string |
| 39 | |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 40 | // Files to be appended at the end of build.prop. These files are appended after |
| 41 | // post_process_props without any further checking. |
| 42 | Footer_files []string `android:"path"` |
| 43 | |
| 44 | // Path to a JSON file containing product configs. |
| 45 | Product_config *string `android:"path"` |
Inseob Kim | acf9174 | 2024-08-05 12:51:05 +0900 | [diff] [blame] | 46 | |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 47 | // Path to android-info.txt file containing board specific info. |
| 48 | // This is empty for build.prop of all partitions except vendor. |
| 49 | Android_info *string `android:"path"` |
| 50 | |
Inseob Kim | acf9174 | 2024-08-05 12:51:05 +0900 | [diff] [blame] | 51 | // Optional subdirectory under which this file is installed into |
| 52 | Relative_install_path *string |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | type buildPropModule struct { |
| 56 | ModuleBase |
| 57 | |
| 58 | properties buildPropProperties |
| 59 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 60 | outputFilePath Path |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 61 | installPath InstallPath |
| 62 | } |
| 63 | |
| 64 | func (p *buildPropModule) stem() string { |
| 65 | return proptools.StringDefault(p.properties.Stem, "build.prop") |
| 66 | } |
| 67 | |
Inseob Kim | d8538e5 | 2024-07-31 02:00:41 +0000 | [diff] [blame] | 68 | func (p *buildPropModule) propFiles(ctx ModuleContext) Paths { |
Yi-Yo Chiang | 3ffc37c | 2024-08-15 07:07:49 +0000 | [diff] [blame] | 69 | partition := p.partition(ctx.DeviceConfig()) |
Inseob Kim | d8538e5 | 2024-07-31 02:00:41 +0000 | [diff] [blame] | 70 | if partition == "system" { |
| 71 | return ctx.Config().SystemPropFiles(ctx) |
Inseob Kim | acf9174 | 2024-08-05 12:51:05 +0900 | [diff] [blame] | 72 | } else if partition == "system_ext" { |
| 73 | return ctx.Config().SystemExtPropFiles(ctx) |
Inseob Kim | 01d4f8b | 2024-08-08 17:47:14 +0900 | [diff] [blame] | 74 | } else if partition == "product" { |
| 75 | return ctx.Config().ProductPropFiles(ctx) |
Inseob Kim | 9a22c7e | 2024-08-26 15:58:09 +0900 | [diff] [blame] | 76 | } else if partition == "odm" { |
| 77 | return ctx.Config().OdmPropFiles(ctx) |
Spandan Das | 859cdef | 2024-10-25 21:06:18 +0000 | [diff] [blame] | 78 | } else if partition == "vendor" { |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 79 | if p.properties.Android_info != nil { |
| 80 | androidInfo := PathForModuleSrc(ctx, proptools.String(p.properties.Android_info)) |
| 81 | return append(ctx.Config().VendorPropFiles(ctx), androidInfo) |
| 82 | } |
Spandan Das | 859cdef | 2024-10-25 21:06:18 +0000 | [diff] [blame] | 83 | return ctx.Config().VendorPropFiles(ctx) |
Inseob Kim | d8538e5 | 2024-07-31 02:00:41 +0000 | [diff] [blame] | 84 | } |
| 85 | return nil |
| 86 | } |
| 87 | |
Inseob Kim | bc4ef22 | 2024-07-31 02:00:41 +0000 | [diff] [blame] | 88 | func shouldAddBuildThumbprint(config Config) bool { |
| 89 | knownOemProperties := []string{ |
| 90 | "ro.product.brand", |
| 91 | "ro.product.name", |
| 92 | "ro.product.device", |
| 93 | } |
| 94 | |
| 95 | for _, knownProp := range knownOemProperties { |
| 96 | if InList(knownProp, config.OemProperties()) { |
| 97 | return true |
| 98 | } |
| 99 | } |
| 100 | return false |
| 101 | } |
| 102 | |
Inseob Kim | 01d4f8b | 2024-08-08 17:47:14 +0900 | [diff] [blame] | 103 | // Can't use PartitionTag() because PartitionTag() returns the partition this module is actually |
| 104 | // installed (e.g. odm module's partition tag can be either "odm" or "vendor") |
| 105 | func (p *buildPropModule) partition(config DeviceConfig) string { |
| 106 | if p.SocSpecific() { |
| 107 | return "vendor" |
| 108 | } else if p.DeviceSpecific() { |
| 109 | return "odm" |
| 110 | } else if p.ProductSpecific() { |
| 111 | return "product" |
| 112 | } else if p.SystemExtSpecific() { |
| 113 | return "system_ext" |
Spandan Das | b9cef3b | 2024-11-06 22:08:28 +0000 | [diff] [blame] | 114 | } else if p.InstallInSystemDlkm() { |
| 115 | return "system_dlkm" |
| 116 | } else if p.InstallInVendorDlkm() { |
| 117 | return "vendor_dlkm" |
| 118 | } else if p.InstallInOdmDlkm() { |
| 119 | return "odm_dlkm" |
Cole Faust | 4385d35 | 2024-11-12 15:13:37 -0800 | [diff] [blame] | 120 | } else if p.InstallInRamdisk() { |
| 121 | // From this hardcoding in make: |
| 122 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/sysprop.mk;l=311;drc=274435657e4682e5cee3fffd11fb301ab32a828d |
| 123 | return "bootimage" |
Inseob Kim | 01d4f8b | 2024-08-08 17:47:14 +0900 | [diff] [blame] | 124 | } |
| 125 | return "system" |
| 126 | } |
| 127 | |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 128 | func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 129 | if !p.SocSpecific() && p.properties.Android_info != nil { |
| 130 | ctx.ModuleErrorf("Android_info cannot be set if build.prop is not installed in vendor partition") |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 131 | } |
| 132 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 133 | outputFilePath := PathForModuleOut(ctx, "build.prop") |
Spandan Das | c32e046 | 2024-11-05 17:55:39 +0000 | [diff] [blame] | 134 | |
Inseob Kim | 01d4f8b | 2024-08-08 17:47:14 +0900 | [diff] [blame] | 135 | partition := p.partition(ctx.DeviceConfig()) |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 136 | |
| 137 | rule := NewRuleBuilder(pctx, ctx) |
| 138 | |
| 139 | config := ctx.Config() |
| 140 | |
| 141 | cmd := rule.Command().BuiltTool("gen_build_prop") |
| 142 | |
| 143 | cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx)) |
| 144 | cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx)) |
| 145 | // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding |
| 146 | // on every incremental build. |
| 147 | cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String()) |
| 148 | // Export build thumbprint only if the product has specified at least one oem fingerprint property |
| 149 | // b/17888863 |
| 150 | if shouldAddBuildThumbprint(config) { |
| 151 | // In the previous make implementation, a dependency was not added on the thumbprint file |
| 152 | cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String()) |
| 153 | } |
| 154 | cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME")) |
| 155 | // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental |
| 156 | // build. |
| 157 | cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE")) |
| 158 | cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx)) |
| 159 | cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config))) |
| 160 | cmd.FlagWithArg("--partition=", partition) |
Inseob Kim | 01d4f8b | 2024-08-08 17:47:14 +0900 | [diff] [blame] | 161 | cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx)) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 162 | cmd.FlagWithOutput("--out=", outputFilePath) |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 163 | |
| 164 | postProcessCmd := rule.Command().BuiltTool("post_process_props") |
| 165 | if ctx.DeviceConfig().BuildBrokenDupSysprop() { |
| 166 | postProcessCmd.Flag("--allow-dup") |
| 167 | } |
| 168 | postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String()) |
Inseob Kim | 6bd92d5 | 2024-07-31 02:01:03 +0000 | [diff] [blame] | 169 | if ctx.Config().EnableUffdGc() == "default" { |
| 170 | postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt")) |
| 171 | } else { |
| 172 | // still need to pass an empty string to kernel-version-file-for-uffd-gc |
| 173 | postProcessCmd.FlagWithArg("--kernel-version-file-for-uffd-gc ", `""`) |
| 174 | } |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 175 | postProcessCmd.Text(outputFilePath.String()) |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 176 | postProcessCmd.Flags(p.properties.Block_list) |
| 177 | |
Nick Chalko | b905931 | 2024-11-11 15:05:12 -0800 | [diff] [blame] | 178 | for _, footer := range p.properties.Footer_files { |
| 179 | path := PathForModuleSrc(ctx, footer) |
| 180 | rule.appendText(outputFilePath, "####################################") |
| 181 | rule.appendTextf(outputFilePath, "# Adding footer from %v", footer) |
| 182 | rule.appendTextf(outputFilePath, "# with path %v", path) |
| 183 | rule.appendText(outputFilePath, "####################################") |
| 184 | rule.Command().Text("cat").FlagWithInput("", path).FlagWithArg(">> ", outputFilePath.String()) |
| 185 | } |
| 186 | |
| 187 | rule.appendText(outputFilePath, "# end of file") |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 188 | |
| 189 | rule.Build(ctx.ModuleName(), "generating build.prop") |
| 190 | |
Inseob Kim | acf9174 | 2024-08-05 12:51:05 +0900 | [diff] [blame] | 191 | p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path)) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 192 | ctx.InstallFile(p.installPath, p.stem(), outputFilePath) |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 193 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 194 | ctx.SetOutputFiles(Paths{outputFilePath}, "") |
| 195 | p.outputFilePath = outputFilePath |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 196 | } |
| 197 | |
Nick Chalko | b905931 | 2024-11-11 15:05:12 -0800 | [diff] [blame] | 198 | func (r *RuleBuilder) appendText(path ModuleOutPath, text string) { |
| 199 | r.Command().Text("echo").Text(proptools.NinjaAndShellEscape(text)).FlagWithArg(">> ", path.String()) |
| 200 | } |
| 201 | |
| 202 | func (r *RuleBuilder) appendTextf(path ModuleOutPath, format string, a ...any) { |
| 203 | r.appendText(path, fmt.Sprintf(format, a...)) |
| 204 | } |
| 205 | |
Inseob Kim | bc4ef22 | 2024-07-31 02:00:41 +0000 | [diff] [blame] | 206 | func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries { |
| 207 | return []AndroidMkEntries{{ |
| 208 | Class: "ETC", |
| 209 | OutputFile: OptionalPathForPath(p.outputFilePath), |
| 210 | ExtraEntries: []AndroidMkExtraEntriesFunc{ |
| 211 | func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) { |
| 212 | entries.SetString("LOCAL_MODULE_PATH", p.installPath.String()) |
| 213 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) |
| 214 | }, |
| 215 | }, |
| 216 | }} |
| 217 | } |
| 218 | |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 219 | // build_prop module generates {partition}/build.prop file. At first common build properties are |
| 220 | // printed based on Soong config variables. And then prop_files are printed as-is. Finally, |
| 221 | // post_process_props tool is run to check if the result build.prop is valid or not. |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 222 | func BuildPropFactory() Module { |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 223 | module := &buildPropModule{} |
| 224 | module.AddProperties(&module.properties) |
| 225 | InitAndroidArchModule(module, DeviceSupported, MultilibCommon) |
| 226 | return module |
| 227 | } |