blob: 45c17c35b4181f67237e0f05cca10cb5636b9783 [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
Liana Kazanova530c32a2024-07-30 19:14:30 +000034 // Path to the input prop files. The contents of the files are directly
35 // emitted to the output
36 Prop_files []string `android:"path"`
37
Inseob Kim2da72af2024-06-18 11:09:12 +090038 // Files to be appended at the end of build.prop. These files are appended after
39 // post_process_props without any further checking.
40 Footer_files []string `android:"path"`
41
42 // Path to a JSON file containing product configs.
43 Product_config *string `android:"path"`
44}
45
46type buildPropModule struct {
47 ModuleBase
48
49 properties buildPropProperties
50
51 outputFilePath OutputPath
52 installPath InstallPath
53}
54
55func (p *buildPropModule) stem() string {
56 return proptools.StringDefault(p.properties.Stem, "build.prop")
57}
58
59func (p *buildPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
60 p.outputFilePath = PathForModuleOut(ctx, "build.prop").OutputPath
61 if !ctx.Config().KatiEnabled() {
62 WriteFileRule(ctx, p.outputFilePath, "# no build.prop if kati is disabled")
63 return
64 }
65
66 partition := p.PartitionTag(ctx.DeviceConfig())
67 if partition != "system" {
68 ctx.PropertyErrorf("partition", "unsupported partition %q: only \"system\" is supported", partition)
69 return
70 }
71
72 rule := NewRuleBuilder(pctx, ctx)
73
74 config := ctx.Config()
75
76 cmd := rule.Command().BuiltTool("gen_build_prop")
77
78 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
79 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
80 // shouldn't depend on BuildFingerprintFile and BuildThumbprintFile to prevent from rebuilding
81 // on every incremental build.
82 cmd.FlagWithArg("--build-fingerprint-file=", config.BuildFingerprintFile(ctx).String())
83 // Export build thumbprint only if the product has specified at least one oem fingerprint property
84 // b/17888863
85 if shouldAddBuildThumbprint(config) {
86 // In the previous make implementation, a dependency was not added on the thumbprint file
87 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
88 }
89 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
90 // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
91 // build.
92 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
93 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
94 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
95 cmd.FlagWithArg("--partition=", partition)
Inseob Kim2da72af2024-06-18 11:09:12 +090096 cmd.FlagWithOutput("--out=", p.outputFilePath)
97
98 postProcessCmd := rule.Command().BuiltTool("post_process_props")
99 if ctx.DeviceConfig().BuildBrokenDupSysprop() {
100 postProcessCmd.Flag("--allow-dup")
101 }
102 postProcessCmd.FlagWithArg("--sdk-version ", config.PlatformSdkVersion().String())
Liana Kazanova29fed1e2024-07-30 17:58:19 +0000103 postProcessCmd.FlagWithInput("--kernel-version-file-for-uffd-gc ", PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt"))
Inseob Kim2da72af2024-06-18 11:09:12 +0900104 postProcessCmd.Text(p.outputFilePath.String())
105 postProcessCmd.Flags(p.properties.Block_list)
106
107 rule.Command().Text("echo").Text(proptools.NinjaAndShellEscape("# end of file")).FlagWithArg(">> ", p.outputFilePath.String())
108
109 rule.Build(ctx.ModuleName(), "generating build.prop")
110
111 p.installPath = PathForModuleInstall(ctx)
112 ctx.InstallFile(p.installPath, p.stem(), p.outputFilePath)
113
114 ctx.SetOutputFiles(Paths{p.outputFilePath}, "")
115}
116
Inseob Kim2da72af2024-06-18 11:09:12 +0900117// build_prop module generates {partition}/build.prop file. At first common build properties are
118// printed based on Soong config variables. And then prop_files are printed as-is. Finally,
119// post_process_props tool is run to check if the result build.prop is valid or not.
120func buildPropFactory() Module {
121 module := &buildPropModule{}
122 module.AddProperties(&module.properties)
123 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
124 return module
125}