blob: 7c3c50645601689ac5d0f4de9356439c3968ac00 [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
Spandan Das168098c2024-10-28 19:44:34 +000023 ctx.RegisterModuleType("build_prop", BuildPropFactory)
Inseob Kim2da72af2024-06-18 11:09:12 +090024}
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 {
Yi-Yo Chiang3ffc37c2024-08-15 07:07:49 +000059 partition := p.partition(ctx.DeviceConfig())
Inseob Kimd8538e52024-07-31 02:00:41 +000060 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 Kim9a22c7e2024-08-26 15:58:09 +090066 } else if partition == "odm" {
67 return ctx.Config().OdmPropFiles(ctx)
Spandan Das859cdef2024-10-25 21:06:18 +000068 } else if partition == "vendor" {
69 // TODO (b/375500423): Add android-info.txt to prop files
70 return ctx.Config().VendorPropFiles(ctx)
Inseob Kimd8538e52024-07-31 02:00:41 +000071 }
72 return nil
73}
74
Inseob Kimbc4ef222024-07-31 02:00:41 +000075func shouldAddBuildThumbprint(config Config) bool {
76 knownOemProperties := []string{
77 "ro.product.brand",
78 "ro.product.name",
79 "ro.product.device",
80 }
81
82 for _, knownProp := range knownOemProperties {
83 if InList(knownProp, config.OemProperties()) {
84 return true
85 }
86 }
87 return false
88}
89
Inseob Kim01d4f8b2024-08-08 17:47:14 +090090// Can't use PartitionTag() because PartitionTag() returns the partition this module is actually
91// installed (e.g. odm module's partition tag can be either "odm" or "vendor")
92func (p *buildPropModule) partition(config DeviceConfig) string {
93 if p.SocSpecific() {
94 return "vendor"
95 } else if p.DeviceSpecific() {
96 return "odm"
97 } else if p.ProductSpecific() {
98 return "product"
99 } else if p.SystemExtSpecific() {
100 return "system_ext"
101 }
102 return "system"
103}
104
105var validPartitions = []string{
106 "system",
107 "system_ext",
108 "product",
109 "odm",
Spandan Das859cdef2024-10-25 21:06:18 +0000110 "vendor",
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900111}
112
Inseob Kim2da72af2024-06-18 11:09:12 +0900113func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
114 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
115 if !ctx.Config().KatiEnabled() {
116 WriteFileRule(ctx, p.outputFilePath, "# no build.prop if kati is disabled")
Inseob Kim88b109e2024-07-31 02:00:41 +0000117 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
Inseob Kim2da72af2024-06-18 11:09:12 +0900118 return
119 }
120
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900121 partition := p.partition(ctx.DeviceConfig())
122 if !InList(partition, validPartitions) {
123 ctx.PropertyErrorf("partition", "unsupported partition %q: only %q are supported", partition, validPartitions)
Inseob Kim2da72af2024-06-18 11:09:12 +0900124 return
125 }
126
127 rule := NewRuleBuilder(pctx, ctx)
128
129 config := ctx.Config()
130
131 cmd := rule.Command().BuiltTool("gen_build_prop")
132
133 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
134 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
135 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
136 // on every incremental build.
137 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
138 // Export build thumbprint only if the product has specified at least one oem fingerprint property
139 // b/17888863
140 if shouldAddBuildThumbprint(config) {
141 // In the previous make implementation, a dependency was not added on the thumbprint file
142 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
143 }
144 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
145 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
146 // build.
147 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
148 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
149 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
150 cmd.FlagWithArg("--partition=", partition)
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900151 cmd.FlagForEachInput("--prop-files=", p.propFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900152 cmd.FlagWithOutput("--out=", p.outputFilePath)
153
154 postProcessCmd := rule.Command().BuiltTool("post_process_props")
155 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
156 postProcessCmd.Flag("--allow-dup")
157 }
158 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Inseob Kim6bd92d52024-07-31 02:01:03 +0000159 if ctx.Config().EnableUffdGc() == "default" {
160 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
161 } else {
162 // still need to pass an empty string to kernel-version-file-for-uffd-gc
163 postProcessCmd.FlagWithArg("--kernel-version-file-for-uffd-gc ", `""`)
164 }
Inseob Kim2da72af2024-06-18 11:09:12 +0900165 postProcessCmd.Text(p.outputFilePath.String())
166 postProcessCmd.Flags(p.properties.Block_list)
167
168 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
169
170 rule.Build(ctx.ModuleName(), "generating build.prop")
171
Inseob Kimacf91742024-08-05 12:51:05 +0900172 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Inseob Kim2da72af2024-06-18 11:09:12 +0900173 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
174
175 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
176}
177
Inseob Kimbc4ef222024-07-31 02:00:41 +0000178func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
179 return []AndroidMkEntries{{
180 Class: "ETC",
181 OutputFile: OptionalPathForPath(p.outputFilePath),
182 ExtraEntries: []AndroidMkExtraEntriesFunc{
183 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
184 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
185 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
186 },
187 },
188 }}
189}
190
Inseob Kim2da72af2024-06-18 11:09:12 +0900191// build_prop module generates {partition}/build.prop file. At first common build properties are
192// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
193// post_process_props tool is run to check if the result build.prop is valid or not.
Spandan Das168098c2024-10-28 19:44:34 +0000194func BuildPropFactory() Module {
Inseob Kim2da72af2024-06-18 11:09:12 +0900195 module := &buildPropModule{}
196 module.AddProperties(&module.properties)
197 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
198 return module
199}