blob: b127755c88b4a501f22fcc14f4f181bf6dff6dad [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() {
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 Kim2da72af2024-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 Kimacf91742024-08-05 12:51:05 +090040
41 // Optional subdirectory under which this file is installed into
42 Relative_install_path *string
Inseob Kim2da72af2024-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 Kimd8538e52024-07-31 02:00:41 +000058func (p *buildPropModule) propFiles(ctx ModuleContext) Paths {
59 partition := p.PartitionTag(ctx.DeviceConfig())
60 if partition == "system" {
61 return ctx.Config().SystemPropFiles(ctx)
Inseob Kimacf91742024-08-05 12:51:05 +090062 } else if partition == "system_ext" {
63 return ctx.Config().SystemExtPropFiles(ctx)
Inseob Kim01d4f8b2024-08-08 17:47:14 +090064 } else if partition == "product" {
65 return ctx.Config().ProductPropFiles(ctx)
Inseob Kimd8538e52024-07-31 02:00:41 +000066 }
67 return nil
68}
69
Inseob Kimbc4ef222024-07-31 02:00:41 +000070func shouldAddBuildThumbprint(config Config) bool {
71 knownOemProperties := []string{
72 "ro.product.brand",
73 "ro.product.name",
74 "ro.product.device",
75 }
76
77 for _, knownProp := range knownOemProperties {
78 if InList(knownProp, config.OemProperties()) {
79 return true
80 }
81 }
82 return false
83}
84
Inseob Kim01d4f8b2024-08-08 17:47:14 +090085// Can't use PartitionTag() because PartitionTag() returns the partition this module is actually
86// installed (e.g. odm module's partition tag can be either "odm" or "vendor")
87func (p *buildPropModule) partition(config DeviceConfig) string {
88 if p.SocSpecific() {
89 return "vendor"
90 } else if p.DeviceSpecific() {
91 return "odm"
92 } else if p.ProductSpecific() {
93 return "product"
94 } else if p.SystemExtSpecific() {
95 return "system_ext"
96 }
97 return "system"
98}
99
100var validPartitions = []string{
101 "system",
102 "system_ext",
103 "product",
104 "odm",
105}
106
Inseob Kim2da72af2024-06-18 11:09:12 +0900107func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
108 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
109 if !ctx.Config().KatiEnabled() {
110 WriteFileRule(ctx, p.outputFilePath, "# no build.prop if kati is disabled")
Inseob Kim88b109e2024-07-31 02:00:41 +0000111 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
Inseob Kim2da72af2024-06-18 11:09:12 +0900112 return
113 }
114
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900115 partition := p.partition(ctx.DeviceConfig())
116 if !InList(partition, validPartitions) {
117 ctx.PropertyErrorf("partition", "unsupported partition %q: only %q are supported", partition, validPartitions)
Inseob Kim2da72af2024-06-18 11:09:12 +0900118 return
119 }
120
121 rule := NewRuleBuilder(pctx, ctx)
122
123 config := ctx.Config()
124
125 cmd := rule.Command().BuiltTool("gen_build_prop")
126
127 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
128 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
129 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
130 // on every incremental build.
131 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
132 // Export build thumbprint only if the product has specified at least one oem fingerprint property
133 // b/17888863
134 if shouldAddBuildThumbprint(config) {
135 // In the previous make implementation, a dependency was not added on the thumbprint file
136 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
137 }
138 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
139 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
140 // build.
141 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
142 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
143 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
144 cmd.FlagWithArg("--partition=", partition)
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900145 cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900146 cmd.FlagWithOutput("--out=", p.outputFilePath)
147
148 postProcessCmd := rule.Command().BuiltTool("post_process_props")
149 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
150 postProcessCmd.Flag("--allow-dup")
151 }
152 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Inseob Kim6bd92d52024-07-31 02:01:03 +0000153 if ctx.Config().EnableUffdGc() == "default" {
154 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
155 } else {
156 // still need to pass an empty string to kernel-version-file-for-uffd-gc
157 postProcessCmd.FlagWithArg("--kernel-version-file-for-uffd-gc ", `""`)
158 }
Inseob Kim2da72af2024-06-18 11:09:12 +0900159 postProcessCmd.Text(p.outputFilePath.String())
160 postProcessCmd.Flags(p.properties.Block_list)
161
162 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
163
164 rule.Build(ctx.ModuleName(), "generating build.prop")
165
Inseob Kimacf91742024-08-05 12:51:05 +0900166 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Inseob Kim2da72af2024-06-18 11:09:12 +0900167 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
168
169 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
170}
171
Inseob Kimbc4ef222024-07-31 02:00:41 +0000172func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
173 return []AndroidMkEntries{{
174 Class: "ETC",
175 OutputFile: OptionalPathForPath(p.outputFilePath),
176 ExtraEntries: []AndroidMkExtraEntriesFunc{
177 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
178 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
179 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
180 },
181 },
182 }}
183}
184
Inseob Kim2da72af2024-06-18 11:09:12 +0900185// build_prop module generates {partition}/build.prop file. At first common build properties are
186// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
187// post_process_props tool is run to check if the result build.prop is valid or not.
188func buildPropFactory() Module {
189 module := &buildPropModule{}
190 module.AddProperties(&module.properties)
191 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
192 return module
193}