Skip to content

Commit

Permalink
Merge "Add mksubst" am: cfaa04b am: d976d4c
Browse files Browse the repository at this point in the history
Original change: https://android-review.googlesource.com/c/platform/build/+/1760830

Change-Id: Ibff9759cca42d31b46ff92065908650db138062a
  • Loading branch information
Treehugger Robot authored and android-build-merge-worker-robot committed Jul 12, 2021
2 parents 5560bd4 + d976d4c commit a752950
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/product_config.rbc
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,17 @@ def _mkstrip(s):
was_space = is_space
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():
"""Returns struct containing runtime global settings."""
settings = dict(
Expand Down Expand Up @@ -498,6 +509,7 @@ rblf = struct(
mkerror = _mkerror,
mkwarning = _mkwarning,
mkstrip = _mkstrip,
mksubst = _mksubst,
printvars = _printvars,
product_configuration = _product_configuration,
require_artifacts_in_path = _require_artifacts_in_path,
Expand Down
3 changes: 3 additions & 0 deletions tests/run.rbc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def assert_eq(expected, actual):
assert_eq("", rblf.mkstrip(" \n \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)
assert_eq(
{
Expand Down

0 comments on commit a752950

Please sign in to comment.