blob: d48d94d4e161bb03b1a0e4c106c48e251c95b78c [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 Kimd8538e52024-07-31 02:00:41 +000064 }
65 return nil
66}
67
Inseob Kimbc4ef222024-07-31 02:00:41 +000068func shouldAddBuildThumbprint(config Config) bool {
69 knownOemProperties := []string{
70 "ro.product.brand",
71 "ro.product.name",
72 "ro.product.device",
73 }
74
75 for _, knownProp := range knownOemProperties {
76 if InList(knownProp, config.OemProperties()) {
77 return true
78 }
79 }
80 return false
81}
82
Inseob Kim2da72af2024-06-18 11:09:12 +090083func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
84 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
85 if !ctx.Config().KatiEnabled() {
86 WriteFileRule(ctx, p.outputFilePath, "# no build.prop if kati is disabled")
Inseob Kim88b109e2024-07-31 02:00:41 +000087 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
Inseob Kim2da72af2024-06-18 11:09:12 +090088 return
89 }
90
91 partition := p.PartitionTag(ctx.DeviceConfig())
Inseob Kimacf91742024-08-05 12:51:05 +090092 if partition != "system" && partition != "system_ext" {
93 ctx.PropertyErrorf("partition", "unsupported partition %q: only \"system\" and \"system_ext\" are supported", partition)
Inseob Kim2da72af2024-06-18 11:09:12 +090094 return
95 }
96
97 rule := NewRuleBuilder(pctx, ctx)
98
99 config := ctx.Config()
100
101 cmd := rule.Command().BuiltTool("gen_build_prop")
102
103 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
104 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
105 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
106 // on every incremental build.
107 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
108 // Export build thumbprint only if the product has specified at least one oem fingerprint property
109 // b/17888863
110 if shouldAddBuildThumbprint(config) {
111 // In the previous make implementation, a dependency was not added on the thumbprint file
112 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
113 }
114 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
115 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
116 // build.
117 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
118 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
119 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
120 cmd.FlagWithArg("--partition=", partition)
Inseob Kimd8538e52024-07-31 02:00:41 +0000121 cmd.FlagForEachInput("--prop-files=", ctx.Config().SystemPropFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900122 cmd.FlagWithOutput("--out=", p.outputFilePath)
123
124 postProcessCmd := rule.Command().BuiltTool("post_process_props")
125 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
126 postProcessCmd.Flag("--allow-dup")
127 }
128 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Inseob Kim6bd92d52024-07-31 02:01:03 +0000129 if ctx.Config().EnableUffdGc() == "default" {
130 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
131 } else {
132 // still need to pass an empty string to kernel-version-file-for-uffd-gc
133 postProcessCmd.FlagWithArg("--kernel-version-file-for-uffd-gc ", `""`)
134 }
Inseob Kim2da72af2024-06-18 11:09:12 +0900135 postProcessCmd.Text(p.outputFilePath.String())
136 postProcessCmd.Flags(p.properties.Block_list)
137
138 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
139
140 rule.Build(ctx.ModuleName(), "generating build.prop")
141
Inseob Kimacf91742024-08-05 12:51:05 +0900142 p.installPath = PathForModuleInstall(ctx, proptools.String(p.properties.Relative_install_path))
Inseob Kim2da72af2024-06-18 11:09:12 +0900143 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
144
145 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
146}
147
Inseob Kimbc4ef222024-07-31 02:00:41 +0000148func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
149 return []AndroidMkEntries{{
150 Class: "ETC",
151 OutputFile: OptionalPathForPath(p.outputFilePath),
152 ExtraEntries: []AndroidMkExtraEntriesFunc{
153 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
154 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
155 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
156 },
157 },
158 }}
159}
160
Inseob Kim2da72af2024-06-18 11:09:12 +0900161// build_prop module generates {partition}/build.prop file. At first common build properties are
162// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
163// post_process_props tool is run to check if the result build.prop is valid or not.
164func buildPropFactory() Module {
165 module := &buildPropModule{}
166 module.AddProperties(&module.properties)
167 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
168 return module
169}