blob: 554768077f232dc6640403630e8f22ae4dc7e9db [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"
112 }
113 return "system"
114}
115
116var validPartitions = []string{
117 "system",
118 "system_ext",
119 "product",
120 "odm",
Spandan Das859cdef2024-10-25 21:06:18 +0000121 "vendor",
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900122}
123
Inseob Kim2da72af2024-06-18 11:09:12 +0900124func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Spandan Dasc32e0462024-11-05 17:55:39 +0000125 if !p.SocSpecific() && p.properties.Android_info != nil {
126 ctx.ModuleErrorf("Android_info cannot be set if build.prop is not installed in vendor partition")
Inseob Kim2da72af2024-06-18 11:09:12 +0900127 }
128
Spandan Dasc32e0462024-11-05 17:55:39 +0000129 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
130
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900131 partition := p.partition(ctx.DeviceConfig())
132 if !InList(partition, validPartitions) {
133 ctx.PropertyErrorf("partition", "unsupported partition %q: only %q are supported", partition, validPartitions)
Inseob Kim2da72af2024-06-18 11:09:12 +0900134 return
135 }
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 Kim01d4f8b2024-08-08 17:47:14 +0900161 cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900162 cmd.FlagWithOutput("--out=", p.outputFilePath)
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 Kim6bd92d52024-07-31 02:01:03 +0000169 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 }
Inseob Kim2da72af2024-06-18 11:09:12 +0900175 postProcessCmd.Text(p.outputFilePath.String())
176 postProcessCmd.Flags(p.properties.Block_list)
177
178 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
179
180 rule.Build(ctx.ModuleName(), "generating build.prop")
181
Inseob Kimacf91742024-08-05 12:51:05 +0900182 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Inseob Kim2da72af2024-06-18 11:09:12 +0900183 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
184
185 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
186}
187
Inseob Kimbc4ef222024-07-31 02:00:41 +0000188func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
189 return []AndroidMkEntries{{
190 Class: "ETC",
191 OutputFile: OptionalPathForPath(p.outputFilePath),
192 ExtraEntries: []AndroidMkExtraEntriesFunc{
193 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
194 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
195 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
196 },
197 },
198 }}
199}
200
Inseob Kim2da72af2024-06-18 11:09:12 +0900201// build_prop module generates {partition}/build.prop file. At first common build properties are
202// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
203// post_process_props tool is run to check if the result build.prop is valid or not.
Spandan Das168098c2024-10-28 19:44:34 +0000204func BuildPropFactory() Module {
Inseob Kim2da72af2024-06-18 11:09:12 +0900205 module := &buildPropModule{}
206 module.AddProperties(&module.properties)
207 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
208 return module
209}