Merge changes from topic "product_config_module" into main
* changes: Use product_config from buildinfo_prop module Add product_config module
This commit is contained in:
@@ -128,6 +128,8 @@ buildinfo_prop {
|
||||
// not installable because this will be included to system/build.prop
|
||||
installable: false,
|
||||
|
||||
product_config: ":product_config",
|
||||
|
||||
// Currently, only microdroid can refer to buildinfo.prop
|
||||
visibility: ["//packages/modules/Virtualization/microdroid"],
|
||||
}
|
||||
@@ -136,3 +138,8 @@ buildinfo_prop {
|
||||
all_apex_contributions {
|
||||
name: "all_apex_contributions",
|
||||
}
|
||||
|
||||
product_config {
|
||||
name: "product_config",
|
||||
visibility: ["//visibility:private"],
|
||||
}
|
||||
|
@@ -83,6 +83,7 @@ bootstrap_go_package {
|
||||
"plugin.go",
|
||||
"prebuilt.go",
|
||||
"prebuilt_build_tool.go",
|
||||
"product_config.go",
|
||||
"proto.go",
|
||||
"provider.go",
|
||||
"raw_files.go",
|
||||
|
@@ -16,7 +16,6 @@ package android
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
@@ -29,6 +28,8 @@ func init() {
|
||||
type buildinfoPropProperties struct {
|
||||
// Whether this module is directly installable to one of the partitions. Default: true.
|
||||
Installable *bool
|
||||
|
||||
Product_config *string `android:"path"`
|
||||
}
|
||||
|
||||
type buildinfoPropModule struct {
|
||||
@@ -54,24 +55,6 @@ 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",
|
||||
@@ -101,20 +84,10 @@ func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||
rule := NewRuleBuilder(pctx, ctx)
|
||||
|
||||
config := ctx.Config()
|
||||
buildVariant := getBuildVariant(config)
|
||||
buildFlavor := getBuildFlavor(config)
|
||||
|
||||
cmd := rule.Command().BuiltTool("buildinfo")
|
||||
|
||||
if config.BoardUseVbmetaDigestInFingerprint() {
|
||||
cmd.Flag("--use-vbmeta-digest-in-fingerprint")
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
// Note: depending on BuildNumberFile will cause the build.prop file to be rebuilt
|
||||
// every build, but that's intentional.
|
||||
cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
|
||||
@@ -122,42 +95,14 @@ func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||
// In the previous make implementation, a dependency was not added on the thumbprint file
|
||||
cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
// Technically we should also have a dependency on BUILD_DATETIME_FILE,
|
||||
// but it can be either an absolute or relative path, which is hard to turn into
|
||||
// a Path object. So just rely on the BuildNumberFile always changing to cause
|
||||
// us to rebuild.
|
||||
cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
|
||||
|
||||
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.FlagWithInput("--product-config=", PathForModuleSrc(ctx, proptools.String(p.properties.Product_config)))
|
||||
cmd.FlagWithOutput("--out=", p.outputFilePath)
|
||||
|
||||
rule.Build(ctx.ModuleName(), "generating buildinfo props")
|
||||
|
58
android/product_config.go
Normal file
58
android/product_config.go
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2024 Google Inc. All rights reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
package android
|
||||
|
||||
import "github.com/google/blueprint/proptools"
|
||||
|
||||
func init() {
|
||||
ctx := InitRegistrationContext
|
||||
ctx.RegisterModuleType("product_config", productConfigFactory)
|
||||
}
|
||||
|
||||
type productConfigModule struct {
|
||||
ModuleBase
|
||||
}
|
||||
|
||||
func (p *productConfigModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||
if ctx.ModuleName() != "product_config" || ctx.ModuleDir() != "build/soong" {
|
||||
ctx.ModuleErrorf("There can only be one product_config module in build/soong")
|
||||
return
|
||||
}
|
||||
outputFilePath := PathForModuleOut(ctx, p.Name()+".json").OutputPath
|
||||
|
||||
// DeviceProduct can be null so calling ctx.Config().DeviceProduct() may cause null dereference
|
||||
targetProduct := proptools.String(ctx.Config().config.productVariables.DeviceProduct)
|
||||
if targetProduct != "" {
|
||||
targetProduct += "."
|
||||
}
|
||||
soongVariablesPath := PathForOutput(ctx, "soong."+targetProduct+"variables")
|
||||
extraVariablesPath := PathForOutput(ctx, "soong."+targetProduct+"extra.variables")
|
||||
|
||||
rule := NewRuleBuilder(pctx, ctx)
|
||||
rule.Command().BuiltTool("merge_json").
|
||||
Output(outputFilePath).
|
||||
Input(soongVariablesPath).
|
||||
Input(extraVariablesPath).
|
||||
rule.Build("product_config.json", "building product_config.json")
|
||||
|
||||
ctx.SetOutputFiles(Paths{outputFilePath}, "")
|
||||
}
|
||||
|
||||
// product_config module exports product variables and extra variables as a JSON file.
|
||||
func productConfigFactory() Module {
|
||||
module := &productConfigModule{}
|
||||
InitAndroidModule(module)
|
||||
return module
|
||||
}
|
@@ -291,6 +291,14 @@ python_binary_host {
|
||||
],
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
name: "merge_json",
|
||||
main: "merge_json.py",
|
||||
srcs: [
|
||||
"merge_json.py",
|
||||
],
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
name: "buildinfo",
|
||||
main: "buildinfo.py",
|
||||
|
@@ -18,46 +18,78 @@
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
TEST_KEY_DIR = "build/make/target/product/security"
|
||||
|
||||
def get_build_variant(product_config):
|
||||
if product_config["Eng"]:
|
||||
return "eng"
|
||||
elif product_config["Debuggable"]:
|
||||
return "userdebug"
|
||||
else:
|
||||
return "user"
|
||||
|
||||
def get_build_flavor(product_config):
|
||||
build_flavor = product_config["DeviceProduct"] + "-" + get_build_variant(product_config)
|
||||
if "address" in product_config.get("SanitizeDevice", []) and "_asan" not in build_flavor:
|
||||
build_flavor += "_asan"
|
||||
return build_flavor
|
||||
|
||||
def get_build_keys(product_config):
|
||||
default_cert = product_config.get("DefaultAppCertificate", "")
|
||||
if default_cert == "" or default_cert == os.path.join(TEST_KEY_DIR, "testKey"):
|
||||
return "test-keys"
|
||||
return "dev-keys"
|
||||
|
||||
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('--product-config', required=True, type=argparse.FileType('r'))
|
||||
parser.add_argument('--out', required=True, type=argparse.FileType('w'))
|
||||
|
||||
return parser.parse_args()
|
||||
option = parser.parse_args()
|
||||
|
||||
product_config = json.load(option.product_config)
|
||||
build_flags = product_config["BuildFlags"]
|
||||
|
||||
option.build_flavor = get_build_flavor(product_config)
|
||||
option.build_keys = get_build_keys(product_config)
|
||||
option.build_id = product_config["BuildId"]
|
||||
option.build_type = product_config["BuildType"]
|
||||
option.build_variant = get_build_variant(product_config)
|
||||
option.cpu_abis = product_config["DeviceAbi"]
|
||||
option.default_locale = None
|
||||
if len(product_config.get("ProductLocales", [])) > 0:
|
||||
option.default_locale = product_config["ProductLocales"][0]
|
||||
option.default_wifi_channels = product_config.get("ProductDefaultWifiChannels", [])
|
||||
option.device = product_config["DeviceName"]
|
||||
option.display_build_number = product_config["DisplayBuildNumber"]
|
||||
option.platform_base_os = product_config["Platform_base_os"]
|
||||
option.platform_display_version = product_config["Platform_display_version_name"]
|
||||
option.platform_min_supported_target_sdk_version = build_flags["RELEASE_PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION"]
|
||||
option.platform_preview_sdk_version = product_config["Platform_preview_sdk_version"]
|
||||
option.platform_sdk_version = product_config["Platform_sdk_version"]
|
||||
option.platform_security_patch = product_config["Platform_security_patch"]
|
||||
option.platform_version = product_config["Platform_version_name"]
|
||||
option.platform_version_codename = product_config["Platform_sdk_codename"]
|
||||
option.platform_version_all_codenames = product_config["Platform_version_active_codenames"]
|
||||
option.platform_version_known_codenames = product_config["Platform_version_known_codenames"]
|
||||
option.platform_version_last_stable = product_config["Platform_version_last_stable"]
|
||||
option.product = product_config["DeviceProduct"]
|
||||
option.use_vbmeta_digest_in_fingerprint = product_config["BoardUseVbmetaDigestInFingerprint"]
|
||||
|
||||
return option
|
||||
|
||||
def main():
|
||||
option = parse_args()
|
||||
|
62
scripts/merge_json.py
Normal file
62
scripts/merge_json.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 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 merging two or more JSON files."""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import json
|
||||
import sys
|
||||
|
||||
def parse_args():
|
||||
"""Parse commandline arguments."""
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("output", help="output JSON file", type=argparse.FileType("w"))
|
||||
parser.add_argument("input", help="input JSON files", nargs="+", type=argparse.FileType("r"))
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
"""Program entry point."""
|
||||
args = parse_args()
|
||||
merged_dict = {}
|
||||
has_error = False
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
for json_file in args.input:
|
||||
try:
|
||||
data = json.load(json_file)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error parsing JSON in file: {json_file.name}. Reason: {e}")
|
||||
has_error = True
|
||||
continue
|
||||
|
||||
for key, value in data.items():
|
||||
if key not in merged_dict:
|
||||
merged_dict[key] = value
|
||||
elif merged_dict[key] == value:
|
||||
logger.warning(f"Duplicate key '{key}' with identical values found.")
|
||||
else:
|
||||
logger.error(f"Conflicting values for key '{key}': {merged_dict[key]} != {value}")
|
||||
has_error = True
|
||||
|
||||
if has_error:
|
||||
sys.exit(1)
|
||||
|
||||
json.dump(merged_dict, args.output)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@@ -1488,6 +1488,15 @@ func (c *configImpl) SoongVarsFile() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configImpl) SoongExtraVarsFile() string {
|
||||
targetProduct, err := c.TargetProductOrErr()
|
||||
if err != nil {
|
||||
return filepath.Join(c.SoongOutDir(), "soong.extra.variables")
|
||||
} else {
|
||||
return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+".extra.variables")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configImpl) SoongNinjaFile() string {
|
||||
targetProduct, err := c.TargetProductOrErr()
|
||||
if err != nil {
|
||||
|
@@ -694,6 +694,7 @@ func runSoong(ctx Context, config Config) {
|
||||
}
|
||||
}
|
||||
distFile(ctx, config, config.SoongVarsFile(), "soong")
|
||||
distFile(ctx, config, config.SoongExtraVarsFile(), "soong")
|
||||
|
||||
if !config.SkipKati() {
|
||||
distGzipFile(ctx, config, config.SoongAndroidMk(), "soong")
|
||||
|
@@ -64,7 +64,8 @@ func testForDanglingRules(ctx Context, config Config) {
|
||||
outDir := config.OutDir()
|
||||
modulePathsDir := filepath.Join(outDir, ".module_paths")
|
||||
rawFilesDir := filepath.Join(outDir, "soong", "raw")
|
||||
variablesFilePath := filepath.Join(outDir, "soong", "soong.variables")
|
||||
variablesFilePath := config.SoongVarsFile()
|
||||
extraVariablesFilePath := config.SoongExtraVarsFile()
|
||||
|
||||
// dexpreopt.config is an input to the soong_docs action, which runs the
|
||||
// soong_build primary builder. However, this file is created from $(shell)
|
||||
@@ -95,6 +96,7 @@ func testForDanglingRules(ctx Context, config Config) {
|
||||
if strings.HasPrefix(line, modulePathsDir) ||
|
||||
strings.HasPrefix(line, rawFilesDir) ||
|
||||
line == variablesFilePath ||
|
||||
line == extraVariablesFilePath ||
|
||||
line == dexpreoptConfigFilePath ||
|
||||
line == buildDatetimeFilePath ||
|
||||
line == bpglob ||
|
||||
|
Reference in New Issue
Block a user