Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 18 | "github.com/google/blueprint/proptools" |
| 19 | ) |
| 20 | |
| 21 | func init() { |
| 22 | ctx := InitRegistrationContext |
Cole Faust | a700d7f | 2024-06-06 14:49:23 -0700 | [diff] [blame] | 23 | ctx.RegisterModuleType("buildinfo_prop", buildinfoPropFactory) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | type buildinfoPropProperties struct { |
| 27 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 28 | Installable *bool |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 29 | |
| 30 | Product_config *string `android:"path"` |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | type buildinfoPropModule struct { |
Cole Faust | a700d7f | 2024-06-06 14:49:23 -0700 | [diff] [blame] | 34 | ModuleBase |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 35 | |
| 36 | properties buildinfoPropProperties |
| 37 | |
| 38 | outputFilePath OutputPath |
| 39 | installPath InstallPath |
| 40 | } |
| 41 | |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 42 | func (p *buildinfoPropModule) installable() bool { |
| 43 | return proptools.BoolDefault(p.properties.Installable, true) |
| 44 | } |
| 45 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 46 | func shouldAddBuildThumbprint(config Config) bool { |
| 47 | knownOemProperties := []string{ |
| 48 | "ro.product.brand", |
| 49 | "ro.product.name", |
| 50 | "ro.product.device", |
| 51 | } |
| 52 | |
| 53 | for _, knownProp := range knownOemProperties { |
| 54 | if InList(knownProp, config.OemProperties()) { |
| 55 | return true |
| 56 | } |
| 57 | } |
| 58 | return false |
| 59 | } |
| 60 | |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 61 | func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Cole Faust | a700d7f | 2024-06-06 14:49:23 -0700 | [diff] [blame] | 62 | if ctx.ModuleName() != "buildinfo.prop" || ctx.ModuleDir() != "build/soong" { |
| 63 | ctx.ModuleErrorf("There can only be one buildinfo_prop module in build/soong") |
| 64 | return |
| 65 | } |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 66 | p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath |
| 67 | if !ctx.Config().KatiEnabled() { |
| 68 | WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled") |
| 69 | return |
| 70 | } |
| 71 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 72 | rule := NewRuleBuilder(pctx, ctx) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 73 | |
| 74 | config := ctx.Config() |
| 75 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 76 | cmd := rule.Command().BuiltTool("buildinfo") |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 77 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 78 | cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx)) |
Cole Faust | 89b4d18 | 2024-06-06 14:39:32 -0700 | [diff] [blame] | 79 | // Note: depending on BuildNumberFile will cause the build.prop file to be rebuilt |
| 80 | // every build, but that's intentional. |
| 81 | cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx)) |
Inseob Kim | 2da72af | 2024-06-18 11:09:12 +0900 | [diff] [blame] | 82 | // Export build thumbprint only if the product has specified at least one oem fingerprint property |
| 83 | // b/17888863 |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 84 | if shouldAddBuildThumbprint(config) { |
Cole Faust | 89b4d18 | 2024-06-06 14:39:32 -0700 | [diff] [blame] | 85 | // In the previous make implementation, a dependency was not added on the thumbprint file |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 86 | cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String()) |
| 87 | } |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 88 | cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME")) |
Cole Faust | 89b4d18 | 2024-06-06 14:39:32 -0700 | [diff] [blame] | 89 | // Technically we should also have a dependency on BUILD_DATETIME_FILE, |
| 90 | // but it can be either an absolute or relative path, which is hard to turn into |
| 91 | // a Path object. So just rely on the BuildNumberFile always changing to cause |
| 92 | // us to rebuild. |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 93 | cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE")) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 94 | cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx)) |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 95 | cmd.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config))) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 96 | cmd.FlagWithOutput("--out=", p.outputFilePath) |
| 97 | |
| 98 | rule.Build(ctx.ModuleName(), "generating buildinfo props") |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 99 | |
| 100 | if !p.installable() { |
| 101 | p.SkipInstall() |
| 102 | } |
| 103 | |
| 104 | p.installPath = PathForModuleInstall(ctx) |
| 105 | ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath) |
mrziwang | 89e4ff6 | 2024-06-27 12:53:08 -0700 | [diff] [blame^] | 106 | |
| 107 | ctx.SetOutputFiles(Paths{p.outputFilePath}, "") |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 108 | } |
| 109 | |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 110 | func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries { |
Cole Faust | a700d7f | 2024-06-06 14:49:23 -0700 | [diff] [blame] | 111 | return []AndroidMkEntries{{ |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 112 | Class: "ETC", |
| 113 | OutputFile: OptionalPathForPath(p.outputFilePath), |
| 114 | ExtraEntries: []AndroidMkExtraEntriesFunc{ |
| 115 | func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) { |
| 116 | entries.SetString("LOCAL_MODULE_PATH", p.installPath.String()) |
| 117 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) |
| 118 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 119 | }, |
| 120 | }, |
| 121 | }} |
| 122 | } |
| 123 | |
| 124 | // buildinfo_prop module generates a build.prop file, which contains a set of common |
| 125 | // system/build.prop properties, such as ro.build.version.*. Not all properties are implemented; |
| 126 | // currently this module is only for microdroid. |
Cole Faust | a700d7f | 2024-06-06 14:49:23 -0700 | [diff] [blame] | 127 | func buildinfoPropFactory() Module { |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 128 | module := &buildinfoPropModule{} |
| 129 | module.AddProperties(&module.properties) |
| 130 | InitAndroidModule(module) |
| 131 | return module |
| 132 | } |