blob: 2f71bc03f004dc8420a4b85472bbc707ab01ca91 [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 (
Nick Chalkob9059312024-11-11 15:05:12 -080018 "fmt"
19
Inseob Kim2da72af2024-06-18 11:09:12 +090020 "github.com/google/blueprint/proptools"
21)
22
23func init() {
Spandan Dasc32e0462024-11-05 17:55:39 +000024 registerBuildPropComponents(InitRegistrationContext)
25}
26
27func registerBuildPropComponents(ctx RegistrationContext) {
Spandan Das168098c2024-10-28 19:44:34 +000028 ctx.RegisterModuleType("build_prop", BuildPropFactory)
Spandan Dasc32e0462024-11-05 17:55:39 +000029 ctx.RegisterModuleType("android_info", AndroidInfoFactory)
Inseob Kim2da72af2024-06-18 11:09:12 +090030}
31
32type buildPropProperties struct {
33 // Output file name. Defaults to "build.prop"
34 Stem *string
35
36 // List of prop names to exclude. This affects not only common build properties but also
37 // properties in prop_files.
38 Block_list []string
39
Inseob Kim2da72af2024-06-18 11:09:12 +090040 // Files to be appended at the end of build.prop. These files are appended after
41 // post_process_props without any further checking.
42 Footer_files []string `android:"path"`
43
44 // Path to a JSON file containing product configs.
45 Product_config *string `android:"path"`
Inseob Kimacf91742024-08-05 12:51:05 +090046
Spandan Dasc32e0462024-11-05 17:55:39 +000047 // Path to android-info.txt file containing board specific info.
48 // This is empty for build.prop of all partitions except vendor.
49 Android_info *string `android:"path"`
50
Inseob Kimacf91742024-08-05 12:51:05 +090051 // Optional subdirectory under which this file is installed into
52 Relative_install_path *string
Inseob Kim2da72af2024-06-18 11:09:12 +090053}
54
55type buildPropModule struct {
56 ModuleBase
57
58 properties buildPropProperties
59
Cole Faust4e9f5922024-11-13 16:09:23 -080060 outputFilePath Path
Inseob Kim2da72af2024-06-18 11:09:12 +090061 installPath InstallPath
62}
63
64func (p *buildPropModule) stem() string {
65 return proptools.StringDefault(p.properties.Stem, "build.prop")
66}
67
Inseob Kimd8538e52024-07-31 02:00:41 +000068func (p *buildPropModule) propFiles(ctx ModuleContext) Paths {
Yi-Yo Chiang3ffc37c2024-08-15 07:07:49 +000069 partition := p.partition(ctx.DeviceConfig())
Inseob Kimd8538e52024-07-31 02:00:41 +000070 if partition == "system" {
71 return ctx.Config().SystemPropFiles(ctx)
Inseob Kimacf91742024-08-05 12:51:05 +090072 } else if partition == "system_ext" {
73 return ctx.Config().SystemExtPropFiles(ctx)
Inseob Kim01d4f8b2024-08-08 17:47:14 +090074 } else if partition == "product" {
75 return ctx.Config().ProductPropFiles(ctx)
Inseob Kim9a22c7e2024-08-26 15:58:09 +090076 } else if partition == "odm" {
77 return ctx.Config().OdmPropFiles(ctx)
Spandan Das859cdef2024-10-25 21:06:18 +000078 } else if partition == "vendor" {
Spandan Dasc32e0462024-11-05 17:55:39 +000079 if p.properties.Android_info != nil {
80 androidInfo := PathForModuleSrc(ctx, proptools.String(p.properties.Android_info))
81 return append(ctx.Config().VendorPropFiles(ctx), androidInfo)
82 }
Spandan Das859cdef2024-10-25 21:06:18 +000083 return ctx.Config().VendorPropFiles(ctx)
Inseob Kimd8538e52024-07-31 02:00:41 +000084 }
85 return nil
86}
87
Inseob Kimbc4ef222024-07-31 02:00:41 +000088func shouldAddBuildThumbprint(config Config) bool {
89 knownOemProperties := []string{
90 "ro.product.brand",
91 "ro.product.name",
92 "ro.product.device",
93 }
94
95 for _, knownProp := range knownOemProperties {
96 if InList(knownProp, config.OemProperties()) {
97 return true
98 }
99 }
100 return false
101}
102
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900103// Can't use PartitionTag() because PartitionTag() returns the partition this module is actually
104// installed (e.g. odm module's partition tag can be either "odm" or "vendor")
105func (p *buildPropModule) partition(config DeviceConfig) string {
106 if p.SocSpecific() {
107 return "vendor"
108 } else if p.DeviceSpecific() {
109 return "odm"
110 } else if p.ProductSpecific() {
111 return "product"
112 } else if p.SystemExtSpecific() {
113 return "system_ext"
Spandan Dasb9cef3b2024-11-06 22:08:28 +0000114 } else if p.InstallInSystemDlkm() {
115 return "system_dlkm"
116 } else if p.InstallInVendorDlkm() {
117 return "vendor_dlkm"
118 } else if p.InstallInOdmDlkm() {
119 return "odm_dlkm"
Cole Faust4385d352024-11-12 15:13:37 -0800120 } else if p.InstallInRamdisk() {
121 // From this hardcoding in make:
122 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/sysprop.mk;l=311;drc=274435657e4682e5cee3fffd11fb301ab32a828d
123 return "bootimage"
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900124 }
125 return "system"
126}
127
Inseob Kim2da72af2024-06-18 11:09:12 +0900128func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Spandan Dasc32e0462024-11-05 17:55:39 +0000129 if !p.SocSpecific() && p.properties.Android_info != nil {
130 ctx.ModuleErrorf("Android_info cannot be set if build.prop is not installed in vendor partition")
Inseob Kim2da72af2024-06-18 11:09:12 +0900131 }
132
Cole Faust4e9f5922024-11-13 16:09:23 -0800133 outputFilePath := PathForModuleOut(ctx, "build.prop")
Spandan Dasc32e0462024-11-05 17:55:39 +0000134
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900135 partition := p.partition(ctx.DeviceConfig())
Inseob Kim2da72af2024-06-18 11:09:12 +0900136
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))
Cole Faust4e9f5922024-11-13 16:09:23 -0800162 cmd.FlagWithOutput("--out=", outputFilePath)
Inseob Kim2da72af2024-06-18 11:09:12 +0900163
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 }
Cole Faust4e9f5922024-11-13 16:09:23 -0800175 postProcessCmd.Text(outputFilePath.String())
Inseob Kim2da72af2024-06-18 11:09:12 +0900176 postProcessCmd.Flags(p.properties.Block_list)
177
Nick Chalkob9059312024-11-11 15:05:12 -0800178 for _, footer := range p.properties.Footer_files {
179 path := PathForModuleSrc(ctx, footer)
180 rule.appendText(outputFilePath, "####################################")
181 rule.appendTextf(outputFilePath, "# Adding footer from %v", footer)
182 rule.appendTextf(outputFilePath, "# with path %v", path)
183 rule.appendText(outputFilePath, "####################################")
184 rule.Command().Text("cat").FlagWithInput("", path).FlagWithArg(">> ", outputFilePath.String())
185 }
186
187 rule.appendText(outputFilePath, "# end of file")
Inseob Kim2da72af2024-06-18 11:09:12 +0900188
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))
Cole Faust4e9f5922024-11-13 16:09:23 -0800192 ctx.InstallFile(p.installPath, p.stem(), outputFilePath)
Inseob Kim2da72af2024-06-18 11:09:12 +0900193
Cole Faust4e9f5922024-11-13 16:09:23 -0800194 ctx.SetOutputFiles(Paths{outputFilePath}, "")
195 p.outputFilePath = outputFilePath
Inseob Kim2da72af2024-06-18 11:09:12 +0900196}
197
Nick Chalkob9059312024-11-11 15:05:12 -0800198func (r *RuleBuilder) appendText(path ModuleOutPath, text string) {
199 r.Command().Text("echo").Text(proptools.NinjaAndShellEscape(text)).FlagWithArg(">> ", path.String())
200}
201
202func (r *RuleBuilder) appendTextf(path ModuleOutPath, format string, a ...any) {
203 r.appendText(path, fmt.Sprintf(format, a...))
204}
205
Inseob Kimbc4ef222024-07-31 02:00:41 +0000206func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
207 return []AndroidMkEntries{{
208 Class: "ETC",
209 OutputFile: OptionalPathForPath(p.outputFilePath),
210 ExtraEntries: []AndroidMkExtraEntriesFunc{
211 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
212 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
213 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
214 },
215 },
216 }}
217}
218
Inseob Kim2da72af2024-06-18 11:09:12 +0900219// build_prop module generates {partition}/build.prop file. At first common build properties are
220// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
221// post_process_props tool is run to check if the result build.prop is valid or not.
Spandan Das168098c2024-10-28 19:44:34 +0000222func BuildPropFactory() Module {
Inseob Kim2da72af2024-06-18 11:09:12 +0900223 module := &buildPropModule{}
224 module.AddProperties(&module.properties)
225 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
226 return module
227}