diff --git a/config/tests/test_mozbuild_reading.py b/config/tests/test_mozbuild_reading.py index f555518aa6f3..b95d3e3fc296 100644 --- a/config/tests/test_mozbuild_reading.py +++ b/config/tests/test_mozbuild_reading.py @@ -97,11 +97,12 @@ class TestMozbuildReading(unittest.TestCase): if not isinstance(ctx, Files): continue relsrcdir = ctx.relsrcdir - if not pattern_exists(os.path.join(relsrcdir, ctx.pattern)): - self.fail("The pattern '%s' in a Files() entry in " - "'%s' corresponds to no files in the tree.\n" - "Please update this entry." % - (ctx.pattern, ctx.main_path)) + for p in ctx.patterns: + if not pattern_exists(os.path.join(relsrcdir, p)): + self.fail("The pattern '%s' in a Files() entry in " + "'%s' corresponds to no files in the tree.\n" + "Please update this entry." % + (p, ctx.main_path)) test_files = ctx['IMPACTED_TESTS'].files for p in test_files: if not pattern_exists(os.path.relpath(p.full_path, config.topsrcdir)): diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index 76109447c89a..2d0c216ad0c7 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -1069,9 +1069,9 @@ class Files(SubContext): """), } - def __init__(self, parent, pattern=None): + def __init__(self, parent, *patterns): super(Files, self).__init__(parent) - self.pattern = pattern + self.patterns = patterns self.finalized = set() self.test_files = set() self.test_tags = set() diff --git a/python/mozbuild/mozbuild/frontend/reader.py b/python/mozbuild/mozbuild/frontend/reader.py index 147a38a3d1ec..c355802fccb6 100644 --- a/python/mozbuild/mozbuild/frontend/reader.py +++ b/python/mozbuild/mozbuild/frontend/reader.py @@ -1342,6 +1342,15 @@ class BuildReader(object): r = {} + # Only do wildcard matching if the '*' character is present. + # Otherwise, mozpath.match will match directories, which we've + # arbitrarily chosen to not allow. + def path_matches_pattern(relpath, pattern): + if pattern == relpath: + return True + + return '*' in pattern and mozpath.match(relpath, pattern) + for path, ctxs in paths.items(): # Should be normalized by read_relevant_mozbuilds. assert '\\' not in path @@ -1364,13 +1373,7 @@ class BuildReader(object): else: relpath = path - pattern = ctx.pattern - - # Only do wildcard matching if the '*' character is present. - # Otherwise, mozpath.match will match directories, which we've - # arbitrarily chosen to not allow. - if pattern == relpath or \ - ('*' in pattern and mozpath.match(relpath, pattern)): + if any(path_matches_pattern(relpath, p) for p in ctx.patterns): flags += ctx if not any([flags.test_tags, flags.test_files, flags.test_flavors]): diff --git a/python/mozbuild/mozbuild/test/frontend/test_context.py b/python/mozbuild/mozbuild/test/frontend/test_context.py index 070cfad67082..dcb1b65bdabb 100644 --- a/python/mozbuild/mozbuild/test/frontend/test_context.py +++ b/python/mozbuild/mozbuild/test/frontend/test_context.py @@ -663,7 +663,7 @@ class TestFiles(unittest.TestCase): def test_aggregate_empty(self): c = Context({}) - files = {'moz.build': Files(c, pattern='**')} + files = {'moz.build': Files(c, '**')} self.assertEqual(Files.aggregate(files), { 'bug_component_counts': [], @@ -672,7 +672,7 @@ class TestFiles(unittest.TestCase): def test_single_bug_component(self): c = Context({}) - f = Files(c, pattern='**') + f = Files(c, '**') f['BUG_COMPONENT'] = (u'Product1', u'Component1') files = {'moz.build': f} @@ -683,10 +683,10 @@ class TestFiles(unittest.TestCase): def test_multiple_bug_components(self): c = Context({}) - f1 = Files(c, pattern='**') + f1 = Files(c, '**') f1['BUG_COMPONENT'] = (u'Product1', u'Component1') - f2 = Files(c, pattern='**') + f2 = Files(c, '**') f2['BUG_COMPONENT'] = (u'Product2', u'Component2') files = {'a': f1, 'b': f2, 'c': f1} @@ -701,10 +701,10 @@ class TestFiles(unittest.TestCase): def test_no_recommended_bug_component(self): """If there is no clear count winner, we don't recommend a bug component.""" c = Context({}) - f1 = Files(c, pattern='**') + f1 = Files(c, '**') f1['BUG_COMPONENT'] = (u'Product1', u'Component1') - f2 = Files(c, pattern='**') + f2 = Files(c, '**') f2['BUG_COMPONENT'] = (u'Product2', u'Component2') files = {'a': f1, 'b': f2} @@ -716,6 +716,22 @@ class TestFiles(unittest.TestCase): 'recommended_bug_component': None, }) + def test_multiple_patterns(self): + c = Context({}) + f1 = Files(c, 'a/**') + f1['BUG_COMPONENT'] = (u'Product1', u'Component1') + f2 = Files(c, 'b/**', 'a/bar') + f2['BUG_COMPONENT'] = (u'Product2', u'Component2') + + files = {'a/foo': f1, 'a/bar' : f2, 'b/foo' : f2 } + self.assertEqual(Files.aggregate(files), { + 'bug_component_counts': [ + ((u'Product2', u'Component2'), 2), + ((u'Product1', u'Component1'), 1), + ], + 'recommended_bug_component': (u'Product2', u'Component2'), + }) + if __name__ == '__main__': main()