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