Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5baf2cbc authored by Inseob Kim's avatar Inseob Kim
Browse files

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.

Bug: 322090587
Test: compare build.prop before and after
Test: build multiple times and see build.prop isn't rebuilt
Change-Id: Icaa7e1fdab2a8c169ac00949d3aaf6c8212a1872
parent 9dcc3676
Loading
Loading
Loading
Loading
+82 −70
Original line number Diff line number Diff line
@@ -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)
	rule := NewRuleBuilder(pctx, ctx)

	writeString := func(str string) {
		lines = append(lines, str)
	}
	config := ctx.Config()
	buildVariant := getBuildVariant(config)
	buildFlavor := getBuildFlavor(config)

	writeString("# begin build properties")
	writeString("# autogenerated by build/soong/android/buildinfo_prop.go")
	cmd := rule.Command().BuiltTool("buildinfo")

	writeProp := func(key, value string) {
		if strings.Contains(key, "=") {
			panic(fmt.Errorf("wrong property key %q: key must not contain '='", key))
	if config.BoardUseVbmetaDigestInFingerprint() {
		cmd.Flag("--use-vbmeta-digest-in-fingerprint")
	}
		writeString(key + "=" + value)

	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())

	// 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())
	}

	config := ctx.Config()
	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())

	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())
	// 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"))

	if config.Eng() {
		writeProp("ro.build.type", "eng")
	} else if config.Debuggable() {
		writeProp("ro.build.type", "userdebug")
	} else {
		writeProp("ro.build.type", "user")
	if len(config.ProductLocales()) > 0 {
		cmd.FlagWithArg("--default-locale=", config.ProductLocales()[0])
	}

	// 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)
		}

		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)

		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)
		}
	*/

	writeString("# end build properties")

	WriteFileRule(ctx, p.outputFilePath, strings.Join(lines, "\n"))
	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()
+61 −2
Original line number Diff line number Diff line
@@ -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 PathForOutput(ctx, 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
}
+8 −0
Original line number Diff line number Diff line
@@ -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)
}
+18 −5
Original line number Diff line number Diff line
@@ -195,7 +195,11 @@ type ProductVariables struct {

	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"`
@@ -474,7 +480,6 @@ type ProductVariables struct {

	ProductManufacturer string `json:",omitempty"`
	ProductBrand        string `json:",omitempty"`
	BuildVersionTags    []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 {
+4 −11
Original line number Diff line number Diff line
@@ -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())
}
Loading