Add mksubst
Bug: 181797530 Test: rbcrun build/make/tests/run.rbc Change-Id: I196c69259b830b6466430f6c933afb49fa787948
This commit is contained in:
@@ -450,6 +450,17 @@ def _mkstrip(s):
|
|||||||
was_space = is_space
|
was_space = is_space
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _mksubst(old, new, s):
|
||||||
|
"""Emulates Make's subst.
|
||||||
|
|
||||||
|
Replaces each occurence of 'old' with 'new'.
|
||||||
|
If 's' is a list, applies substitution to each item.
|
||||||
|
"""
|
||||||
|
if type(s) == "list":
|
||||||
|
return [e.replace(old, new) for e in s]
|
||||||
|
return s.replace(old, new)
|
||||||
|
|
||||||
|
|
||||||
def __get_options():
|
def __get_options():
|
||||||
"""Returns struct containing runtime global settings."""
|
"""Returns struct containing runtime global settings."""
|
||||||
settings = dict(
|
settings = dict(
|
||||||
@@ -498,6 +509,7 @@ rblf = struct(
|
|||||||
mkerror = _mkerror,
|
mkerror = _mkerror,
|
||||||
mkwarning = _mkwarning,
|
mkwarning = _mkwarning,
|
||||||
mkstrip = _mkstrip,
|
mkstrip = _mkstrip,
|
||||||
|
mksubst = _mksubst,
|
||||||
printvars = _printvars,
|
printvars = _printvars,
|
||||||
product_configuration = _product_configuration,
|
product_configuration = _product_configuration,
|
||||||
require_artifacts_in_path = _require_artifacts_in_path,
|
require_artifacts_in_path = _require_artifacts_in_path,
|
||||||
|
@@ -31,6 +31,9 @@ def assert_eq(expected, actual):
|
|||||||
assert_eq("", rblf.mkstrip(" \n \t "))
|
assert_eq("", rblf.mkstrip(" \n \t "))
|
||||||
assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
|
assert_eq("a b c", rblf.mkstrip(" a b \n c \t"))
|
||||||
|
|
||||||
|
assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
|
||||||
|
assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
|
||||||
|
|
||||||
globals, config = rblf.product_configuration("test/device", init)
|
globals, config = rblf.product_configuration("test/device", init)
|
||||||
assert_eq(
|
assert_eq(
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user