blob: cda56f1e00fa8b28b11558fa8ef78ab9e80186ed [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
Cole Faust4e9f5922024-11-13 16:09:23 -080058 outputFilePath Path
Inseob Kim2da72af2024-06-18 11:09:12 +090059 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"
Cole Faust4385d352024-11-12 15:13:37 -0800118 } else if p.InstallInRamdisk() {
119 // From this hardcoding in make:
120 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/sysprop.mk;l=311;drc=274435657e4682e5cee3fffd11fb301ab32a828d
121 return "bootimage"
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900122 }
123 return "system"
124}
125
Inseob Kim2da72af2024-06-18 11:09:12 +0900126func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Spandan Dasc32e0462024-11-05 17:55:39 +0000127 if !p.SocSpecific() && p.properties.Android_info != nil {
128 ctx.ModuleErrorf("Android_info cannot be set if build.prop is not installed in vendor partition")
Inseob Kim2da72af2024-06-18 11:09:12 +0900129 }
130
Cole Faust4e9f5922024-11-13 16:09:23 -0800131 outputFilePath := PathForModuleOut(ctx, "build.prop")
Spandan Dasc32e0462024-11-05 17:55:39 +0000132
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900133 partition := p.partition(ctx.DeviceConfig())
Inseob Kim2da72af2024-06-18 11:09:12 +0900134
135 rule := NewRuleBuilder(pctx, ctx)
136
137 config := ctx.Config()
138
139 cmd := rule.Command().BuiltTool("gen_build_prop")
140
141 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
142 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
143 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
144 // on every incremental build.
145 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
146 // Export build thumbprint only if the product has specified at least one oem fingerprint property
147 // b/17888863
148 if shouldAddBuildThumbprint(config) {
149 // In the previous make implementation, a dependency was not added on the thumbprint file
150 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
151 }
152 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
153 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
154 // build.
155 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
156 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
157 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
158 cmd.FlagWithArg("--partition=", partition)
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900159 cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx))
Cole Faust4e9f5922024-11-13 16:09:23 -0800160 cmd.FlagWithOutput("--out=", outputFilePath)
Inseob Kim2da72af2024-06-18 11:09:12 +0900161
162 postProcessCmd := rule.Command().BuiltTool("post_process_props")
163 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
164 postProcessCmd.Flag("--allow-dup")
165 }
166 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Inseob Kim6bd92d52024-07-31 02:01:03 +0000167 if ctx.Config().EnableUffdGc() == "default" {
168 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
169 } else {
170 // still need to pass an empty string to kernel-version-file-for-uffd-gc
171 postProcessCmd.FlagWithArg("--kernel-version-file-for-uffd-gc ", `""`)
172 }
Cole Faust4e9f5922024-11-13 16:09:23 -0800173 postProcessCmd.Text(outputFilePath.String())
Inseob Kim2da72af2024-06-18 11:09:12 +0900174 postProcessCmd.Flags(p.properties.Block_list)
175
Cole Faust4e9f5922024-11-13 16:09:23 -0800176 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", outputFilePath.String())
Inseob Kim2da72af2024-06-18 11:09:12 +0900177
178 rule.Build(ctx.ModuleName(), "generating build.prop")
179
Inseob Kimacf91742024-08-05 12:51:05 +0900180 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Cole Faust4e9f5922024-11-13 16:09:23 -0800181 ctx.InstallFile(p.installPath, p.stem(), outputFilePath)
Inseob Kim2da72af2024-06-18 11:09:12 +0900182
Cole Faust4e9f5922024-11-13 16:09:23 -0800183 ctx.SetOutputFiles(Paths{outputFilePath}, "")
184 p.outputFilePath = outputFilePath
Inseob Kim2da72af2024-06-18 11:09:12 +0900185}
186
Inseob Kimbc4ef222024-07-31 02:00:41 +0000187func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
188 return []AndroidMkEntries{{
189 Class: "ETC",
190 OutputFile: OptionalPathForPath(p.outputFilePath),
191 ExtraEntries: []AndroidMkExtraEntriesFunc{
192 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
193 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
194 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
195 },
196 },
197 }}
198}
199
Inseob Kim2da72af2024-06-18 11:09:12 +0900200// build_prop module generates {partition}/build.prop file. At first common build properties are
201// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
202// post_process_props tool is run to check if the result build.prop is valid or not.
Spandan Das168098c2024-10-28 19:44:34 +0000203func BuildPropFactory() Module {
Inseob Kim2da72af2024-06-18 11:09:12 +0900204 module := &buildPropModule{}
205 module.AddProperties(&module.properties)
206 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
207 return module
208}