Bug 1616239 - Enable http3 tests for asan, r=necko-reviewers,dragana
[gecko.git] / mach
blobfeb0ac6184871e49a58b4ffc8dea644e492ece3a
1 #!/bin/sh
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 # The beginning of this script is both valid POSIX shell and valid Python,
7 # such that the script starts with the shell and is reexecuted with
8 # the right Python.
10 # Embeds a shell script inside a Python triple quote. This pattern is valid
11 # shell because `''':'`, `':'` and `:` are all equivalent, and `:` is a no-op.
12 ''':'
14 # Commands that are to be run with the system Python 3 instead of the
15 # virtualenv.
16 nativecmds="
17 bootstrap
18 create-mach-environment
19 install-moz-phab
22 run_py() {
23 # Try to run a specific Python interpreter.
24 py_executable="$1"
25 shift
26 if command -v "$py_executable" > /dev/null
27 then
28 exec "$py_executable" "$0" "$@"
29 else
30 echo "This mach command requires $py_executable, which wasn't found on the system!"
31 case "$py_executable" in
32 python3) ;;
34 echo "Consider running 'mach bootstrap' or 'mach create-mach-environment' to create the mach virtualenvs, or set MACH_USE_SYSTEM_PYTHON to use the system Python installation over a virtualenv."
36 esac
37 exit 1
41 get_command() {
42 # Parse the name of the mach command out of the arguments. This is necessary
43 # in the presence of global mach arguments that come before the name of the
44 # command, e.g. `mach -v build`. We dispatch to the correct Python
45 # interpreter depending on the command.
46 while true; do
47 case $1 in
48 -v|--verbose) shift;;
49 -l|--log-file)
50 if [ "$#" -lt 2 ]
51 then
52 echo
53 break
54 else
55 shift 2
58 --no-interactive) shift;;
59 --log-interval) shift;;
60 --log-no-times) shift;;
61 -h) shift;;
62 --debug-command) shift;;
63 --settings)
64 if [ "$#" -lt 2 ]
65 then
66 echo
67 break
68 else
69 shift 2
72 "") echo; break;;
73 *) echo $1; break;;
74 esac
75 done
78 state_dir=${MOZBUILD_STATE_PATH:-~/.mozbuild}
79 command=$(get_command "$@")
81 # If MACH_USE_SYSTEM_PYTHON or MOZ_AUTOMATION are set, always use the
82 # python 3 executables and not the virtualenv locations.
83 if [ -z ${MACH_USE_SYSTEM_PYTHON} ] && [ -z ${MOZ_AUTOMATION} ]
84 then
85 case "$OSTYPE" in
86 cygwin|msys|win32) bin_path=Scripts;;
87 *) bin_path=bin;;
88 esac
89 py3executable=$state_dir/_virtualenvs/mach/$bin_path/python
90 else
91 py3executable=python3
94 # Check whether we need to run with the native Python 3 interpreter.
95 case " $(echo $nativecmds) " in
96 *\ $command\ *)
97 run_py python3 "$@"
99 esac
101 # # Use the mach virtualenv's Python 3 for the rest of the commands.
102 run_py "$py3executable" "$@"
105 from __future__ import absolute_import, print_function, unicode_literals
107 import os
108 import sys
110 def load_mach(dir_path, mach_path):
111 if sys.version_info < (3, 5):
112 import imp
113 mach_bootstrap = imp.load_source('mach_bootstrap', mach_path)
114 else:
115 import importlib.util
116 spec = importlib.util.spec_from_file_location('mach_bootstrap', mach_path)
117 mach_bootstrap = importlib.util.module_from_spec(spec)
118 spec.loader.exec_module(mach_bootstrap)
120 return mach_bootstrap.bootstrap(dir_path)
123 def check_and_get_mach(dir_path):
124 bootstrap_paths = (
125 'build/mach_bootstrap.py',
126 # test package bootstrap
127 'tools/mach_bootstrap.py',
129 for bootstrap_path in bootstrap_paths:
130 mach_path = os.path.join(dir_path, bootstrap_path)
131 if os.path.isfile(mach_path):
132 return load_mach(dir_path, mach_path)
133 return None
136 def main(args):
137 # XCode python sets __PYVENV_LAUNCHER__, which overrides the executable
138 # used when a python subprocess is created. This is an issue when we want
139 # to run using our virtualenv python executables.
140 # In future Python relases, __PYVENV_LAUNCHER__ will be cleared before
141 # application code (mach) is started.
142 # https://github.com/python/cpython/pull/9516
143 os.environ.pop("__PYVENV_LAUNCHER__", None)
145 mach = check_and_get_mach(os.path.dirname(os.path.realpath(__file__)))
146 if not mach:
147 print('Could not run mach: No mach source directory found.')
148 sys.exit(1)
149 sys.exit(mach.run(args))
152 if __name__ == '__main__':
153 main(sys.argv[1:])