blob: 80bbfc19d257330ae0a4dfb91166fd546f87e51b [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 Kim26756a82024-07-25 10:58:08 +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 Kim45ed4c22024-07-25 10:58:08 +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 Kimbf322252024-07-25 10:58:08 +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 Kim26756a82024-07-25 10:58:08 +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())
Liana Kazanova29fed1e2024-07-30 17:58:19 +0000124 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
Inseob Kim2da72af2024-06-18 11:09:12 +0900125 postProcessCmd.Text(p.outputFilePath.String())
126 postProcessCmd.Flags(p.properties.Block_list)
127
128 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
129
130 rule.Build(ctx.ModuleName(), "generating build.prop")
131
132 p.installPath = PathForModuleInstall(ctx)
133 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
134
135 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
136}
137
Inseob Kim45ed4c22024-07-25 10:58:08 +0000138func (p *buildPropModule) AndroidMkEntries() []AndroidMkEntries {
139 return []AndroidMkEntries{{
140 Class: "ETC",
141 OutputFile: OptionalPathForPath(p.outputFilePath),
142 ExtraEntries: []AndroidMkExtraEntriesFunc{
143 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
144 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
145 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
146 },
147 },
148 }}
149}
150
Inseob Kim2da72af2024-06-18 11:09:12 +0900151// build_prop module generates {partition}/build.prop file. At first common build properties are
152// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
153// post_process_props tool is run to check if the result build.prop is valid or not.
154func buildPropFactory() Module {
155 module := &buildPropModule{}
156 module.AddProperties(&module.properties)
157 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
158 return module
159}