Bug 1138579 - Support multiple Files patterns in moz.build r=gps

Add support for |with Files('a/**', 'b/**')| in mozbuild config files.

MozReview-Commit-ID: IoM4qfEhXXc

Differential Revision: https://phabricator.services.mozilla.com/D5315

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Campbell 2018-09-20 01:58:21 +00:00
parent 8d7c2999dc
commit 388abb1424
4 changed files with 40 additions and 20 deletions

View File

@ -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)):

View File

@ -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()

View File

@ -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]):

View File

@ -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()