If filter/filter_out pattern is a list, remove empty elements from it.

Also, fix __mk2regex bug: the returned pattern should end with $.
Bug: 193540681
Test: internal
Change-Id: Ia56856826c6b05ccf857ae5ab7a70609bf4f1e1d

Change-Id: Ie2a9bf62ee48824ce7cd5fe9e9ec2f55311473e3
This commit is contained in:
Sasha Smundak
2021-08-26 09:42:55 -07:00
parent ee20ae1a8d
commit f00e35ecae
2 changed files with 4 additions and 1 deletions

View File

@@ -439,7 +439,7 @@ def __mk2regex(words):
"""Returns regular expression equivalent to Make pattern."""
# TODO(asmundak): this will mishandle '\%'
return "^(" + "|".join([w.replace("%", ".*", 1) for w in words]) + ")"
return "^(" + "|".join([w.replace("%", ".*", 1) for w in words if w]) + ")$"
def _regex_match(regex, w):
return rblf_regex(regex, w)

View File

@@ -47,6 +47,9 @@ assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
assert_eq(["from/a:to/a", "from/b:to/b"], rblf.product_copy_files_by_pattern("from/%", "to/%", "a b"))
assert_eq([], rblf.filter(["a", "", "b"], "f"))
assert_eq(["", "b"], rblf.filter_out(["a", "" ], ["a", "", "b"] ))
globals, config = rblf.product_configuration("test/device", init)
assert_eq(
{