blob: defbff0b0644c1e815c874695d3ca71e4f3db399 [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 (
Zi Wang9b215962024-06-27 21:51:33 +000018 "fmt"
19
Inseob Kim4f1f3d92022-04-25 18:23:58 +090020 "github.com/google/blueprint/proptools"
21)
22
23func init() {
24 ctx := InitRegistrationContext
Cole Fausta700d7f2024-06-06 14:49:23 -070025 ctx.RegisterModuleType("buildinfo_prop", buildinfoPropFactory)
Inseob Kim4f1f3d92022-04-25 18:23:58 +090026}
27
28type buildinfoPropProperties struct {
29 // Whether this module is directly installable to one of the partitions. Default: true.
30 Installable *bool
Inseob Kim1d914822024-06-11 11:00:30 +090031
32 Product_config *string `android:"path"`
Inseob Kim4f1f3d92022-04-25 18:23:58 +090033}
34
35type buildinfoPropModule struct {
Cole Fausta700d7f2024-06-06 14:49:23 -070036 ModuleBase
Inseob Kim4f1f3d92022-04-25 18:23:58 +090037
38 properties buildinfoPropProperties
39
40 outputFilePath OutputPath
41 installPath InstallPath
42}
43
Zi Wang9b215962024-06-27 21:51:33 +000044var _ OutputFileProducer = (*buildinfoPropModule)(nil)
45
Inseob Kim4f1f3d92022-04-25 18:23:58 +090046func (p *buildinfoPropModule) installable() bool {
47 return proptools.BoolDefault(p.properties.Installable, true)
48}
49
Zi Wang9b215962024-06-27 21:51:33 +000050// OutputFileProducer
51func (p *buildinfoPropModule) OutputFiles(tag string) (Paths, error) {
52 if tag != "" {
53 return nil, fmt.Errorf("unsupported tag %q", tag)
54 }
55 return Paths{p.outputFilePath}, nil
56}
57
Inseob Kim8fa54da2024-03-19 16:48:59 +090058func shouldAddBuildThumbprint(config Config) bool {
59 knownOemProperties := []string{
60 "ro.product.brand",
61 "ro.product.name",
62 "ro.product.device",
63 }
64
65 for _, knownProp := range knownOemProperties {
66 if InList(knownProp, config.OemProperties()) {
67 return true
68 }
69 }
70 return false
71}
72
Inseob Kim4f1f3d92022-04-25 18:23:58 +090073func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
Cole Fausta700d7f2024-06-06 14:49:23 -070074 if ctx.ModuleName() != "buildinfo.prop" || ctx.ModuleDir() != "build/soong" {
75 ctx.ModuleErrorf("There can only be one buildinfo_prop module in build/soong")
76 return
77 }
Inseob Kim4f1f3d92022-04-25 18:23:58 +090078 p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath
79 if !ctx.Config().KatiEnabled() {
80 WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled")
81 return
82 }
83
Inseob Kim8fa54da2024-03-19 16:48:59 +090084 rule := NewRuleBuilder(pctx, ctx)
Inseob Kim4f1f3d92022-04-25 18:23:58 +090085
86 config := ctx.Config()
87
Inseob Kim8fa54da2024-03-19 16:48:59 +090088 cmd := rule.Command().BuiltTool("buildinfo")
Inseob Kim4f1f3d92022-04-25 18:23:58 +090089
Inseob Kim8fa54da2024-03-19 16:48:59 +090090 cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
Cole Faust89b4d182024-06-06 14:39:32 -070091 // Note: depending on BuildNumberFile will cause the build.prop file to be rebuilt
92 // every build, but that's intentional.
93 cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
Inseob Kim2da72af2024-06-18 11:09:12 +090094 // Export build thumbprint only if the product has specified at least one oem fingerprint property
95 // b/17888863
Inseob Kim8fa54da2024-03-19 16:48:59 +090096 if shouldAddBuildThumbprint(config) {
Cole Faust89b4d182024-06-06 14:39:32 -070097 // In the previous make implementation, a dependency was not added on the thumbprint file
Inseob Kim8fa54da2024-03-19 16:48:59 +090098 cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
99 }
Inseob Kim8fa54da2024-03-19 16:48:59 +0900100 cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
Cole Faust89b4d182024-06-06 14:39:32 -0700101 // Technically we should also have a dependency on BUILD_DATETIME_FILE,
102 // but it can be either an absolute or relative path, which is hard to turn into
103 // a Path object. So just rely on the BuildNumberFile always changing to cause
104 // us to rebuild.
Inseob Kim8fa54da2024-03-19 16:48:59 +0900105 cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
Inseob Kim8fa54da2024-03-19 16:48:59 +0900106 cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
Inseob Kim1d914822024-06-11 11:00:30 +0900107 cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
Inseob Kim8fa54da2024-03-19 16:48:59 +0900108 cmd.FlagWithOutput("--out=", p.outputFilePath)
109
110 rule.Build(ctx.ModuleName(), "generating buildinfo props")
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900111
112 if !p.installable() {
113 p.SkipInstall()
114 }
115
116 p.installPath = PathForModuleInstall(ctx)
117 ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath)
118}
119
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900120func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries {
Cole Fausta700d7f2024-06-06 14:49:23 -0700121 return []AndroidMkEntries{{
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900122 Class: "ETC",
123 OutputFile: OptionalPathForPath(p.outputFilePath),
124 ExtraEntries: []AndroidMkExtraEntriesFunc{
125 func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
126 entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
127 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
128 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
129 },
130 },
131 }}
132}
133
134// buildinfo_prop module generates a build.prop file, which contains a set of common
135// system/build.prop properties, such as ro.build.version.*. Not all properties are implemented;
136// currently this module is only for microdroid.
Cole Fausta700d7f2024-06-06 14:49:23 -0700137func buildinfoPropFactory() Module {
Inseob Kim4f1f3d92022-04-25 18:23:58 +0900138 module := &buildinfoPropModule{}
139 module.AddProperties(&module.properties)
140 InitAndroidModule(module)
141 return module
142}