From f8b4d273d3df3adce27c788f8ee7c58d776f5921 Mon Sep 17 00:00:00 2001 From: Jonathan Bedard Date: Fri, 7 Oct 2022 18:26:13 -0700 Subject: [PATCH] [run-webkit-tests] Support user specifying variant directly https://bugs.webkit.org/show_bug.cgi?id=246228 rdar://100907445 Reviewed by Elliott Williams. * Tools/Scripts/webkitpy/common/find_files.py: (_normalized_find): Consider variants of a single test file. (_normalized_find.sorted_paths_generator): * Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy.py: (LayoutTestFinder._expand_variants): Handle specific variant as argument. * Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy_unittest.py: (LayoutTestFinderTests.test_find_glob_query): Canonical link: https://commits.webkit.org/255305@main --- Tools/Scripts/webkitpy/common/find_files.py | 26 ++++++++++++------- .../controllers/layout_test_finder_legacy.py | 4 ++- .../layout_test_finder_legacy_unittest.py | 5 ++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Tools/Scripts/webkitpy/common/find_files.py b/Tools/Scripts/webkitpy/common/find_files.py index 7bffd1da5a13..66e646fbaf6e 100644 --- a/Tools/Scripts/webkitpy/common/find_files.py +++ b/Tools/Scripts/webkitpy/common/find_files.py @@ -73,13 +73,21 @@ def _normalized_find(filesystem, paths, skipped_directories, file_filter, direct Glob patterns are ok. """ - def sort_by_directory_key(files_list): - if not directory_sort_key: - return files_list[:] - - return sorted(files_list, key=directory_sort_key) - - paths_to_walk = itertools.chain(*(sort_by_directory_key(filesystem.glob(path)) for path in paths)) - - all_files = itertools.chain(*(sort_by_directory_key(filesystem.files_under(path, skipped_directories, file_filter)) for path in paths_to_walk)) + sort_fn = (lambda lst: sorted(lst, key=directory_sort_key)) if directory_sort_key else (lambda lst: lst[:]) + + def sorted_paths_generator(path, function): + base_path, separator, variant = path.partition('?') + if not separator: + return sort_fn(function(base_path)) + # This isn't perfect, you won't be able glob the variant parts of the test name, + # but this is ultimately a design flaw stemming from a layout test not being a file + result = ['{}{}{}'.format(part, separator, variant) for part in function(base_path)] + if result: + return sort_fn(result) + return sort_fn(function(path)) + + paths_to_walk = itertools.chain(*(sorted_paths_generator(path, filesystem.glob) for path in paths)) + all_files = itertools.chain(*(sorted_paths_generator( + path, lambda p: filesystem.files_under(p, skipped_directories, file_filter), + ) for path in paths_to_walk)) return all_files diff --git a/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy.py b/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy.py index c404436ce1b3..00734e8f8a35 100644 --- a/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy.py +++ b/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy.py @@ -148,6 +148,7 @@ def _expand_variants(self, files): if ".any." not in f: expanded.append(f) continue + f, variant_separator, passed_variant = f.partition('?') opened_file = fs.open_text_file_for_reading(f) try: first_line = opened_file.readline() @@ -164,7 +165,8 @@ def _expand_variants(self, files): variants.append(variant) if variants: for variant in variants: - expanded.append(f + variant) + if not passed_variant or variant.startswith(variant_separator + passed_variant): + expanded.append(f + variant) else: expanded.append(f) except UnicodeDecodeError: diff --git a/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy_unittest.py b/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy_unittest.py index 773b9059f9df..46bee59d803a 100644 --- a/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy_unittest.py +++ b/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_finder_legacy_unittest.py @@ -197,6 +197,11 @@ def test_find_glob_c(self): tests = [t.test_path for t in finder.find_tests_by_path(['failures/expected/i[m]age.html'])] self.assertEqual(tests, ['failures/expected/image.html']) + def test_find_glob_query(self): + finder = self.finder + tests = [t.test_path for t in finder.find_tests_by_path(['failures/expected/image.html?variant'])] + self.assertEqual(tests, ['failures/expected/image.html?variant']) + def test_find_glob_mixed_file_type_sorted(self): finder = self.finder # this should expand the *, sort the result, then recurse;