Merge "Make global config depend on version defaults." am: b9306ac477 am: 64f39fec22

Original change: https://android-review.googlesource.com/c/platform/build/+/1822533

Change-Id: I19899584b5da0acafe9b1cb23157ba5a94b9b5a7
This commit is contained in:
Alexander Smundak 2021-09-20 17:31:20 +00:00 committed by Automerger Merge Worker
commit ffaa210dca
4 changed files with 52 additions and 26 deletions

View file

@ -38,7 +38,7 @@ def _allowed_versions(all_versions, min_version, max_version, default_version):
return all_versions[min_i:max_i + 1]
# This function is a manual conversion of the version_defaults.mk
def _versions_default(g, all_versions):
def _versions_default(g, all_versions, v):
"""Handle various build version information.
Guarantees that the following are defined:
@ -59,17 +59,21 @@ def _versions_default(g, all_versions):
_build_id_init(g)
g["INTERNAL_BUILD_ID_MAKEFILE"] = "build/make/core/build_id"
allowed_versions = _allowed_versions(all_versions, v_min, v_max, v_default)
g.setdefault("TARGET_PLATFORM_VERSION", v_default)
allowed_versions = _allowed_versions(all_versions, v.min_platform_version, v.max_platform_version, v.default_platform_version)
g.setdefault("TARGET_PLATFORM_VERSION", v.default_platform_version)
if g["TARGET_PLATFORM_VERSION"] not in allowed_versions:
fail("% is not valid, must be one of %s" % (g["TARGET_PLATFORM_VERSION"], allowed_versions))
g["DEFAULT_PLATFORM_VERSION"] = v_default
g["PLATFORM_VERSION_LAST_STABLE"] = 11
g.setdefault("PLATFORM_VERSION_CODENAME", g["TARGET_PLATFORM_VERSION"])
g["DEFAULT_PLATFORM_VERSION"] = v.default_platform_version
g["PLATFORM_VERSION_LAST_STABLE"] = v.platform_version_last_stable
target_platform_version = g["TARGET_PLATFORM_VERSION"]
if v.codenames[target_platform_version]:
g.setdefault("PLATFORM_VERSION_CODENAME", v.codenames[target_platform_version])
else:
g.setdefault("PLATFORM_VERSION_CODENAME", target_platform_version)
# TODO(asmundak): set PLATFORM_VERSION_ALL_CODENAMES
g.setdefault("PLATFORM_SDK_VERSION", 30)
g.setdefault("PLATFORM_SDK_VERSION", v.platform_sdk_version)
version_codename = g["PLATFORM_VERSION_CODENAME"]
if version_codename == "REL":
g.setdefault("PLATFORM_VERSION", g["PLATFORM_VERSION_LAST_STABLE"])
@ -92,7 +96,8 @@ def _versions_default(g, all_versions):
# It must be of the form "YYYY-MM-DD" on production devices.
# It must match one of the Android Security Patch Level strings of the Public Security Bulletins.
# If there is no $PLATFORM_SECURITY_PATCH set, keep it empty.
g.setdefault("PLATFORM_SECURITY_PATCH", "2021-03-05")
g.setdefault("PLATFORM_SECURITY_PATCH", v.platform_security_patch)
dt = 'TZ="GMT" %s' % g["PLATFORM_SECURITY_PATCH"]
g.setdefault("PLATFORM_SECURITY_PATCH_TIMESTAMP", rblf_shell("date -d '%s' +%%s" % dt))
@ -116,16 +121,23 @@ def _versions_default(g, all_versions):
# in a warning being shown when any activity from the app is started.
g.setdefault("PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION", 23)
def init(g):
# This is the sdk extension version of this tree.
g["PLATFORM_SDK_EXTENSION_VERSION"] = v.platform_sdk_extension_version
# This is the sdk extension version that PLATFORM_SDK_VERSION ships with.
g["PLATFORM_BASE_SDK_EXTENSION_VERSION"] = v.platform_base_sdk_extension_version
def init(g, v):
"""Initializes globals.
The code is the Starlark counterpart of the contents of the
envsetup.mk file.
Args:
g: globals dictionary
v: version info struct
"""
all_versions = _all_versions()
_versions_default(g, all_versions)
_versions_default(g, all_versions, v)
for v in all_versions:
g["IS_AT_LEAST" + v] = True
if v == g["TARGET_PLATFORM_VERSION"]:
@ -210,7 +222,3 @@ def init(g):
if g.get("TARGET_BUILD_TYPE", "") != "debug":
g["TARGET_BUILD_TYPE"] = "release"
v_default = "SP1A"
v_min = "SP1A"
v_max = "SP1A"

View file

@ -17,7 +17,7 @@ load("//build/make/core:envsetup.rbc", _envsetup_init = "init")
"""Runtime functions."""
_soong_config_namespaces_key = "$SOONG_CONFIG_NAMESPACES"
def _global_init():
def _global_init(version_info):
"""Returns dict created from the runtime environment."""
globals = dict()
@ -31,7 +31,7 @@ def _global_init():
globals.setdefault("PRODUCT_SOONG_NAMESPACES", [])
globals.setdefault(_soong_config_namespaces_key, {})
_envsetup_init(globals)
_envsetup_init(globals, version_info)
# Variables that should be defined.
mandatory_vars = [
@ -46,10 +46,8 @@ def _global_init():
for bv in mandatory_vars:
if not bv in globals:
fail(bv, " is not defined")
return globals
_globals_base = _global_init()
def __print_attr(attr, value):
if not value:
@ -69,8 +67,9 @@ def __print_attr(attr, value):
else:
fail("bad output format", _options.format)
def _printvars(globals, cfg):
"""Prints known configuration variables."""
def _printvars(state):
"""Prints configuration and global variables."""
(globals, cfg, globals_base) = state
for attr, val in sorted(cfg.items()):
__print_attr(attr, val)
if _options.print_globals:
@ -85,7 +84,7 @@ def _printvars(globals, cfg):
print("SOONG_CONFIG_" + nsname, ":=", " ".join(nsvars.keys()))
for var, val in sorted(nsvars.items()):
__print_attr("SOONG_CONFIG_%s_%s" % (nsname, var), val)
elif attr not in _globals_base:
elif attr not in globals_base:
__print_attr(attr, val)
def __printvars_rearrange_list(value_list):
@ -93,7 +92,7 @@ def __printvars_rearrange_list(value_list):
seen = {item: 0 for item in value_list}
return sorted(seen.keys()) if _options.rearrange == "sort" else seen.keys()
def _product_configuration(top_pcm_name, top_pcm):
def _product_configuration(top_pcm_name, top_pcm, version_info):
"""Creates configuration."""
# Product configuration is created by traversing product's inheritance
@ -107,7 +106,8 @@ def _product_configuration(top_pcm_name, top_pcm):
# PCM means "Product Configuration Module", i.e., a Starlark file
# whose body consists of a single init function.
globals = dict(**_globals_base)
globals_base = _global_init(version_info)
globals = dict(**globals_base)
config_postfix = [] # Configs in postfix order
@ -198,7 +198,7 @@ def _product_configuration(top_pcm_name, top_pcm):
_percolate_inherited(configs, pcm_name, cfg, children_names)
configs[pcm_name] = pcm, cfg, children_names, True
return globals, configs[top_pcm_name][1]
return (globals, configs[top_pcm_name][1], globals_base)
def _substitute_inherited(configs, pcm_name, cfg):
"""Substitutes inherited values in all the attributes.
@ -526,6 +526,8 @@ def _mkstrip(s):
That is, removes string's leading and trailing whitespace characters and
replaces any sequence of whitespace characters with with a single space.
"""
if type(s) != "string":
return s
result = ""
was_space = False
for ch in s.strip().elems():

View file

@ -21,15 +21,17 @@
# * all runtime functions (wildcard, regex, etc.) work
load("//build/make/core:product_config.rbc", "rblf")
load(":version_defaults.rbc", "version_defaults")
load(":device.rbc", "init")
def assert_eq(expected, actual):
if expected != actual:
fail("Expected %s, got %s" % (expected, actual))
fail("Expected '%s', got '%s'" % (expected, actual))
# Unit tests for non-trivial runtime functions
assert_eq("", rblf.mkstrip(" \n \t "))
assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
assert_eq(1, rblf.mkstrip(1))
assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
@ -50,7 +52,7 @@ assert_eq(["from/a:to/a", "from/b:to/b"], rblf.product_copy_files_by_pattern("fr
assert_eq([], rblf.filter(["a", "", "b"], "f"))
assert_eq(["", "b"], rblf.filter_out(["a", "" ], ["a", "", "b"] ))
globals, config = rblf.product_configuration("test/device", init)
(globals, config, globals_base) = rblf.product_configuration("test/device", init, version_defaults)
assert_eq(
{
"PRODUCT_COPY_FILES": [
@ -87,3 +89,6 @@ assert_eq(
},
{k:v for k, v in sorted(ns.items()) }
)
assert_eq("S", globals["PLATFORM_VERSION"])
assert_eq(30, globals["PLATFORM_SDK_VERSION"])

View file

@ -0,0 +1,11 @@
version_defaults = struct(
codenames = { "SP1A" : "S" },
default_platform_version = "SP1A",
max_platform_version = "SP1A",
min_platform_version = "SP1A",
platform_base_sdk_extension_version = 0,
platform_sdk_extension_version = 1,
platform_sdk_version = 30,
platform_security_patch = "2021-08-05",
platform_version_last_stable = 11,
)