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