blob: 14e5e2310a0046a96585ee64351d1dc77de4c9aa [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"`
40}
41
42type buildPropModule struct {
43 ModuleBase
44
45 properties buildPropProperties
46
47 outputFilePath OutputPath
48 installPath InstallPath
49}
50
51func (p *buildPropModule) stem() string {
52 return proptools.StringDefault(p.properties.Stem, "build.prop")
53}
54
Inseob Kimd8538e52024-07-31 02:00:41 +000055func (p *buildPropModule) propFiles(ctx ModuleContext) Paths {
56 partition := p.PartitionTag(ctx.DeviceConfig())
57 if partition == "system" {
58 return ctx.Config().SystemPropFiles(ctx)
59 }
60 return nil
61}
62
Inseob Kimbc4ef222024-07-31 02:00:41 +000063func shouldAddBuildThumbprint(config Config) bool {
64 knownOemProperties := []string{
65 "ro.product.brand",
66 "ro.product.name",
67 "ro.product.device",
68 }
69
70 for _, knownProp := range knownOemProperties {
71 if InList(knownProp, config.OemProperties()) {
72 return true
73 }
74 }
75 return false
76}
77
Inseob Kim2da72af2024-06-18 11:09:12 +090078func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
79 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
80 if !ctx.Config().KatiEnabled() {
81 WriteFileRule(ctx, p.outputFilePath, "# no build.prop if kati is disabled")
Inseob Kim88b109e2024-07-31 02:00:41 +000082 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
Inseob Kim2da72af2024-06-18 11:09:12 +090083 return
84 }
85
86 partition := p.PartitionTag(ctx.DeviceConfig())
87 if partition != "system" {
88 ctx.PropertyErrorf("partition", "unsupported partition %q: only \"system\" is supported", partition)
89 return
90 }
91
92 rule := NewRuleBuilder(pctx, ctx)
93
94 config := ctx.Config()
95
96 cmd := rule.Command().BuiltTool("gen_build_prop")
97
98 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
99 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
100 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
101 // on every incremental build.
102 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
103 // Export build thumbprint only if the product has specified at least one oem fingerprint property
104 // b/17888863
105 if shouldAddBuildThumbprint(config) {
106 // In the previous make implementation, a dependency was not added on the thumbprint file
107 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
108 }
109 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
110 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
111 // build.
112 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
113 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
114 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
115 cmd.FlagWithArg("--partition=", partition)
Inseob Kimd8538e52024-07-31 02:00:41 +0000116 cmd.FlagForEachInput("--prop-files=", ctx.Config().SystemPropFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900117 cmd.FlagWithOutput("--out=", p.outputFilePath)
118
119 postProcessCmd := rule.Command().BuiltTool("post_process_props")
120 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
121 postProcessCmd.Flag("--allow-dup")
122 }
123 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Inseob Kim6bd92d52024-07-31 02:01:03 +0000124 if ctx.Config().EnableUffdGc() == "default" {
125 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
126 } else {
127 // still need to pass an empty string to kernel-version-file-for-uffd-gc
128 postProcessCmd.FlagWithArg("--kernel-version-file-for-uffd-gc ", `""`)
129 }
Inseob Kim2da72af2024-06-18 11:09:12 +0900130 postProcessCmd.Text(p.outputFilePath.String())
131 postProcessCmd.Flags(p.properties.Block_list)
132
133 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
134
135 rule.Build(ctx.ModuleName(), "generating build.prop")
136
137 p.installPath = PathForModuleInstall(ctx)
138 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
139
140 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
141}
142
Inseob Kimbc4ef222024-07-31 02:00:41 +0000143func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
144 return []AndroidMkEntries{{
145 Class: "ETC",
146 OutputFile: OptionalPathForPath(p.outputFilePath),
147 ExtraEntries: []AndroidMkExtraEntriesFunc{
148 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
149 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
150 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
151 },
152 },
153 }}
154}
155
Inseob Kim2da72af2024-06-18 11:09:12 +0900156// build_prop module generates {partition}/build.prop file. At first common build properties are
157// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
158// post_process_props tool is run to check if the result build.prop is valid or not.
159func buildPropFactory() Module {
160 module := &buildPropModule{}
161 module.AddProperties(&module.properties)
162 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
163 return module
164}