blob: ede93ed20535ac811aeee8ce9b455fd5f4947545 [file] [log] [blame]
Inseob Kim320628f2024-06-18 11:09:12 +09001// 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
15package android
16
17import (
18 "github.com/google/blueprint/proptools"
19)
20
21func init() {
22 ctx := InitRegistrationContext
23 ctx.RegisterModuleType("build_prop", buildPropFactory)
24}
25
26type 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 Kim320628f2024-06-18 11:09:12 +090034 // 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 Kima8bc86a2024-08-05 12:51:05 +090040
41 // Optional subdirectory under which this file is installed into
42 Relative_install_path *string
Inseob Kim320628f2024-06-18 11:09:12 +090043}
44
45type buildPropModule struct {
46 ModuleBase
47
48 properties buildPropProperties
49
50 outputFilePath OutputPath
51 installPath InstallPath
52}
53
54func (p *buildPropModule) stem() string {
55 return proptools.StringDefault(p.properties.Stem, "build.prop")
56}
57
Inseob Kimda1f6282024-07-31 02:00:41 +000058func (p *buildPropModule) propFiles(ctx ModuleContext) Paths {
Yi-Yo Chiang140c2b42024-08-15 07:07:49 +000059 partition := p.partition(ctx.DeviceConfig())
Inseob Kimda1f6282024-07-31 02:00:41 +000060 if partition == "system" {
61 return ctx.Config().SystemPropFiles(ctx)
Inseob Kima8bc86a2024-08-05 12:51:05 +090062 } else if partition == "system_ext" {
63 return ctx.Config().SystemExtPropFiles(ctx)
Inseob Kim46288272024-08-08 17:47:14 +090064 } else if partition == "product" {
65 return ctx.Config().ProductPropFiles(ctx)
Inseob Kim97c7d582024-08-26 15:58:09 +090066 } else if partition == "odm" {
67 return ctx.Config().OdmPropFiles(ctx)
Inseob Kimda1f6282024-07-31 02:00:41 +000068 }
69 return nil
70}
71
Inseob Kim52ce1012024-07-31 02:00:41 +000072func 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 Kim46288272024-08-08 17:47:14 +090087// 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")
89func (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
102var validPartitions = []string{
103 "system",
104 "system_ext",
105 "product",
106 "odm",
107}
108
Inseob Kim320628f2024-06-18 11:09:12 +0900109func (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 Kim6d8b7a62024-07-31 02:00:41 +0000113 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
Inseob Kim320628f2024-06-18 11:09:12 +0900114 return
115 }
116
Inseob Kim46288272024-08-08 17:47:14 +0900117 partition := p.partition(ctx.DeviceConfig())
118 if !InList(partition, validPartitions) {
119 ctx.PropertyErrorf("partition", "unsupported partition %q: only %q are supported", partition, validPartitions)
Inseob Kim320628f2024-06-18 11:09:12 +0900120 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 Kim46288272024-08-08 17:47:14 +0900147 cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx))
Inseob Kim320628f2024-06-18 11:09:12 +0900148 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 Kim769a8ee2024-07-31 02:01:03 +0000155 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 Kim320628f2024-06-18 11:09:12 +0900161 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 Kima8bc86a2024-08-05 12:51:05 +0900168 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Inseob Kim320628f2024-06-18 11:09:12 +0900169 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
170
171 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
172}
173
Inseob Kim52ce1012024-07-31 02:00:41 +0000174func (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 Kim320628f2024-06-18 11:09:12 +0900187// 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.
190func buildPropFactory() Module {
191 module := &buildPropModule{}
192 module.AddProperties(&module.properties)
193 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
194 return module
195}