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