From 4db91af70c08e069de7f108125e908db92d08170 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Mon, 13 Dec 2021 16:35:01 -0800 Subject: [PATCH] Create $(findstring) starlark implementation Bug: 201700692 Test: go test in other cl in the topic Change-Id: Ibe7d600c9fe5335a1277e1572aa52f6c512c2951 --- core/product_config.rbc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/product_config.rbc b/core/product_config.rbc index f26b428cd3..d47cdc0e43 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -476,6 +476,12 @@ def _find_and_copy(pattern, from_dir, to_dir): return sorted(["%s/%s:%s/%s" % ( from_dir, f, to_dir, f) for f in rblf_find_files(from_dir, pattern, only_files=1)]) +def _findstring(needle, haystack): + """Equivalent to GNU make's $(findstring).""" + if haystack.find(needle) < 0: + return "" + return needle + def _filter_out(pattern, text): """Return all the words from `text' that do not match any word in `pattern'. @@ -727,6 +733,7 @@ rblf = struct( filter = _filter, filter_out = _filter_out, find_and_copy = _find_and_copy, + findstring = _findstring, inherit = _inherit, indirect = _indirect, mk2rbc_error = _mk2rbc_error,