Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / tools / lint / hooks.py
blob92f8565bf7a3efedbffc287579c90863b0a2da39
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 import os
7 import shutil
8 import signal
9 import subprocess
10 import sys
12 here = os.path.dirname(os.path.realpath(__file__))
13 topsrcdir = os.path.join(here, os.pardir, os.pardir)
16 def run_process(cmd):
17 proc = subprocess.Popen(cmd)
19 # ignore SIGINT, the mozlint subprocess should exit quickly and gracefully
20 orig_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
21 proc.wait()
22 signal.signal(signal.SIGINT, orig_handler)
23 return proc.returncode
26 def run_mozlint(hooktype, args):
27 if isinstance(hooktype, bytes):
28 hooktype = hooktype.decode("UTF-8", "replace")
30 python = shutil.which("python3")
31 if not python:
32 print("error: Python 3 not detected on your system! Please install it.")
33 sys.exit(1)
35 cmd = [python, os.path.join(topsrcdir, "mach"), "lint"]
37 if "commit" in hooktype:
38 # don't prevent commits, just display the lint results
39 run_process(cmd + ["--workdir=staged"])
40 return False
41 elif "push" in hooktype:
42 return run_process(cmd + ["--outgoing"] + args)
44 print("warning: '{}' is not a valid mozlint hooktype".format(hooktype))
45 return False
48 def hg(ui, repo, **kwargs):
49 hooktype = kwargs["hooktype"]
50 return run_mozlint(hooktype, kwargs.get("pats", []))
53 def git():
54 hooktype = os.path.basename(__file__)
55 if hooktype == "hooks.py":
56 hooktype = "pre-push"
57 return run_mozlint(hooktype, [])
60 if __name__ == "__main__":
61 sys.exit(git())