blob: c226431a7e207e4a466aea87af6594081f4a6d7a [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 Kimbcc00552024-07-19 14:57:22 +090055func (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 Kim361baad2024-07-19 18:15:50 +090063func 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")
82 return
83 }
84
85 partition := p.PartitionTag(ctx.DeviceConfig())
86 if partition != "system" {
87 ctx.PropertyErrorf("partition", "unsupported partition %q: only \"system\" is supported", partition)
88 return
89 }
90
91 rule := NewRuleBuilder(pctx, ctx)
92
93 config := ctx.Config()
94
95 cmd := rule.Command().BuiltTool("gen_build_prop")
96
97 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
98 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
99 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
100 // on every incremental build.
101 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
102 // Export build thumbprint only if the product has specified at least one oem fingerprint property
103 // b/17888863
104 if shouldAddBuildThumbprint(config) {
105 // In the previous make implementation, a dependency was not added on the thumbprint file
106 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
107 }
108 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
109 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
110 // build.
111 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
112 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
113 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
114 cmd.FlagWithArg("--partition=", partition)
Inseob Kimbcc00552024-07-19 14:57:22 +0900115 cmd.FlagForEachInput("--prop-files=", ctx.Config().SystemPropFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900116 cmd.FlagWithOutput("--out=", p.outputFilePath)
117
118 postProcessCmd := rule.Command().BuiltTool("post_process_props")
119 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
120 postProcessCmd.Flag("--allow-dup")
121 }
122 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
123 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
124 postProcessCmd.Text(p.outputFilePath.String())
125 postProcessCmd.Flags(p.properties.Block_list)
126
127 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
128
129 rule.Build(ctx.ModuleName(), "generating build.prop")
130
131 p.installPath = PathForModuleInstall(ctx)
132 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
133
134 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
135}
136
Inseob Kim361baad2024-07-19 18:15:50 +0900137func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
138 return []AndroidMkEntries{{
139 Class: "ETC",
140 OutputFile: OptionalPathForPath(p.outputFilePath),
141 ExtraEntries: []AndroidMkExtraEntriesFunc{
142 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
143 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
144 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
145 },
146 },
147 }}
148}
149
Inseob Kim2da72af2024-06-18 11:09:12 +0900150// build_prop module generates {partition}/build.prop file. At first common build properties are
151// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
152// post_process_props tool is run to check if the result build.prop is valid or not.
153func buildPropFactory() Module {
154 module := &buildPropModule{}
155 module.AddProperties(&module.properties)
156 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
157 return module
158}