Bug 1410969 - Consolidate code for resolving path metadata; r?ahal
find_paths_and_tags() can instantiate a BuildReader to read moz.build
metadata. We switch `mach test` to call this to avoid some redundant
code.
To facilitate `mach try`'s use case, we add test flavors to the
result of find_paths_and_metadata() and change the function name to
reflect its more generic purpose.
MozReview-Commit-ID: Lcz05W8g2dt
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -251,30 +251,24 @@ class Test(MachCommandBase):
run_tests.extend(tests)
if not tests:
print('UNKNOWN TEST: %s' % entry, file=sys.stderr)
if not what:
from tryselect.selectors.syntax import AutoTry
at = AutoTry(self.topsrcdir, resolver, self._mach_context)
- res = at.find_paths_and_tags(False, detect_paths=True)
- if res['paths']:
- print("Tests will be run based on modifications to the "
- "following files:\n\t%s" % "\n\t".join(res['paths']))
+ res = at.find_paths_and_metadata(False, detect_paths=True)
+ paths = res['paths']
+ tags = res['tags']
+ flavors = res['flavors']
- # TODO this code is redundant with what `find_paths_and_tags` does.
- reader = self.mozbuild_reader(config_mode='empty')
- files_info = reader.files_info(res['paths'])
-
- paths, tags, flavors = set(), set(), set()
- for info in files_info.values():
- paths |= info.test_files
- tags |= info.test_tags
- flavors |= info.test_flavors
+ if paths:
+ print("Tests will be run based on modifications to the "
+ "following files:\n\t%s" % "\n\t".join(paths))
# This requires multiple calls to resolve_tests, because the test
# resolver returns tests that match every condition, while we want
# tests that match any condition. Bug 1210213 tracks implementing
# more flexible querying.
if tags:
run_tests = list(resolver.resolve_tests(tags=tags))
if paths:
--- a/tools/tryselect/selectors/syntax.py
+++ b/tools/tryselect/selectors/syntax.py
@@ -454,18 +454,18 @@ class AutoTry(object):
for e in value:
parts.append(arg)
parts.append(e)
if action in ('store_true', 'store_false'):
parts.append(arg)
return " ".join(parts)
- def find_paths_and_tags(self, verbose, detect_paths):
- paths, tags = set(), set()
+ def find_paths_and_metadata(self, verbose, detect_paths):
+ paths, tags, flavors = set(), set(), set()
changed_files = self.vcs.files_changed
if changed_files and detect_paths:
if verbose:
print("Pushing tests based on modifications to the "
"following files:\n\t%s" % "\n\t".join(changed_files))
from mozbuild.frontend.reader import (
BuildReader,
@@ -474,28 +474,30 @@ class AutoTry(object):
config = EmptyConfig(self.topsrcdir)
reader = BuildReader(config)
files_info = reader.files_info(changed_files)
for path, info in files_info.items():
paths |= info.test_files
tags |= info.test_tags
+ flavors |= info.test_flavors
if verbose:
if paths:
print("Pushing tests based on the following patterns:\n\t%s" %
"\n\t".join(paths))
if tags:
print("Pushing tests based on the following tags:\n\t%s" %
"\n\t".join(tags))
return {
'paths': paths,
'tags': tags,
+ 'flavors': flavors,
}
def normalise_list(self, items, allow_subitems=False):
rv = defaultdict(list)
for item in items:
parsed = parse_arg(item)
for key, values in parsed.iteritems():
rv[key].extend(values)
@@ -584,18 +586,18 @@ class AutoTry(object):
print("No saved configuration called %s found in autotry.ini" % kwargs["preset"],
file=sys.stderr)
for key, value in kwargs.iteritems():
if value in (None, []) and key in defaults:
kwargs[key] = defaults[key]
if not any(kwargs[item] for item in ("paths", "tests", "tags")):
- res = self.find_paths_and_tags(kwargs['verbose'],
- kwargs['detect_paths'])
+ res = self.find_paths_and_metadata(kwargs['verbose'],
+ kwargs['detect_paths'])
kwargs['paths'] = res['paths']
kwargs['tags'] = res['tags']
builds, platforms, tests, talos, jobs, paths, tags, extra = self.validate_args(**kwargs)
if paths or tags:
paths = [os.path.relpath(os.path.normpath(os.path.abspath(item)), self.topsrcdir)
for item in paths]