tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

update_built.py (3128B)


      1 # mypy: allow-untyped-defs
      2 
      3 import logging
      4 import os
      5 import subprocess
      6 from argparse import ArgumentParser
      7 
      8 logger = logging.getLogger()
      9 
     10 wpt_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
     11 
     12 # These paths should be kept in sync with job_path_map in jobs.py.
     13 scripts = {
     14    "canvas": ["html/canvas/tools/gentest.py"],
     15    "conformance-checkers": ["conformance-checkers/tools/dl.py",
     16                             "conformance-checkers/tools/ins-del-datetime.py",
     17                             "conformance-checkers/tools/picture.py",
     18                             "conformance-checkers/tools/url.py"],
     19    "css-images": ["css/css-images/tools/generate_object_view_box_tests.py"],
     20    "css-ui": ["css/css-ui/tools/appearance-build-webkit-reftests.py"],
     21    "css-writing-modes": ["css/css-writing-modes/tools/generators/generate.py"],
     22    # FIXME: https://github.com/web-platform-tests/wpt/issues/32060
     23    # "css-text": ["css/css-text/line-breaking/tools/generate-segment-break-transformation-rules-tests.py"],
     24    # "css-text-decor": ["css/css-text-decor/tools/generate-text-emphasis-line-height-tests.py",
     25    #                    "css/css-text-decor/tools/generate-text-emphasis-position-property-tests.py",
     26    #                    "css/css-text-decor/tools/generate-text-emphasis-ruby-tests.py",
     27    #                    "css/css-text-decor/tools/generate-text-emphasis-style-property-tests.py"],
     28    "fetch": ["fetch/metadata/tools/generate.py"],
     29    "html5lib": ["html/tools/update_html5lib_tests.py"],
     30    "infrastructure": ["infrastructure/assumptions/tools/ahem-generate-table.py"],
     31    "mimesniff": ["mimesniff/mime-types/resources/generated-mime-types.py"],
     32    "speculative-parsing": ["html/syntax/speculative-parsing/tools/generate.py"]
     33 }
     34 
     35 
     36 def get_parser():
     37    parser = ArgumentParser()
     38    parser.add_argument("--list", action="store_true",
     39                        help="List suites that can be updated and the related script files")
     40    parser.add_argument("--include", nargs="*", choices=scripts.keys(),
     41                        help="Suites to update (default is to update everything)")
     42    return parser
     43 
     44 
     45 def list_suites(include):
     46    for name, script_paths in scripts.items():
     47        if name in include:
     48            print(name)
     49            for script_path in script_paths:
     50                print(f"    {script_path}")
     51 
     52 
     53 def run(venv, **kwargs):
     54    include = kwargs["include"]
     55    if include is None:
     56        include = list(scripts.keys())
     57 
     58    if kwargs["list"]:
     59        list_suites(include)
     60        return 0
     61 
     62    failed = False
     63 
     64    for target in include:
     65        for script in scripts[target]:
     66            script_path = script.replace("/", os.path.sep)
     67            cmd = [os.path.join(venv.bin_path, "python3"), os.path.join(wpt_root, script_path)]
     68            logger.info(f"Running {' '.join(cmd)}")
     69            try:
     70                subprocess.check_call(cmd, cwd=os.path.dirname(script_path))
     71            except subprocess.CalledProcessError:
     72                logger.error(f"Update script {script} failed")
     73                failed = True
     74 
     75    return 1 if failed else 0