blob: d3ccecb665726136488e0dd1a627862bef1b586a [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 Kim2da72af2024-06-18 11:09:12 +090063func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
64 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
65 if !ctx.Config().KatiEnabled() {
66 WriteFileRule(ctx, p.outputFilePath, "# no build.prop if kati is disabled")
Inseob Kim88b109e2024-07-31 02:00:41 +000067 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
Inseob Kim2da72af2024-06-18 11:09:12 +090068 return
69 }
70
71 partition := p.PartitionTag(ctx.DeviceConfig())
72 if partition != "system" {
73 ctx.PropertyErrorf("partition", "unsupported partition %q: only \"system\" is supported", partition)
74 return
75 }
76
77 rule := NewRuleBuilder(pctx, ctx)
78
79 config := ctx.Config()
80
81 cmd := rule.Command().BuiltTool("gen_build_prop")
82
83 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
84 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
85 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
86 // on every incremental build.
87 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
88 // Export build thumbprint only if the product has specified at least one oem fingerprint property
89 // b/17888863
90 if shouldAddBuildThumbprint(config) {
91 // In the previous make implementation, a dependency was not added on the thumbprint file
92 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
93 }
94 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
95 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
96 // build.
97 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
98 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
99 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
100 cmd.FlagWithArg("--partition=", partition)
Inseob Kimd8538e52024-07-31 02:00:41 +0000101 cmd.FlagForEachInput("--prop-files=", ctx.Config().SystemPropFiles(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +0900102 cmd.FlagWithOutput("--out=", p.outputFilePath)
103
104 postProcessCmd := rule.Command().BuiltTool("post_process_props")
105 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
106 postProcessCmd.Flag("--allow-dup")
107 }
108 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Liana Kazanova29fed1e2024-07-30 17:58:19 +0000109 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
Inseob Kim2da72af2024-06-18 11:09:12 +0900110 postProcessCmd.Text(p.outputFilePath.String())
111 postProcessCmd.Flags(p.properties.Block_list)
112
113 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
114
115 rule.Build(ctx.ModuleName(), "generating build.prop")
116
117 p.installPath = PathForModuleInstall(ctx)
118 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
119
120 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
121}
122
Inseob Kim2da72af2024-06-18 11:09:12 +0900123// build_prop module generates {partition}/build.prop file. At first common build properties are
124// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
125// post_process_props tool is run to check if the result build.prop is valid or not.
126func buildPropFactory() Module {
127 module := &buildPropModule{}
128 module.AddProperties(&module.properties)
129 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
130 return module
131}