blob: 083f3efcb5a49cddd25c276b89a815d87727a491 [file] [log] [blame]
Inseob Kim4f1f3d92022-04-25 18:23:58 +09001// Copyright 2022 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 "fmt"
19 "strings"
20
21 "github.com/google/blueprint/proptools"
22)
23
24func init() {
25 ctx := InitRegistrationContext
Cole Fausta700d7f2024-06-06 14:49:23 -070026 ctx.RegisterModuleType("buildinfo_prop", buildinfoPropFactory)
Inseob Kim4f1f3d92022-04-25 18:23:58 +090027}
28
29type buildinfoPropProperties struct {
30 // Whether this module is directly installable to one of the partitions. Default: true.
31 Installable *bool
32}
33
34type buildinfoPropModule struct {
Cole Fausta700d7f2024-06-06 14:49:23 -070035 ModuleBase
Inseob Kim4f1f3d92022-04-25 18:23:58 +090036
37 properties buildinfoPropProperties
38
39 outputFilePath OutputPath
40 installPath InstallPath
41}
42
43var _ OutputFileProducer = (*buildinfoPropModule)(nil)
44
45func (p *buildinfoPropModule) installable() bool {
46 return proptools.BoolDefault(p.properties.Installable, true)
47}
48
49// OutputFileProducer
50func (p *buildinfoPropModule) OutputFiles(tag string) (Paths, error) {
51 if tag != "" {
52 return nil, fmt.Errorf("unsupported tag %q", tag)
53 }
54 return Paths{p.outputFilePath}, nil
55}
56
Inseob Kim8fa54da2024-03-19 16:48:59 +090057func getBuildVariant(config Config) string {
58 if config.Eng() {
59 return "eng"
60 } else if config.Debuggable() {
61 return "userdebug"
62 } else {
63 return "user"
64 }
65}
66
67func getBuildFlavor(config Config) string {
68 buildFlavor := config.DeviceProduct() + "-" + getBuildVariant(config)
69 if InList("address", config.SanitizeDevice()) && !strings.Contains(buildFlavor, "_asan") {
70 buildFlavor += "_asan"
71 }
72 return buildFlavor
73}
74
75func shouldAddBuildThumbprint(config Config) bool {
76 knownOemProperties := []string{
77 "ro.product.brand",
78 "ro.product.name",
79 "ro.product.device",
80 }
81
82 for _, knownProp := range knownOemProperties {
83 if InList(knownProp, config.OemProperties()) {
84 return true
85 }
86 }
87 return false
88}
89
Inseob Kim4f1f3d92022-04-25 18:23:58 +090090func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Cole Fausta700d7f2024-06-06 14:49:23 -070091 if ctx.ModuleName() != "buildinfo.prop" || ctx.ModuleDir() != "build/soong" {
92 ctx.ModuleErrorf("There can only be one buildinfo_prop module in build/soong")
93 return
94 }
Inseob Kim4f1f3d92022-04-25 18:23:58 +090095 p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath
96 if !ctx.Config().KatiEnabled() {
97 WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled")
98 return
99 }
100
Inseob Kim8fa54da2024-03-19 16:48:59 +0900101 rule := NewRuleBuilder(pctx, ctx)
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900102
103 config := ctx.Config()
Inseob Kim8fa54da2024-03-19 16:48:59 +0900104 buildVariant := getBuildVariant(config)
105 buildFlavor := getBuildFlavor(config)
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900106
Inseob Kim8fa54da2024-03-19 16:48:59 +0900107 cmd := rule.Command().BuiltTool("buildinfo")
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900108
Inseob Kim8fa54da2024-03-19 16:48:59 +0900109 if config.BoardUseVbmetaDigestInFingerprint() {
110 cmd.Flag("--use-vbmeta-digest-in-fingerprint")
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900111 }
112
Inseob Kim8fa54da2024-03-19 16:48:59 +0900113 cmd.FlagWithArg("--build-flavor=", buildFlavor)
114 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
115 cmd.FlagWithArg("--build-id=", config.BuildId())
116 cmd.FlagWithArg("--build-keys=", config.BuildKeys())
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900117
Cole Faust89b4d182024-06-06 14:39:32 -0700118 // Note: depending on BuildNumberFile will cause the build.prop file to be rebuilt
119 // every build, but that's intentional.
120 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
Inseob Kim8fa54da2024-03-19 16:48:59 +0900121 if shouldAddBuildThumbprint(config) {
Cole Faust89b4d182024-06-06 14:39:32 -0700122 // In the previous make implementation, a dependency was not added on the thumbprint file
Inseob Kim8fa54da2024-03-19 16:48:59 +0900123 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
124 }
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900125
Inseob Kim8fa54da2024-03-19 16:48:59 +0900126 cmd.FlagWithArg("--build-type=", config.BuildType())
127 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
128 cmd.FlagWithArg("--build-variant=", buildVariant)
129 cmd.FlagForEachArg("--cpu-abis=", config.DeviceAbi())
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900130
Cole Faust89b4d182024-06-06 14:39:32 -0700131 // Technically we should also have a dependency on BUILD_DATETIME_FILE,
132 // but it can be either an absolute or relative path, which is hard to turn into
133 // a Path object. So just rely on the BuildNumberFile always changing to cause
134 // us to rebuild.
Inseob Kim8fa54da2024-03-19 16:48:59 +0900135 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900136
Inseob Kim8fa54da2024-03-19 16:48:59 +0900137 if len(config.ProductLocales()) > 0 {
138 cmd.FlagWithArg("--default-locale=", config.ProductLocales()[0])
139 }
140
141 cmd.FlagForEachArg("--default-wifi-channels=", config.ProductDefaultWifiChannels())
142 cmd.FlagWithArg("--device=", config.DeviceName())
143 if config.DisplayBuildNumber() {
144 cmd.Flag("--display-build-number")
145 }
146
147 cmd.FlagWithArg("--platform-base-os=", config.PlatformBaseOS())
148 cmd.FlagWithArg("--platform-display-version=", config.PlatformDisplayVersionName())
149 cmd.FlagWithArg("--platform-min-supported-target-sdk-version=", config.PlatformMinSupportedTargetSdkVersion())
150 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
151 cmd.FlagWithArg("--platform-preview-sdk-version=", config.PlatformPreviewSdkVersion())
152 cmd.FlagWithArg("--platform-sdk-version=", config.PlatformSdkVersion().String())
153 cmd.FlagWithArg("--platform-security-patch=", config.PlatformSecurityPatch())
154 cmd.FlagWithArg("--platform-version=", config.PlatformVersionName())
155 cmd.FlagWithArg("--platform-version-codename=", config.PlatformSdkCodename())
156 cmd.FlagForEachArg("--platform-version-all-codenames=", config.PlatformVersionActiveCodenames())
157 cmd.FlagWithArg("--platform-version-known-codenames=", config.PlatformVersionKnownCodenames())
158 cmd.FlagWithArg("--platform-version-last-stable=", config.PlatformVersionLastStable())
159 cmd.FlagWithArg("--product=", config.DeviceProduct())
160
161 cmd.FlagWithOutput("--out=", p.outputFilePath)
162
163 rule.Build(ctx.ModuleName(), "generating buildinfo props")
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900164
165 if !p.installable() {
166 p.SkipInstall()
167 }
168
169 p.installPath = PathForModuleInstall(ctx)
170 ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath)
171}
172
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900173func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries {
Cole Fausta700d7f2024-06-06 14:49:23 -0700174 return []AndroidMkEntries{{
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900175 Class: "ETC",
176 OutputFile: OptionalPathForPath(p.outputFilePath),
177 ExtraEntries: []AndroidMkExtraEntriesFunc{
178 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
179 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
180 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
181 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
182 },
183 },
184 }}
185}
186
187// buildinfo_prop module generates a build.prop file, which contains a set of common
188// system/build.prop properties, such as ro.build.version.*. Not all properties are implemented;
189// currently this module is only for microdroid.
Cole Fausta700d7f2024-06-06 14:49:23 -0700190func buildinfoPropFactory() Module {
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900191 module := &buildinfoPropModule{}
192 module.AddProperties(&module.properties)
193 InitAndroidModule(module)
194 return module
195}