buildinfo_prop.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. package android
  15. import (
  16. "fmt"
  17. "strings"
  18. "github.com/google/blueprint/proptools"
  19. )
  20. func init() {
  21. ctx := InitRegistrationContext
  22. ctx.RegisterSingletonModuleType("buildinfo_prop", buildinfoPropFactory)
  23. }
  24. type buildinfoPropProperties struct {
  25. // Whether this module is directly installable to one of the partitions. Default: true.
  26. Installable *bool
  27. }
  28. type buildinfoPropModule struct {
  29. SingletonModuleBase
  30. properties buildinfoPropProperties
  31. outputFilePath OutputPath
  32. installPath InstallPath
  33. }
  34. var _ OutputFileProducer = (*buildinfoPropModule)(nil)
  35. func (p *buildinfoPropModule) installable() bool {
  36. return proptools.BoolDefault(p.properties.Installable, true)
  37. }
  38. // OutputFileProducer
  39. func (p *buildinfoPropModule) OutputFiles(tag string) (Paths, error) {
  40. if tag != "" {
  41. return nil, fmt.Errorf("unsupported tag %q", tag)
  42. }
  43. return Paths{p.outputFilePath}, nil
  44. }
  45. func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
  46. p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath
  47. if !ctx.Config().KatiEnabled() {
  48. WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled")
  49. return
  50. }
  51. rule := NewRuleBuilder(pctx, ctx)
  52. cmd := rule.Command().Text("(")
  53. writeString := func(str string) {
  54. cmd.Text(`echo "` + str + `" && `)
  55. }
  56. writeString("# begin build properties")
  57. writeString("# autogenerated by build/soong/android/buildinfo_prop.go")
  58. writeProp := func(key, value string) {
  59. if strings.Contains(key, "=") {
  60. panic(fmt.Errorf("wrong property key %q: key must not contain '='", key))
  61. }
  62. writeString(key + "=" + value)
  63. }
  64. config := ctx.Config()
  65. writeProp("ro.build.version.sdk", config.PlatformSdkVersion().String())
  66. writeProp("ro.build.version.preview_sdk", config.PlatformPreviewSdkVersion())
  67. writeProp("ro.build.version.codename", config.PlatformSdkCodename())
  68. writeProp("ro.build.version.all_codenames", strings.Join(config.PlatformVersionActiveCodenames(), ","))
  69. writeProp("ro.build.version.release", config.PlatformVersionLastStable())
  70. writeProp("ro.build.version.release_or_codename", config.PlatformVersionName())
  71. writeProp("ro.build.version.security_patch", config.PlatformSecurityPatch())
  72. writeProp("ro.build.version.base_os", config.PlatformBaseOS())
  73. writeProp("ro.build.version.min_supported_target_sdk", config.PlatformMinSupportedTargetSdkVersion())
  74. if config.Eng() {
  75. writeProp("ro.build.type", "eng")
  76. } else if config.Debuggable() {
  77. writeProp("ro.build.type", "userdebug")
  78. } else {
  79. writeProp("ro.build.type", "user")
  80. }
  81. // Currently, only a few properties are implemented to unblock microdroid use case.
  82. // TODO(b/189164487): support below properties as well and replace build/make/tools/buildinfo.sh
  83. /*
  84. if $BOARD_USE_VBMETA_DIGTEST_IN_FINGERPRINT {
  85. writeProp("ro.build.legacy.id", config.BuildID())
  86. } else {
  87. writeProp("ro.build.id", config.BuildId())
  88. }
  89. writeProp("ro.build.display.id", $BUILD_DISPLAY_ID)
  90. writeProp("ro.build.version.incremental", $BUILD_NUMBER)
  91. writeProp("ro.build.version.preview_sdk_fingerprint", $PLATFORM_PREVIEW_SDK_FINGERPRINT)
  92. writeProp("ro.build.version.known_codenames", $PLATFORM_VERSION_KNOWN_CODENAMES)
  93. writeProp("ro.build.version.release_or_preview_display", $PLATFORM_DISPLAY_VERSION)
  94. writeProp("ro.build.date", `$DATE`)
  95. writeProp("ro.build.date.utc", `$DATE +%s`)
  96. writeProp("ro.build.user", $BUILD_USERNAME)
  97. writeProp("ro.build.host", $BUILD_HOSTNAME)
  98. writeProp("ro.build.tags", $BUILD_VERSION_TAGS)
  99. writeProp("ro.build.flavor", $TARGET_BUILD_FLAVOR)
  100. // These values are deprecated, use "ro.product.cpu.abilist"
  101. // instead (see below).
  102. writeString("# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,")
  103. writeString("# use ro.product.cpu.abilist instead.")
  104. writeProp("ro.product.cpu.abi", $TARGET_CPU_ABI)
  105. if [ -n "$TARGET_CPU_ABI2" ] {
  106. writeProp("ro.product.cpu.abi2", $TARGET_CPU_ABI2)
  107. }
  108. if [ -n "$PRODUCT_DEFAULT_LOCALE" ] {
  109. writeProp("ro.product.locale", $PRODUCT_DEFAULT_LOCALE)
  110. }
  111. writeProp("ro.wifi.channels", $PRODUCT_DEFAULT_WIFI_CHANNELS)
  112. writeString("# ro.build.product is obsolete; use ro.product.device")
  113. writeProp("ro.build.product", $TARGET_DEVICE)
  114. writeString("# Do not try to parse description or thumbprint")
  115. writeProp("ro.build.description", $PRIVATE_BUILD_DESC)
  116. if [ -n "$BUILD_THUMBPRINT" ] {
  117. writeProp("ro.build.thumbprint", $BUILD_THUMBPRINT)
  118. }
  119. */
  120. writeString("# end build properties")
  121. cmd.Text("true) > ").Output(p.outputFilePath)
  122. rule.Build("build.prop", "generating build.prop")
  123. if !p.installable() {
  124. p.SkipInstall()
  125. }
  126. p.installPath = PathForModuleInstall(ctx)
  127. ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath)
  128. }
  129. func (f *buildinfoPropModule) GenerateSingletonBuildActions(ctx SingletonContext) {
  130. // does nothing; buildinfo_prop is a singeton because two buildinfo modules don't make sense.
  131. }
  132. func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries {
  133. return []AndroidMkEntries{AndroidMkEntries{
  134. Class: "ETC",
  135. OutputFile: OptionalPathForPath(p.outputFilePath),
  136. ExtraEntries: []AndroidMkExtraEntriesFunc{
  137. func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) {
  138. entries.SetString("LOCAL_MODULE_PATH", p.installPath.String())
  139. entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
  140. entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
  141. },
  142. },
  143. }}
  144. }
  145. // buildinfo_prop module generates a build.prop file, which contains a set of common
  146. // system/build.prop properties, such as ro.build.version.*. Not all properties are implemented;
  147. // currently this module is only for microdroid.
  148. func buildinfoPropFactory() SingletonModule {
  149. module := &buildinfoPropModule{}
  150. module.AddProperties(&module.properties)
  151. InitAndroidModule(module)
  152. return module
  153. }