Bug 1799258 - Support outByIn.size()<2 in SampleOutByIn. r=bradwerth
[gecko.git] / mach
blob5811a8fd6e6c9d624e9d48b3bb2cfacc0b25c0dd
1 #!/usr/bin/env python3
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 platform
8 import sys
9 from textwrap import dedent
12 def load_mach(dir_path, mach_path):
13     # Defer import of "importlib.util" until after Python version check has happened
14     # so that Python 2 usages fail gracefully.
15     import importlib.util
16     spec = importlib.util.spec_from_file_location('mach_initialize', mach_path)
17     mach_initialize = importlib.util.module_from_spec(spec)
18     spec.loader.exec_module(mach_initialize)
19     return mach_initialize.initialize(dir_path)
22 def check_and_get_mach(dir_path):
23     initialize_paths = (
24         # Run Thunderbird's mach_initialize.py if it exists
25         'comm/build/mach_initialize.py',
26         'build/mach_initialize.py',
27         # test package initialize
28         'tools/mach_initialize.py',
29     )
30     for initialize_path in initialize_paths:
31         mach_path = os.path.join(dir_path, initialize_path)
32         if os.path.isfile(mach_path):
33             return load_mach(dir_path, mach_path)
34     return None
37 def main(args):
38     # Ensure we are running Python 3.6+. We run this check as soon as
39     # possible to avoid a cryptic import/usage error.
40     if sys.version_info < (3, 6):
41         print("Python 3.6+ is required to run mach.")
42         print("You are running Python", platform.python_version())
43         if sys.platform.startswith("linux"):
44             print(dedent("""
45             See https://firefox-source-docs.mozilla.org/setup/linux_build.html#installingpython
46             for guidance on how to install Python on your system.
47             """).strip())
48         elif sys.platform.startswith("darwin"):
49             print(dedent("""
50             See https://firefox-source-docs.mozilla.org/setup/macos_build.html
51             for guidance on how to prepare your system to build Firefox. Perhaps
52             you need to update Xcode, or install Python using brew?
53             """).strip())
54         elif "MOZILLABUILD" in os.environ and os.environ.get("TERM"):
55             print(dedent("""
56             Python is provided by MozillaBuild; ensure your MozillaBuild installation is
57             up to date. See https://firefox-source-docs.mozilla.org/setup/windows_build.html#install-mozillabuild
58             for details.
59             """).strip())
60         elif sys.platform.startswith("win"):
61             print(dedent("""
62             You probably want to be interacting with Mach from within MozillaBuild, see
63             https://firefox-source-docs.mozilla.org/setup/windows_build.html for details.
64             
65             If you are deliberately using Mach from outside MozillaBuild, then see
66             https://firefox-source-docs.mozilla.org/mach/windows-usage-outside-mozillabuild.html#install-python
67             for guidance on installing native Python on your system.
68             """).strip())
69         else:
70             print(dedent("""
71             We do not have specific instructions for your platform on how to
72             install Python. You may find Pyenv (https://github.com/pyenv/pyenv)
73             helpful, if your system package manager does not provide a way to
74             install a recent enough Python 3.
75             """).strip())
76         sys.exit(1)
78     # XCode python sets __PYVENV_LAUNCHER__, which overrides the executable
79     # used when a python subprocess is created. This is an issue when we want
80     # to run using our virtualenv python executables.
81     # In future Python relases, __PYVENV_LAUNCHER__ will be cleared before
82     # application code (mach) is started.
83     # https://github.com/python/cpython/pull/9516
84     os.environ.pop("__PYVENV_LAUNCHER__", None)
86     mach = check_and_get_mach(os.path.dirname(os.path.realpath(__file__)))
87     if not mach:
88         print('Could not run mach: No mach source directory found.')
89         sys.exit(1)
90     sys.exit(mach.run(args))
93 if __name__ == '__main__':
94     main(sys.argv[1:])