| 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 |  | 
|  | 57 | func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) { | 
|  | 58 | p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath | 
|  | 59 | if !ctx.Config().KatiEnabled() { | 
|  | 60 | WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled") | 
|  | 61 | return | 
|  | 62 | } | 
|  | 63 |  | 
| Cole Faust | a734749 | 2022-12-16 10:56:24 -0800 | [diff] [blame] | 64 | lines := make([]string, 0) | 
| Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 65 |  | 
|  | 66 | writeString := func(str string) { | 
| Cole Faust | a734749 | 2022-12-16 10:56:24 -0800 | [diff] [blame] | 67 | lines = append(lines, str) | 
| Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
|  | 70 | writeString("# begin build properties") | 
|  | 71 | writeString("# autogenerated by build/soong/android/buildinfo_prop.go") | 
|  | 72 |  | 
|  | 73 | writeProp := func(key, value string) { | 
|  | 74 | if strings.Contains(key, "=") { | 
|  | 75 | panic(fmt.Errorf("wrong property key %q: key must not contain '='", key)) | 
|  | 76 | } | 
|  | 77 | writeString(key + "=" + value) | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | config := ctx.Config() | 
|  | 81 |  | 
|  | 82 | writeProp("ro.build.version.sdk", config.PlatformSdkVersion().String()) | 
|  | 83 | writeProp("ro.build.version.preview_sdk", config.PlatformPreviewSdkVersion()) | 
|  | 84 | writeProp("ro.build.version.codename", config.PlatformSdkCodename()) | 
|  | 85 | writeProp("ro.build.version.all_codenames", strings.Join(config.PlatformVersionActiveCodenames(), ",")) | 
|  | 86 | writeProp("ro.build.version.release", config.PlatformVersionLastStable()) | 
|  | 87 | writeProp("ro.build.version.release_or_codename", config.PlatformVersionName()) | 
|  | 88 | writeProp("ro.build.version.security_patch", config.PlatformSecurityPatch()) | 
|  | 89 | writeProp("ro.build.version.base_os", config.PlatformBaseOS()) | 
|  | 90 | writeProp("ro.build.version.min_supported_target_sdk", config.PlatformMinSupportedTargetSdkVersion()) | 
| Jiyong Park | 3707384 | 2022-06-21 10:13:42 +0900 | [diff] [blame] | 91 | writeProp("ro.build.version.known_codenames", config.PlatformVersionKnownCodenames()) | 
| Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 92 |  | 
|  | 93 | if config.Eng() { | 
|  | 94 | writeProp("ro.build.type", "eng") | 
|  | 95 | } else if config.Debuggable() { | 
|  | 96 | writeProp("ro.build.type", "userdebug") | 
|  | 97 | } else { | 
|  | 98 | writeProp("ro.build.type", "user") | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | // Currently, only a few properties are implemented to unblock microdroid use case. | 
|  | 102 | // TODO(b/189164487): support below properties as well and replace build/make/tools/buildinfo.sh | 
|  | 103 | /* | 
|  | 104 | if $BOARD_USE_VBMETA_DIGTEST_IN_FINGERPRINT { | 
|  | 105 | writeProp("ro.build.legacy.id", config.BuildID()) | 
|  | 106 | } else { | 
|  | 107 | writeProp("ro.build.id", config.BuildId()) | 
|  | 108 | } | 
|  | 109 | writeProp("ro.build.display.id", $BUILD_DISPLAY_ID) | 
|  | 110 | writeProp("ro.build.version.incremental", $BUILD_NUMBER) | 
|  | 111 | writeProp("ro.build.version.preview_sdk_fingerprint", $PLATFORM_PREVIEW_SDK_FINGERPRINT) | 
| Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 112 | writeProp("ro.build.version.release_or_preview_display", $PLATFORM_DISPLAY_VERSION) | 
|  | 113 | writeProp("ro.build.date", `$DATE`) | 
|  | 114 | writeProp("ro.build.date.utc", `$DATE +%s`) | 
|  | 115 | writeProp("ro.build.user", $BUILD_USERNAME) | 
|  | 116 | writeProp("ro.build.host", $BUILD_HOSTNAME) | 
|  | 117 | writeProp("ro.build.tags", $BUILD_VERSION_TAGS) | 
|  | 118 | writeProp("ro.build.flavor", $TARGET_BUILD_FLAVOR) | 
|  | 119 | // These values are deprecated, use "ro.product.cpu.abilist" | 
|  | 120 | // instead (see below). | 
|  | 121 | writeString("# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,") | 
|  | 122 | writeString("# use ro.product.cpu.abilist instead.") | 
|  | 123 | writeProp("ro.product.cpu.abi", $TARGET_CPU_ABI) | 
|  | 124 | if [ -n "$TARGET_CPU_ABI2" ] { | 
|  | 125 | writeProp("ro.product.cpu.abi2", $TARGET_CPU_ABI2) | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | if [ -n "$PRODUCT_DEFAULT_LOCALE" ] { | 
|  | 129 | writeProp("ro.product.locale", $PRODUCT_DEFAULT_LOCALE) | 
|  | 130 | } | 
|  | 131 | writeProp("ro.wifi.channels", $PRODUCT_DEFAULT_WIFI_CHANNELS) | 
|  | 132 | writeString("# ro.build.product is obsolete; use ro.product.device") | 
|  | 133 | writeProp("ro.build.product", $TARGET_DEVICE) | 
|  | 134 |  | 
|  | 135 | writeString("# Do not try to parse description or thumbprint") | 
|  | 136 | writeProp("ro.build.description", $PRIVATE_BUILD_DESC) | 
|  | 137 | if [ -n "$BUILD_THUMBPRINT" ] { | 
|  | 138 | writeProp("ro.build.thumbprint", $BUILD_THUMBPRINT) | 
|  | 139 | } | 
|  | 140 | */ | 
|  | 141 |  | 
|  | 142 | writeString("# end build properties") | 
|  | 143 |  | 
| Cole Faust | a734749 | 2022-12-16 10:56:24 -0800 | [diff] [blame] | 144 | WriteFileRule(ctx, p.outputFilePath, strings.Join(lines, "\n")) | 
| Inseob Kim | 4f1f3d9 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 145 |  | 
|  | 146 | if !p.installable() { | 
|  | 147 | p.SkipInstall() | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | p.installPath = PathForModuleInstall(ctx) | 
|  | 151 | ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath) | 
|  | 152 | } | 
|  | 153 |  | 
|  | 154 | func (f *buildinfoPropModule) GenerateSingletonBuildActions(ctx SingletonContext) { | 
|  | 155 | // does nothing; buildinfo_prop is a singeton because two buildinfo modules don't make sense. | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries { | 
|  | 159 | return []AndroidMkEntries{AndroidMkEntries{ | 
|  | 160 | Class:      "ETC", | 
|  | 161 | OutputFile: OptionalPathForPath(p.outputFilePath), | 
|  | 162 | ExtraEntries: []AndroidMkExtraEntriesFunc{ | 
|  | 163 | func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) { | 
|  | 164 | entries.SetString("LOCAL_MODULE_PATH", p.installPath.String()) | 
|  | 165 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) | 
|  | 166 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) | 
|  | 167 | }, | 
|  | 168 | }, | 
|  | 169 | }} | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | // buildinfo_prop module generates a build.prop file, which contains a set of common | 
|  | 173 | // system/build.prop properties, such as ro.build.version.*.  Not all properties are implemented; | 
|  | 174 | // currently this module is only for microdroid. | 
|  | 175 | func buildinfoPropFactory() SingletonModule { | 
|  | 176 | module := &buildinfoPropModule{} | 
|  | 177 | module.AddProperties(&module.properties) | 
|  | 178 | InitAndroidModule(module) | 
|  | 179 | return module | 
|  | 180 | } |