| OLD | NEW |
| 1 from __future__ import print_function | 1 from __future__ import print_function |
| 2 | 2 |
| 3 import argparse | 3 import argparse |
| 4 import json | 4 import json |
| 5 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 import stat | 8 import stat |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 def get_files_changed(): | 397 def get_files_changed(): |
| 398 root = os.path.abspath(os.curdir) | 398 root = os.path.abspath(os.curdir) |
| 399 git = get_git_cmd(wpt_root) | 399 git = get_git_cmd(wpt_root) |
| 400 branch_point = git("merge-base", "HEAD", "master").strip() | 400 branch_point = git("merge-base", "HEAD", "master").strip() |
| 401 logger.debug("Branch point from master: %s" % branch_point) | 401 logger.debug("Branch point from master: %s" % branch_point) |
| 402 logger.debug(git("log", "--oneline", "%s.." % branch_point)) | 402 logger.debug(git("log", "--oneline", "%s.." % branch_point)) |
| 403 files = git("diff", "--name-only", "-z", "%s.." % branch_point) | 403 files = git("diff", "--name-only", "-z", "%s.." % branch_point) |
| 404 if not files: | 404 if not files: |
| 405 return [] | 405 return [] |
| 406 assert files[-1] == "\0" | 406 assert files[-1] == "\0" |
| 407 return ["%s/%s" % (wpt_root, item) | 407 return [os.path.join(wpt_root, item) |
| 408 for item in files[:-1].split("\0")] | 408 for item in files[:-1].split("\0")] |
| 409 | 409 |
| 410 | 410 |
| 411 def get_affected_testfiles(files_changed): | 411 def get_affected_testfiles(files_changed): |
| 412 affected_testfiles = [] | 412 affected_testfiles = set() |
| 413 all_tests = set() | |
| 414 nontests_changed = set(files_changed) | 413 nontests_changed = set(files_changed) |
| 415 manifest_file = os.path.join(wpt_root, "MANIFEST.json") | 414 manifest_file = os.path.join(wpt_root, "MANIFEST.json") |
| 416 for _, test, _ in manifest.load(wpt_root, manifest_file): | 415 skip_dirs = ["conformance-checkers", "docs", "tools"] |
| 417 test_full_path = os.path.join(wpt_root, test) | 416 test_types = ["testharness", "reftest", "wdspec"] |
| 418 all_tests.add(test_full_path) | 417 |
| 419 if test_full_path in nontests_changed: | 418 wpt_manifest = manifest.load(wpt_root, manifest_file) |
| 420 # Reduce the set of changed files to only non-tests. | 419 |
| 421 nontests_changed.remove(test_full_path) | 420 support_files = {os.path.join(wpt_root, path) |
| 422 for changedfile_pathname in nontests_changed: | 421 for _, path, _ in wpt_manifest.itertypes("support")} |
| 423 changed_file_repo_path = os.path.join(os.path.sep, os.path.relpath(chang
edfile_pathname, wpt_root)) | 422 test_files = {os.path.join(wpt_root, path) |
| 424 os.path.normpath(changed_file_repo_path) | 423 for _, path, _ in wpt_manifest.itertypes(*test_types)} |
| 425 path_components = changed_file_repo_path.split(os.sep)[1:] | 424 |
| 425 nontests_changed = nontests_changed.intersection(support_files) |
| 426 |
| 427 nontest_changed_paths = set() |
| 428 for full_path in nontests_changed: |
| 429 rel_path = os.path.relpath(full_path, wpt_root) |
| 430 path_components = rel_path.split(os.sep) |
| 426 if len(path_components) < 2: | 431 if len(path_components) < 2: |
| 427 # This changed file is in the repo root, so skip it | 432 # This changed file is in the repo root, so skip it |
| 428 # (because it's not part of any test). | 433 # (because it's not part of any test). |
| 429 continue | 434 continue |
| 430 top_level_subdir = path_components[0] | 435 top_level_subdir = path_components[0] |
| 431 if top_level_subdir in ["conformance-checkers", "docs"]: | 436 if top_level_subdir in skip_dirs: |
| 432 continue | 437 continue |
| 433 # OK, this changed file is the kind we care about: It's something | 438 repo_path = "/" + os.path.relpath(full_path, wpt_root).replace(os.path.s
ep, "/") |
| 434 # other than a test (e.g., it's a .js or .json file), and it's | 439 nontest_changed_paths.add((full_path, repo_path)) |
| 435 # somewhere down beneath one of the top-level "spec" directories. | 440 |
| 436 # So now we try to find any tests that reference it. | 441 for root, dirs, fnames in os.walk(wpt_root): |
| 437 for root, dirs, fnames in os.walk(os.path.join(wpt_root, top_level_subdi
r)): | 442 # Walk top_level_subdir looking for test files containing either the |
| 438 # Walk top_level_subdir looking for test files containing either the | 443 # relative filepath or absolute filepatch to the changed files. |
| 439 # relative filepath or absolute filepatch to the changed file. | 444 if root == wpt_root: |
| 440 for fname in fnames: | 445 for dir_name in skip_dirs: |
| 441 testfile_full_path = os.path.join(root, fname) | 446 dirs.remove(dir_name) |
| 442 # Skip any test file that's already in files_changed. | 447 for fname in fnames: |
| 443 if testfile_full_path in files_changed: | 448 test_full_path = os.path.join(root, fname) |
| 444 continue | 449 # Skip any file that's not a test file. |
| 445 # Skip any file that's not a test file. | 450 if test_full_path not in test_files: |
| 446 if testfile_full_path not in all_tests: | 451 continue |
| 447 continue | 452 with open(test_full_path, "rb") as fh: |
| 448 with open(testfile_full_path, "r") as fh: | 453 file_contents = fh.read() |
| 449 file_contents = fh.read() | 454 if file_contents.startswith("\xfe\xff"): |
| 450 changed_file_relpath = os.path.relpath(changedfile_pathname,
root).replace(os.path.sep, "/") | 455 file_contents = file_contents.decode("utf-16be") |
| 451 if changed_file_relpath in file_contents or changed_file_rep
o_path.replace(os.path.sep, "/") in file_contents: | 456 elif file_contents.startswith("\xff\xfe"): |
| 452 affected_testfiles.append(testfile_full_path) | 457 file_contents = file_contents.decode("utf-16le") |
| 458 for full_path, repo_path in nontest_changed_paths: |
| 459 rel_path = os.path.relpath(full_path, root).replace(os.path.
sep, "/") |
| 460 if rel_path in file_contents or repo_path in file_contents: |
| 461 affected_testfiles.add(test_full_path) |
| 462 continue |
| 453 return affected_testfiles | 463 return affected_testfiles |
| 454 | 464 |
| 455 | 465 |
| 456 def wptrunner_args(root, files_changed, iterations, browser): | 466 def wptrunner_args(root, files_changed, iterations, browser): |
| 457 parser = wptcommandline.create_parser([browser.product]) | 467 parser = wptcommandline.create_parser([browser.product]) |
| 458 args = vars(parser.parse_args([])) | 468 args = vars(parser.parse_args([])) |
| 459 args.update(browser.wptrunner_args(root)) | 469 args.update(browser.wptrunner_args(root)) |
| 460 args.update({ | 470 args.update({ |
| 461 "tests_root": wpt_root, | 471 "tests_root": wpt_root, |
| 462 "metadata_root": wpt_root, | 472 "metadata_root": wpt_root, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 return retcode | 744 return retcode |
| 735 | 745 |
| 736 | 746 |
| 737 if __name__ == "__main__": | 747 if __name__ == "__main__": |
| 738 try: | 748 try: |
| 739 retcode = main() | 749 retcode = main() |
| 740 except: | 750 except: |
| 741 raise | 751 raise |
| 742 else: | 752 else: |
| 743 sys.exit(retcode) | 753 sys.exit(retcode) |
| OLD | NEW |