Reland "Migrate buildinfo.sh script into Soong"
To build system.img in Soong, we need all artifacts including build.prop. This fully migrates buildinfo.prop file into Soong as a first step to build build.prop on Soong. This fixes an error caused by an incorrect path to build thumbprint file. Bug: 322090587 Test: compare build.prop before and after Test: build multiple times and see build.prop isn't rebuilt Change-Id: Id4fa830009538856c30825ff47268b11fa6cb5d6
This commit is contained in:
parent
8399758b97
commit
8fa54dab08
7 changed files with 341 additions and 89 deletions
|
@ -54,6 +54,39 @@ func (p *buildinfoPropModule) OutputFiles(tag string) (Paths, error) {
|
|||
return Paths{p.outputFilePath}, nil
|
||||
}
|
||||
|
||||
func getBuildVariant(config Config) string {
|
||||
if config.Eng() {
|
||||
return "eng"
|
||||
} else if config.Debuggable() {
|
||||
return "userdebug"
|
||||
} else {
|
||||
return "user"
|
||||
}
|
||||
}
|
||||
|
||||
func getBuildFlavor(config Config) string {
|
||||
buildFlavor := config.DeviceProduct() + "-" + getBuildVariant(config)
|
||||
if InList("address", config.SanitizeDevice()) && !strings.Contains(buildFlavor, "_asan") {
|
||||
buildFlavor += "_asan"
|
||||
}
|
||||
return buildFlavor
|
||||
}
|
||||
|
||||
func shouldAddBuildThumbprint(config Config) bool {
|
||||
knownOemProperties := []string{
|
||||
"ro.product.brand",
|
||||
"ro.product.name",
|
||||
"ro.product.device",
|
||||
}
|
||||
|
||||
for _, knownProp := range knownOemProperties {
|
||||
if InList(knownProp, config.OemProperties()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||
p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath
|
||||
if !ctx.Config().KatiEnabled() {
|
||||
|
@ -61,87 +94,66 @@ func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|||
return
|
||||
}
|
||||
|
||||
lines := make([]string, 0)
|
||||
|
||||
writeString := func(str string) {
|
||||
lines = append(lines, str)
|
||||
}
|
||||
|
||||
writeString("# begin build properties")
|
||||
writeString("# autogenerated by build/soong/android/buildinfo_prop.go")
|
||||
|
||||
writeProp := func(key, value string) {
|
||||
if strings.Contains(key, "=") {
|
||||
panic(fmt.Errorf("wrong property key %q: key must not contain '='", key))
|
||||
}
|
||||
writeString(key + "=" + value)
|
||||
}
|
||||
rule := NewRuleBuilder(pctx, ctx)
|
||||
|
||||
config := ctx.Config()
|
||||
buildVariant := getBuildVariant(config)
|
||||
buildFlavor := getBuildFlavor(config)
|
||||
|
||||
writeProp("ro.build.version.sdk", config.PlatformSdkVersion().String())
|
||||
writeProp("ro.build.version.preview_sdk", config.PlatformPreviewSdkVersion())
|
||||
writeProp("ro.build.version.codename", config.PlatformSdkCodename())
|
||||
writeProp("ro.build.version.all_codenames", strings.Join(config.PlatformVersionActiveCodenames(), ","))
|
||||
writeProp("ro.build.version.release", config.PlatformVersionLastStable())
|
||||
writeProp("ro.build.version.release_or_codename", config.PlatformVersionName())
|
||||
writeProp("ro.build.version.security_patch", config.PlatformSecurityPatch())
|
||||
writeProp("ro.build.version.base_os", config.PlatformBaseOS())
|
||||
writeProp("ro.build.version.min_supported_target_sdk", config.PlatformMinSupportedTargetSdkVersion())
|
||||
writeProp("ro.build.version.known_codenames", config.PlatformVersionKnownCodenames())
|
||||
cmd := rule.Command().BuiltTool("buildinfo")
|
||||
|
||||
if config.Eng() {
|
||||
writeProp("ro.build.type", "eng")
|
||||
} else if config.Debuggable() {
|
||||
writeProp("ro.build.type", "userdebug")
|
||||
} else {
|
||||
writeProp("ro.build.type", "user")
|
||||
if config.BoardUseVbmetaDigestInFingerprint() {
|
||||
cmd.Flag("--use-vbmeta-digest-in-fingerprint")
|
||||
}
|
||||
|
||||
// Currently, only a few properties are implemented to unblock microdroid use case.
|
||||
// TODO(b/189164487): support below properties as well and replace build/make/tools/buildinfo.sh
|
||||
/*
|
||||
if $BOARD_USE_VBMETA_DIGTEST_IN_FINGERPRINT {
|
||||
writeProp("ro.build.legacy.id", config.BuildID())
|
||||
} else {
|
||||
writeProp("ro.build.id", config.BuildId())
|
||||
}
|
||||
writeProp("ro.build.display.id", $BUILD_DISPLAY_ID)
|
||||
writeProp("ro.build.version.incremental", $BUILD_NUMBER)
|
||||
writeProp("ro.build.version.preview_sdk_fingerprint", $PLATFORM_PREVIEW_SDK_FINGERPRINT)
|
||||
writeProp("ro.build.version.release_or_preview_display", $PLATFORM_DISPLAY_VERSION)
|
||||
writeProp("ro.build.date", `$DATE`)
|
||||
writeProp("ro.build.date.utc", `$DATE +%s`)
|
||||
writeProp("ro.build.user", $BUILD_USERNAME)
|
||||
writeProp("ro.build.host", $BUILD_HOSTNAME)
|
||||
writeProp("ro.build.tags", $BUILD_VERSION_TAGS)
|
||||
writeProp("ro.build.flavor", $TARGET_BUILD_FLAVOR)
|
||||
// These values are deprecated, use "ro.product.cpu.abilist"
|
||||
// instead (see below).
|
||||
writeString("# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,")
|
||||
writeString("# use ro.product.cpu.abilist instead.")
|
||||
writeProp("ro.product.cpu.abi", $TARGET_CPU_ABI)
|
||||
if [ -n "$TARGET_CPU_ABI2" ] {
|
||||
writeProp("ro.product.cpu.abi2", $TARGET_CPU_ABI2)
|
||||
}
|
||||
cmd.FlagWithArg("--build-flavor=", buildFlavor)
|
||||
cmd.FlagWithInput("--build-hostname-file=", config.BuildHostnameFile(ctx))
|
||||
cmd.FlagWithArg("--build-id=", config.BuildId())
|
||||
cmd.FlagWithArg("--build-keys=", config.BuildKeys())
|
||||
|
||||
if [ -n "$PRODUCT_DEFAULT_LOCALE" ] {
|
||||
writeProp("ro.product.locale", $PRODUCT_DEFAULT_LOCALE)
|
||||
}
|
||||
writeProp("ro.wifi.channels", $PRODUCT_DEFAULT_WIFI_CHANNELS)
|
||||
writeString("# ro.build.product is obsolete; use ro.product.device")
|
||||
writeProp("ro.build.product", $TARGET_DEVICE)
|
||||
// shouldn't depend on BuildNumberFile and BuildThumbprintFile to prevent from rebuilding
|
||||
// on every incremental build.
|
||||
cmd.FlagWithArg("--build-number-file=", config.BuildNumberFile(ctx).String())
|
||||
if shouldAddBuildThumbprint(config) {
|
||||
cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
|
||||
}
|
||||
|
||||
writeString("# Do not try to parse description or thumbprint")
|
||||
writeProp("ro.build.description", $PRIVATE_BUILD_DESC)
|
||||
if [ -n "$BUILD_THUMBPRINT" ] {
|
||||
writeProp("ro.build.thumbprint", $BUILD_THUMBPRINT)
|
||||
}
|
||||
*/
|
||||
cmd.FlagWithArg("--build-type=", config.BuildType())
|
||||
cmd.FlagWithArg("--build-username=", config.Getenv("BUILD_USERNAME"))
|
||||
cmd.FlagWithArg("--build-variant=", buildVariant)
|
||||
cmd.FlagForEachArg("--cpu-abis=", config.DeviceAbi())
|
||||
|
||||
writeString("# end build properties")
|
||||
// shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
|
||||
// build.
|
||||
cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
|
||||
|
||||
WriteFileRule(ctx, p.outputFilePath, strings.Join(lines, "\n"))
|
||||
if len(config.ProductLocales()) > 0 {
|
||||
cmd.FlagWithArg("--default-locale=", config.ProductLocales()[0])
|
||||
}
|
||||
|
||||
cmd.FlagForEachArg("--default-wifi-channels=", config.ProductDefaultWifiChannels())
|
||||
cmd.FlagWithArg("--device=", config.DeviceName())
|
||||
if config.DisplayBuildNumber() {
|
||||
cmd.Flag("--display-build-number")
|
||||
}
|
||||
|
||||
cmd.FlagWithArg("--platform-base-os=", config.PlatformBaseOS())
|
||||
cmd.FlagWithArg("--platform-display-version=", config.PlatformDisplayVersionName())
|
||||
cmd.FlagWithArg("--platform-min-supported-target-sdk-version=", config.PlatformMinSupportedTargetSdkVersion())
|
||||
cmd.FlagWithInput("--platform-preview-sdk-fingerprint-file=", ApiFingerprintPath(ctx))
|
||||
cmd.FlagWithArg("--platform-preview-sdk-version=", config.PlatformPreviewSdkVersion())
|
||||
cmd.FlagWithArg("--platform-sdk-version=", config.PlatformSdkVersion().String())
|
||||
cmd.FlagWithArg("--platform-security-patch=", config.PlatformSecurityPatch())
|
||||
cmd.FlagWithArg("--platform-version=", config.PlatformVersionName())
|
||||
cmd.FlagWithArg("--platform-version-codename=", config.PlatformSdkCodename())
|
||||
cmd.FlagForEachArg("--platform-version-all-codenames=", config.PlatformVersionActiveCodenames())
|
||||
cmd.FlagWithArg("--platform-version-known-codenames=", config.PlatformVersionKnownCodenames())
|
||||
cmd.FlagWithArg("--platform-version-last-stable=", config.PlatformVersionLastStable())
|
||||
cmd.FlagWithArg("--product=", config.DeviceProduct())
|
||||
|
||||
cmd.FlagWithOutput("--out=", p.outputFilePath)
|
||||
|
||||
rule.Build(ctx.ModuleName(), "generating buildinfo props")
|
||||
|
||||
if !p.installable() {
|
||||
p.SkipInstall()
|
||||
|
|
|
@ -114,6 +114,8 @@ const (
|
|||
GenerateDocFile
|
||||
)
|
||||
|
||||
const testKeyDir = "build/make/target/product/security"
|
||||
|
||||
// SoongOutDir returns the build output directory for the configuration.
|
||||
func (c Config) SoongOutDir() string {
|
||||
return c.soongOutDir
|
||||
|
@ -841,6 +843,10 @@ func (c *config) BuildId() string {
|
|||
return String(c.productVariables.BuildId)
|
||||
}
|
||||
|
||||
func (c *config) DisplayBuildNumber() bool {
|
||||
return Bool(c.productVariables.DisplayBuildNumber)
|
||||
}
|
||||
|
||||
// BuildNumberFile returns the path to a text file containing metadata
|
||||
// representing the current build's number.
|
||||
//
|
||||
|
@ -852,6 +858,23 @@ func (c *config) BuildNumberFile(ctx PathContext) Path {
|
|||
return PathForOutput(ctx, String(c.productVariables.BuildNumberFile))
|
||||
}
|
||||
|
||||
// BuildHostnameFile returns the path to a text file containing metadata
|
||||
// representing the current build's host name.
|
||||
func (c *config) BuildHostnameFile(ctx PathContext) Path {
|
||||
return PathForOutput(ctx, String(c.productVariables.BuildHostnameFile))
|
||||
}
|
||||
|
||||
// BuildThumbprintFile returns the path to a text file containing metadata
|
||||
// representing the current build's thumbprint.
|
||||
//
|
||||
// Rules that want to reference the build thumbprint should read from this file
|
||||
// without depending on it. They will run whenever their other dependencies
|
||||
// require them to run and get the current build thumbprint. This ensures they
|
||||
// don't rebuild on every incremental build when the build thumbprint changes.
|
||||
func (c *config) BuildThumbprintFile(ctx PathContext) Path {
|
||||
return PathForArbitraryOutput(ctx, "target", "product", c.DeviceName(), String(c.productVariables.BuildThumbprintFile))
|
||||
}
|
||||
|
||||
// DeviceName returns the name of the current device target.
|
||||
// TODO: take an AndroidModuleContext to select the device name for multi-device builds
|
||||
func (c *config) DeviceName() string {
|
||||
|
@ -873,6 +896,10 @@ func (c *config) HasDeviceProduct() bool {
|
|||
return c.productVariables.DeviceProduct != nil
|
||||
}
|
||||
|
||||
func (c *config) DeviceAbi() []string {
|
||||
return c.productVariables.DeviceAbi
|
||||
}
|
||||
|
||||
func (c *config) DeviceResourceOverlays() []string {
|
||||
return c.productVariables.DeviceResourceOverlays
|
||||
}
|
||||
|
@ -881,6 +908,10 @@ func (c *config) ProductResourceOverlays() []string {
|
|||
return c.productVariables.ProductResourceOverlays
|
||||
}
|
||||
|
||||
func (c *config) PlatformDisplayVersionName() string {
|
||||
return String(c.productVariables.Platform_display_version_name)
|
||||
}
|
||||
|
||||
func (c *config) PlatformVersionName() string {
|
||||
return String(c.productVariables.Platform_version_name)
|
||||
}
|
||||
|
@ -1038,7 +1069,7 @@ func (c *config) DefaultAppCertificateDir(ctx PathContext) SourcePath {
|
|||
if defaultCert != "" {
|
||||
return PathForSource(ctx, filepath.Dir(defaultCert))
|
||||
}
|
||||
return PathForSource(ctx, "build/make/target/product/security")
|
||||
return PathForSource(ctx, testKeyDir)
|
||||
}
|
||||
|
||||
func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
|
||||
|
@ -1050,10 +1081,18 @@ func (c *config) DefaultAppCertificate(ctx PathContext) (pem, key SourcePath) {
|
|||
return defaultDir.Join(ctx, "testkey.x509.pem"), defaultDir.Join(ctx, "testkey.pk8")
|
||||
}
|
||||
|
||||
func (c *config) BuildKeys() string {
|
||||
defaultCert := String(c.productVariables.DefaultAppCertificate)
|
||||
if defaultCert == "" || defaultCert == filepath.Join(testKeyDir, "testkey") {
|
||||
return "test-keys"
|
||||
}
|
||||
return "dev-keys"
|
||||
}
|
||||
|
||||
func (c *config) ApexKeyDir(ctx ModuleContext) SourcePath {
|
||||
// TODO(b/121224311): define another variable such as TARGET_APEX_KEY_OVERRIDE
|
||||
defaultCert := String(c.productVariables.DefaultAppCertificate)
|
||||
if defaultCert == "" || filepath.Dir(defaultCert) == "build/make/target/product/security" {
|
||||
if defaultCert == "" || filepath.Dir(defaultCert) == testKeyDir {
|
||||
// When defaultCert is unset or is set to the testkeys path, use the APEX keys
|
||||
// that is under the module dir
|
||||
return pathForModuleSrc(ctx)
|
||||
|
@ -1112,6 +1151,10 @@ func (c *config) Eng() bool {
|
|||
return Bool(c.productVariables.Eng)
|
||||
}
|
||||
|
||||
func (c *config) BuildType() string {
|
||||
return String(c.productVariables.BuildType)
|
||||
}
|
||||
|
||||
// DevicePrimaryArchType returns the ArchType for the first configured device architecture, or
|
||||
// Common if there are no device architectures.
|
||||
func (c *config) DevicePrimaryArchType() ArchType {
|
||||
|
@ -2086,3 +2129,19 @@ func (c *config) AllApexContributions() []string {
|
|||
func (c *config) BuildIgnoreApexContributionContents() []string {
|
||||
return c.productVariables.BuildIgnoreApexContributionContents
|
||||
}
|
||||
|
||||
func (c *config) ProductLocales() []string {
|
||||
return c.productVariables.ProductLocales
|
||||
}
|
||||
|
||||
func (c *config) ProductDefaultWifiChannels() []string {
|
||||
return c.productVariables.ProductDefaultWifiChannels
|
||||
}
|
||||
|
||||
func (c *config) BoardUseVbmetaDigestInFingerprint() bool {
|
||||
return Bool(c.productVariables.BoardUseVbmetaDigestInFingerprint)
|
||||
}
|
||||
|
||||
func (c *config) OemProperties() []string {
|
||||
return c.productVariables.OemProperties
|
||||
}
|
||||
|
|
|
@ -868,3 +868,11 @@ type AdditionalSdkInfo struct {
|
|||
}
|
||||
|
||||
var AdditionalSdkInfoProvider = blueprint.NewProvider[AdditionalSdkInfo]()
|
||||
|
||||
var apiFingerprintPathKey = NewOnceKey("apiFingerprintPathKey")
|
||||
|
||||
func ApiFingerprintPath(ctx PathContext) OutputPath {
|
||||
return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
|
||||
return PathForOutput(ctx, "api_fingerprint.txt")
|
||||
}).(OutputPath)
|
||||
}
|
||||
|
|
|
@ -193,9 +193,13 @@ type ProductVariables struct {
|
|||
// Suffix to add to generated Makefiles
|
||||
Make_suffix *string `json:",omitempty"`
|
||||
|
||||
BuildId *string `json:",omitempty"`
|
||||
BuildNumberFile *string `json:",omitempty"`
|
||||
BuildId *string `json:",omitempty"`
|
||||
BuildNumberFile *string `json:",omitempty"`
|
||||
BuildHostnameFile *string `json:",omitempty"`
|
||||
BuildThumbprintFile *string `json:",omitempty"`
|
||||
DisplayBuildNumber *bool `json:",omitempty"`
|
||||
|
||||
Platform_display_version_name *string `json:",omitempty"`
|
||||
Platform_version_name *string `json:",omitempty"`
|
||||
Platform_sdk_version *int `json:",omitempty"`
|
||||
Platform_sdk_codename *string `json:",omitempty"`
|
||||
|
@ -296,6 +300,8 @@ type ProductVariables struct {
|
|||
MinimizeJavaDebugInfo *bool `json:",omitempty"`
|
||||
Build_from_text_stub *bool `json:",omitempty"`
|
||||
|
||||
BuildType *string `json:",omitempty"`
|
||||
|
||||
Check_elf_files *bool `json:",omitempty"`
|
||||
|
||||
UncompressPrivAppDex *bool `json:",omitempty"`
|
||||
|
@ -472,9 +478,8 @@ type ProductVariables struct {
|
|||
|
||||
AfdoProfiles []string `json:",omitempty"`
|
||||
|
||||
ProductManufacturer string `json:",omitempty"`
|
||||
ProductBrand string `json:",omitempty"`
|
||||
BuildVersionTags []string `json:",omitempty"`
|
||||
ProductManufacturer string `json:",omitempty"`
|
||||
ProductBrand string `json:",omitempty"`
|
||||
|
||||
ReleaseVersion string `json:",omitempty"`
|
||||
ReleaseAconfigValueSets []string `json:",omitempty"`
|
||||
|
@ -502,6 +507,14 @@ type ProductVariables struct {
|
|||
ExportRuntimeApis *bool `json:",omitempty"`
|
||||
|
||||
AconfigContainerValidation string `json:",omitempty"`
|
||||
|
||||
ProductLocales []string `json:",omitempty"`
|
||||
|
||||
ProductDefaultWifiChannels []string `json:",omitempty"`
|
||||
|
||||
BoardUseVbmetaDigestInFingerprint *bool `json:",omitempty"`
|
||||
|
||||
OemProperties []string `json:",omitempty"`
|
||||
}
|
||||
|
||||
type PartitionQualifiedVariablesType struct {
|
||||
|
|
15
java/sdk.go
15
java/sdk.go
|
@ -31,7 +31,6 @@ func init() {
|
|||
|
||||
var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey")
|
||||
var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey")
|
||||
var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey")
|
||||
|
||||
func UseApiFingerprint(ctx android.BaseModuleContext) (useApiFingerprint bool, fingerprintSdkVersion string, fingerprintDeps android.OutputPath) {
|
||||
if ctx.Config().UnbundledBuild() && !ctx.Config().AlwaysUsePrebuiltSdks() {
|
||||
|
@ -45,8 +44,8 @@ func UseApiFingerprint(ctx android.BaseModuleContext) (useApiFingerprint bool, f
|
|||
|
||||
useApiFingerprint = apiFingerprintTrue || dessertShaIsSet
|
||||
if apiFingerprintTrue {
|
||||
fingerprintSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", ApiFingerprintPath(ctx).String())
|
||||
fingerprintDeps = ApiFingerprintPath(ctx)
|
||||
fingerprintSdkVersion = ctx.Config().PlatformSdkCodename() + fmt.Sprintf(".$$(cat %s)", android.ApiFingerprintPath(ctx).String())
|
||||
fingerprintDeps = android.ApiFingerprintPath(ctx)
|
||||
}
|
||||
if dessertShaIsSet {
|
||||
fingerprintSdkVersion = ctx.Config().Getenv("UNBUNDLED_BUILD_TARGET_SDK_WITH_DESSERT_SHA")
|
||||
|
@ -337,7 +336,7 @@ func nonUpdatableFrameworkAidlPath(ctx android.PathContext) android.OutputPath {
|
|||
|
||||
// Create api_fingerprint.txt
|
||||
func createAPIFingerprint(ctx android.SingletonContext) {
|
||||
out := ApiFingerprintPath(ctx)
|
||||
out := android.ApiFingerprintPath(ctx)
|
||||
|
||||
rule := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
|
@ -378,17 +377,11 @@ func createAPIFingerprint(ctx android.SingletonContext) {
|
|||
rule.Build("api_fingerprint", "generate api_fingerprint.txt")
|
||||
}
|
||||
|
||||
func ApiFingerprintPath(ctx android.PathContext) android.OutputPath {
|
||||
return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
|
||||
return android.PathForOutput(ctx, "api_fingerprint.txt")
|
||||
}).(android.OutputPath)
|
||||
}
|
||||
|
||||
func sdkMakeVars(ctx android.MakeVarsContext) {
|
||||
if ctx.Config().AlwaysUsePrebuiltSdks() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Strict("FRAMEWORK_AIDL", sdkFrameworkAidlPath(ctx).String())
|
||||
ctx.Strict("API_FINGERPRINT", ApiFingerprintPath(ctx).String())
|
||||
ctx.Strict("API_FINGERPRINT", android.ApiFingerprintPath(ctx).String())
|
||||
}
|
||||
|
|
|
@ -305,3 +305,14 @@ python_binary_host {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
name: "buildinfo",
|
||||
main: "buildinfo.py",
|
||||
srcs: ["buildinfo.py"],
|
||||
version: {
|
||||
py3: {
|
||||
embedded_launcher: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
156
scripts/buildinfo.py
Executable file
156
scripts/buildinfo.py
Executable file
|
@ -0,0 +1,156 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2024 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
"""A tool for generating buildinfo.prop"""
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import subprocess
|
||||
|
||||
def parse_args():
|
||||
"""Parse commandline arguments."""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--use-vbmeta-digest-in-fingerprint', action='store_true')
|
||||
parser.add_argument('--build-flavor', required=True)
|
||||
parser.add_argument('--build-hostname-file', required=True, type=argparse.FileType('r')),
|
||||
parser.add_argument('--build-id', required=True)
|
||||
parser.add_argument('--build-keys', required=True)
|
||||
parser.add_argument('--build-number-file', required=True, type=argparse.FileType('r'))
|
||||
parser.add_argument('--build-thumbprint-file', type=argparse.FileType('r'))
|
||||
parser.add_argument('--build-type', required=True)
|
||||
parser.add_argument('--build-username', required=True)
|
||||
parser.add_argument('--build-variant', required=True)
|
||||
parser.add_argument('--cpu-abis', action='append', required=True)
|
||||
parser.add_argument('--date-file', required=True, type=argparse.FileType('r'))
|
||||
parser.add_argument('--default-locale')
|
||||
parser.add_argument('--default-wifi-channels', action='append', default=[])
|
||||
parser.add_argument('--device', required=True)
|
||||
parser.add_argument("--display-build-number", action='store_true')
|
||||
parser.add_argument('--platform-base-os', required=True)
|
||||
parser.add_argument('--platform-display-version', required=True)
|
||||
parser.add_argument('--platform-min-supported-target-sdk-version', required=True)
|
||||
parser.add_argument('--platform-preview-sdk-fingerprint-file',
|
||||
required=True,
|
||||
type=argparse.FileType('r'))
|
||||
parser.add_argument('--platform-preview-sdk-version', required=True)
|
||||
parser.add_argument('--platform-sdk-version', required=True)
|
||||
parser.add_argument('--platform-security-patch', required=True)
|
||||
parser.add_argument('--platform-version', required=True)
|
||||
parser.add_argument('--platform-version-codename',required=True)
|
||||
parser.add_argument('--platform-version-all-codenames', action='append', required=True)
|
||||
parser.add_argument('--platform-version-known-codenames', required=True)
|
||||
parser.add_argument('--platform-version-last-stable', required=True)
|
||||
parser.add_argument('--product', required=True)
|
||||
|
||||
parser.add_argument('--out', required=True, type=argparse.FileType('w'))
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
option = parse_args()
|
||||
|
||||
build_hostname = option.build_hostname_file.read().strip()
|
||||
build_number = option.build_number_file.read().strip()
|
||||
build_version_tags = option.build_keys
|
||||
if option.build_type == "debug":
|
||||
build_version_tags = "debug," + build_version_tags
|
||||
|
||||
raw_date = option.date_file.read().strip()
|
||||
date = subprocess.check_output(["date", "-d", f"@{raw_date}"], text=True).strip()
|
||||
date_utc = subprocess.check_output(["date", "-d", f"@{raw_date}", "+%s"], text=True).strip()
|
||||
|
||||
# build_desc is human readable strings that describe this build. This has the same info as the
|
||||
# build fingerprint.
|
||||
# e.g. "aosp_cf_x86_64_phone-userdebug VanillaIceCream MAIN eng.20240319.143939 test-keys"
|
||||
build_desc = f"{option.product}-{option.build_variant} {option.platform_version} " \
|
||||
f"{option.build_id} {build_number} {build_version_tags}"
|
||||
|
||||
platform_preview_sdk_fingerprint = option.platform_preview_sdk_fingerprint_file.read().strip()
|
||||
|
||||
with contextlib.redirect_stdout(option.out):
|
||||
print("# begin build properties")
|
||||
print("# autogenerated by buildinfo.py")
|
||||
|
||||
# The ro.build.id will be set dynamically by init, by appending the unique vbmeta digest.
|
||||
if option.use_vbmeta_digest_in_fingerprint:
|
||||
print(f"ro.build.legacy.id={option.build_id}")
|
||||
else:
|
||||
print(f"ro.build.id?={option.build_id}")
|
||||
|
||||
# ro.build.display.id is shown under Settings -> About Phone
|
||||
if option.build_variant == "user":
|
||||
# User builds should show:
|
||||
# release build number or branch.buld_number non-release builds
|
||||
|
||||
# Dev. branches should have DISPLAY_BUILD_NUMBER set
|
||||
if option.display_build_number:
|
||||
print(f"ro.build.display.id?={option.build_id} {build_number} {option.build_keys}")
|
||||
else:
|
||||
print(f"ro.build.display.id?={option.build_id} {option.build_keys}")
|
||||
else:
|
||||
# Non-user builds should show detailed build information (See build desc above)
|
||||
print(f"ro.build.display.id?={build_desc}")
|
||||
print(f"ro.build.version.incremental={build_number}")
|
||||
print(f"ro.build.version.sdk={option.platform_sdk_version}")
|
||||
print(f"ro.build.version.preview_sdk={option.platform_preview_sdk_version}")
|
||||
print(f"ro.build.version.preview_sdk_fingerprint={platform_preview_sdk_fingerprint}")
|
||||
print(f"ro.build.version.codename={option.platform_version_codename}")
|
||||
print(f"ro.build.version.all_codenames={','.join(option.platform_version_all_codenames)}")
|
||||
print(f"ro.build.version.known_codenames={option.platform_version_known_codenames}")
|
||||
print(f"ro.build.version.release={option.platform_version_last_stable}")
|
||||
print(f"ro.build.version.release_or_codename={option.platform_version}")
|
||||
print(f"ro.build.version.release_or_preview_display={option.platform_display_version}")
|
||||
print(f"ro.build.version.security_patch={option.platform_security_patch}")
|
||||
print(f"ro.build.version.base_os={option.platform_base_os}")
|
||||
print(f"ro.build.version.min_supported_target_sdk={option.platform_min_supported_target_sdk_version}")
|
||||
print(f"ro.build.date={date}")
|
||||
print(f"ro.build.date.utc={date_utc}")
|
||||
print(f"ro.build.type={option.build_variant}")
|
||||
print(f"ro.build.user={option.build_username}")
|
||||
print(f"ro.build.host={build_hostname}")
|
||||
# TODO: Remove any tag-related optional property declarations once the goals
|
||||
# from go/arc-android-sigprop-changes have been achieved.
|
||||
print(f"ro.build.tags?={build_version_tags}")
|
||||
# ro.build.flavor are used only by the test harness to distinguish builds.
|
||||
# Only add _asan for a sanitized build if it isn't already a part of the
|
||||
# flavor (via a dedicated lunch config for example).
|
||||
print(f"ro.build.flavor={option.build_flavor}")
|
||||
|
||||
# These values are deprecated, use "ro.product.cpu.abilist"
|
||||
# instead (see below).
|
||||
print(f"# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,")
|
||||
print(f"# use ro.product.cpu.abilist instead.")
|
||||
print(f"ro.product.cpu.abi={option.cpu_abis[0]}")
|
||||
if len(option.cpu_abis) > 1:
|
||||
print(f"ro.product.cpu.abi2={option.cpu_abis[1]}")
|
||||
|
||||
if option.default_locale:
|
||||
print(f"ro.product.locale={option.default_locale}")
|
||||
print(f"ro.wifi.channels={' '.join(option.default_wifi_channels)}")
|
||||
|
||||
print(f"# ro.build.product is obsolete; use ro.product.device")
|
||||
print(f"ro.build.product={option.device}")
|
||||
|
||||
print(f"# Do not try to parse description or thumbprint")
|
||||
print(f"ro.build.description?={build_desc}")
|
||||
if option.build_thumbprint_file:
|
||||
build_thumbprint = option.build_thumbprint_file.read().strip()
|
||||
print(f"ro.build.thumbprint={build_thumbprint}")
|
||||
|
||||
print(f"# end build properties")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue