blob: 838947045b31502d279f7f837643fe7907f19e2c [file] [log] [blame]
Inseob Kim2da72af2024-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() {
Spandan Dasc32e0462024-11-05 17:55:39 +000022 registerBuildPropComponents(InitRegistrationContext)
23}
24
25func registerBuildPropComponents(ctx RegistrationContext) {
Spandan Das168098c2024-10-28 19:44:34 +000026 ctx.RegisterModuleType("build_prop", BuildPropFactory)
Spandan Dasc32e0462024-11-05 17:55:39 +000027 ctx.RegisterModuleType("android_info", AndroidInfoFactory)
Inseob Kim2da72af2024-06-18 11:09:12 +090028}
29
30type 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 Kim2da72af2024-06-18 11:09:12 +090038 // 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 Kimacf91742024-08-05 12:51:05 +090044
Spandan Dasc32e0462024-11-05 17:55:39 +000045 // 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 Kimacf91742024-08-05 12:51:05 +090049 // Optional subdirectory under which this file is installed into
50 Relative_install_path *string
Inseob Kim2da72af2024-06-18 11:09:12 +090051}
52
53type buildPropModule struct {
54 ModuleBase
55
56 properties buildPropProperties
57
58 outputFilePath OutputPath
59 installPath InstallPath
60}
61
62func (p *buildPropModule) stem() string {
63 return proptools.StringDefault(p.properties.Stem, "build.prop")
64}
65
Inseob Kimd8538e52024-07-31 02:00:41 +000066func (p *buildPropModule) propFiles(ctx ModuleContext) Paths {
Yi-Yo Chiang3ffc37c2024-08-15 07:07:49 +000067 partition := p.partition(ctx.DeviceConfig())
Inseob Kimd8538e52024-07-31 02:00:41 +000068 if partition == "system" {
69 return ctx.Config().SystemPropFiles(ctx)
Inseob Kimacf91742024-08-05 12:51:05 +090070 } else if partition == "system_ext" {
71 return ctx.Config().SystemExtPropFiles(ctx)
Inseob Kim01d4f8b2024-08-08 17:47:14 +090072 } else if partition == "product" {
73 return ctx.Config().ProductPropFiles(ctx)
Inseob Kim9a22c7e2024-08-26 15:58:09 +090074 } else if partition == "odm" {
75 return ctx.Config().OdmPropFiles(ctx)
Spandan Das859cdef2024-10-25 21:06:18 +000076 } else if partition == "vendor" {
Spandan Dasc32e0462024-11-05 17:55:39 +000077 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 Das859cdef2024-10-25 21:06:18 +000081 return ctx.Config().VendorPropFiles(ctx)
Inseob Kimd8538e52024-07-31 02:00:41 +000082 }
83 return nil
84}
85
Inseob Kimbc4ef222024-07-31 02:00:41 +000086func 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 Kim01d4f8b2024-08-08 17:47:14 +0900101// 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")
103func (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 Dasb9cef3b2024-11-06 22:08:28 +0000112 } 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 Kim01d4f8b2024-08-08 17:47:14 +0900118 }
119 return "system"
120}
121
122var validPartitions = []string{
123 "system",
124 "system_ext",
125 "product",
126 "odm",
Spandan Das859cdef2024-10-25 21:06:18 +0000127 "vendor",
Spandan Dasb9cef3b2024-11-06 22:08:28 +0000128 "system_dlkm",
129 "vendor_dlkm",
130 "odm_dlkm",
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900131}
132
Inseob Kim2da72af2024-06-18 11:09:12 +0900133func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Spandan Dasc32e0462024-11-05 17:55:39 +0000134 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 Kim2da72af2024-06-18 11:09:12 +0900136 }
137
Spandan Dasc32e0462024-11-05 17:55:39 +0000138 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
139
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900140 partition := p.partition(ctx.DeviceConfig())
141 if !InList(partition, validPartitions) {
142 ctx.PropertyErrorf("partition", "unsupported partition %q: only %q are supported", partition, validPartitions)
Inseob Kim2da72af2024-06-18 11:09:12 +0900143 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 Kim01d4f8b2024-08-08 17:47:14 +0900170 cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900171 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 Kim6bd92d52024-07-31 02:01:03 +0000178 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 Kim2da72af2024-06-18 11:09:12 +0900184 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 Kimacf91742024-08-05 12:51:05 +0900191 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Inseob Kim2da72af2024-06-18 11:09:12 +0900192 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
193
194 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
195}
196
Inseob Kimbc4ef222024-07-31 02:00:41 +0000197func (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 Kim2da72af2024-06-18 11:09:12 +0900210// 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 Das168098c2024-10-28 19:44:34 +0000213func BuildPropFactory() Module {
Inseob Kim2da72af2024-06-18 11:09:12 +0900214 module := &buildPropModule{}
215 module.AddProperties(&module.properties)
216 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
217 return module
218}