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 ( |
| 18 | "fmt" |
| 19 | "strings" |
| 20 | |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | ctx := InitRegistrationContext |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 26 | ctx.RegisterParallelSingletonModuleType("buildinfo_prop", buildinfoPropFactory) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | type buildinfoPropProperties struct { |
| 30 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 31 | Installable *bool |
| 32 | } |
| 33 | |
| 34 | type buildinfoPropModule struct { |
| 35 | SingletonModuleBase |
| 36 | |
| 37 | properties buildinfoPropProperties |
| 38 | |
| 39 | outputFilePath OutputPath |
| 40 | installPath InstallPath |
| 41 | } |
| 42 | |
| 43 | var _ OutputFileProducer = (*buildinfoPropModule)(nil) |
| 44 | |
| 45 | func (p *buildinfoPropModule) installable() bool { |
| 46 | return proptools.BoolDefault(p.properties.Installable, true) |
| 47 | } |
| 48 | |
| 49 | // OutputFileProducer |
| 50 | func (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 Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 57 | func 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 | |
| 67 | func 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 | |
| 75 | func 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 Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 90 | func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 91 | p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath |
| 92 | if !ctx.Config().KatiEnabled() { |
| 93 | WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled") |
| 94 | return |
| 95 | } |
| 96 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 97 | rule := NewRuleBuilder(pctx, ctx) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 98 | |
| 99 | config := ctx.Config() |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 100 | buildVariant := getBuildVariant(config) |
| 101 | buildFlavor := getBuildFlavor(config) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 102 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 103 | cmd := rule.Command().BuiltTool("buildinfo") |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 104 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 105 | if config.BoardUseVbmetaDigestInFingerprint() { |
| 106 | cmd.Flag("--use-vbmeta-digest-in-fingerprint") |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 107 | } |
| 108 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 109 | cmd.FlagWithArg("--build-flavor=", buildFlavor) |
| 110 | cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx)) |
| 111 | cmd.FlagWithArg("--build-id=", config.BuildId()) |
| 112 | cmd.FlagWithArg("--build-keys=", config.BuildKeys()) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 113 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 114 | // shouldn't depend on BuildNumberFile and BuildThumbprintFile to prevent from rebuilding |
| 115 | // on every incremental build. |
| 116 | cmd.FlagWithArg("--build-number-file=", config.BuildNumberFile(ctx).String()) |
| 117 | if shouldAddBuildThumbprint(config) { |
| 118 | cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String()) |
| 119 | } |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 120 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 121 | cmd.FlagWithArg("--build-type=", config.BuildType()) |
| 122 | cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME")) |
| 123 | cmd.FlagWithArg("--build-variant=", buildVariant) |
| 124 | cmd.FlagForEachArg("--cpu-abis=", config.DeviceAbi()) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 125 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 126 | // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental |
| 127 | // build. |
| 128 | cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE")) |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 129 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 130 | if len(config.ProductLocales()) > 0 { |
| 131 | cmd.FlagWithArg("--default-locale=", config.ProductLocales()[0]) |
| 132 | } |
| 133 | |
| 134 | cmd.FlagForEachArg("--default-wifi-channels=", config.ProductDefaultWifiChannels()) |
| 135 | cmd.FlagWithArg("--device=", config.DeviceName()) |
| 136 | if config.DisplayBuildNumber() { |
| 137 | cmd.Flag("--display-build-number") |
| 138 | } |
| 139 | |
| 140 | cmd.FlagWithArg("--platform-base-os=", config.PlatformBaseOS()) |
| 141 | cmd.FlagWithArg("--platform-display-version=", config.PlatformDisplayVersionName()) |
| 142 | cmd.FlagWithArg("--platform-min-supported-target-sdk-version=", config.PlatformMinSupportedTargetSdkVersion()) |
| 143 | cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx)) |
| 144 | cmd.FlagWithArg("--platform-preview-sdk-version=", config.PlatformPreviewSdkVersion()) |
| 145 | cmd.FlagWithArg("--platform-sdk-version=", config.PlatformSdkVersion().String()) |
| 146 | cmd.FlagWithArg("--platform-security-patch=", config.PlatformSecurityPatch()) |
| 147 | cmd.FlagWithArg("--platform-version=", config.PlatformVersionName()) |
| 148 | cmd.FlagWithArg("--platform-version-codename=", config.PlatformSdkCodename()) |
| 149 | cmd.FlagForEachArg("--platform-version-all-codenames=", config.PlatformVersionActiveCodenames()) |
| 150 | cmd.FlagWithArg("--platform-version-known-codenames=", config.PlatformVersionKnownCodenames()) |
| 151 | cmd.FlagWithArg("--platform-version-last-stable=", config.PlatformVersionLastStable()) |
| 152 | cmd.FlagWithArg("--product=", config.DeviceProduct()) |
| 153 | |
| 154 | cmd.FlagWithOutput("--out=", p.outputFilePath) |
| 155 | |
| 156 | rule.Build(ctx.ModuleName(), "generating buildinfo props") |
Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 157 | |
| 158 | if !p.installable() { |
| 159 | p.SkipInstall() |
| 160 | } |
| 161 | |
| 162 | p.installPath = PathForModuleInstall(ctx) |
| 163 | ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath) |
| 164 | } |
| 165 | |
| 166 | func (f *buildinfoPropModule) GenerateSingletonBuildActions(ctx SingletonContext) { |
| 167 | // does nothing; buildinfo_prop is a singeton because two buildinfo modules don't make sense. |
| 168 | } |
| 169 | |
| 170 | func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries { |
| 171 | return []AndroidMkEntries{AndroidMkEntries{ |
| 172 | Class: "ETC", |
| 173 | OutputFile: OptionalPathForPath(p.outputFilePath), |
| 174 | ExtraEntries: []AndroidMkExtraEntriesFunc{ |
| 175 | func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) { |
| 176 | entries.SetString("LOCAL_MODULE_PATH", p.installPath.String()) |
| 177 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) |
| 178 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 179 | }, |
| 180 | }, |
| 181 | }} |
| 182 | } |
| 183 | |
| 184 | // buildinfo_prop module generates a build.prop file, which contains a set of common |
| 185 | // system/build.prop properties, such as ro.build.version.*. Not all properties are implemented; |
| 186 | // currently this module is only for microdroid. |
| 187 | func buildinfoPropFactory() SingletonModule { |
| 188 | module := &buildinfoPropModule{} |
| 189 | module.AddProperties(&module.properties) |
| 190 | InitAndroidModule(module) |
| 191 | return module |
| 192 | } |