no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / tools / lint / wpt / wpt.py
blob6f4f40492a9463e065515bc21971444559146055
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 import json
8 import os
9 import subprocess
10 import sys
12 from mozlint import result
14 results = []
17 def lint(files, config, **kwargs):
18 log = kwargs["log"]
19 tests_dir = os.path.join(kwargs["root"], "testing", "web-platform", "tests")
21 def process_line(line):
22 try:
23 data = json.loads(line)
24 except ValueError:
25 print(
26 f"Got non-JSON output: {line}",
27 file=sys.stderr,
29 return
31 data["level"] = "error"
32 data["path"] = os.path.relpath(
33 os.path.join(tests_dir, data["path"]), kwargs["root"]
35 data.setdefault("lineno", 0)
36 results.append(result.from_config(config, **data))
38 if files == [tests_dir]:
39 print(
40 "No specific files specified, running the full wpt lint" " (this is slow)",
41 file=sys.stderr,
43 files = ["--all"]
44 cmd = ["python3", os.path.join(tests_dir, "wpt"), "lint", "--json"] + files
45 log.debug("Command: {}".format(" ".join(cmd)))
47 proc = subprocess.Popen(
48 cmd, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
50 try:
51 for line in proc.stdout:
52 process_line(line.rstrip("\r\n"))
53 proc.wait()
54 if proc.returncode != 0:
55 results.append(
56 result.from_config(
57 config,
58 message="Lint process exited with return code %s" % proc.returncode,
61 except KeyboardInterrupt:
62 proc.kill()
64 return results