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
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.
89 taskcluster-build-image
90 taskcluster-load-image
92 telemetry-tests-client
106 web-platform-tests-update
121 # Try to run a specific Python interpreter. Fall back to the system
122 # default Python if the specific interpreter couldn't be found.
125 if which "$py_executable" > /dev
/null
127 exec "$py_executable" "$0" "$@"
128 elif [ "$py_executable" = "python2.7" ]; then
129 exec python
"$0" "$@"
131 echo "This mach command requires $py_executable, which wasn't found on the system!"
137 if [ "$first_arg" = "help" ]; then
138 # When running `./mach help <command>`, the correct Python for <command>
143 if [ -z "$first_arg" ]; then
144 # User ran `./mach` or `./mach help`, use Python 3.
148 case "${first_arg}" in
150 # We have global arguments which are tricky to parse from this shell
151 # script. So invoke `mach` with a special --print-command argument to
152 # return the name of the command. This adds extra overhead when using
153 # global arguments, but global arguments are an edge case and this hack
154 # is only needed temporarily for the Python 3 migration. We use Python
155 # 2.7 because using Python 3 hits this error in build tasks:
156 # https://searchfox.org/mozilla-central/rev/c7e8bc4996f9/build/moz.configure/init.configure#319
157 command=`run_py python2.7 --print-command "$@" | tail -n1`
160 # In the common case, the first argument is the command.
161 command=${first_arg};
165 # Check for the mach subcommand in the Python 2 commands list and run it
166 # with the correct interpreter.
167 case " $(echo $py2commands) " in
169 run_py python2.7
"$@"
176 # Run Python 3 for everything else.
180 from __future__ import absolute_import, print_function, unicode_literals
188 (path, child) = os.path.split(path)
192 def load_mach(dir_path, mach_path):
193 if sys.version_info < (3, 5):
195 mach_bootstrap = imp.load_source('mach_bootstrap
', mach_path)
197 import importlib.util
198 spec = importlib.util.spec_from_file_location('mach_bootstrap
', mach_path)
199 mach_bootstrap = importlib.util.module_from_spec(spec)
200 spec.loader.exec_module(mach_bootstrap)
202 return mach_bootstrap.bootstrap(dir_path)
205 def check_and_get_mach(dir_path):
207 'build
/mach_bootstrap.py
',
208 # test package bootstrap
209 'tools
/mach_bootstrap.py
',
211 for bootstrap_path in bootstrap_paths:
212 mach_path = os.path.join(dir_path, bootstrap_path)
213 if os.path.isfile(mach_path):
214 return load_mach(dir_path, mach_path)
219 # Check whether the current directory is within a mach src or obj dir.
220 for dir_path in ancestors(os.getcwd()):
221 # If we find a "config.status" and "mozinfo.json" file, we are in the objdir.
222 config_status_path = os.path.join(dir_path, 'config.status
')
223 mozinfo_path = os.path.join(dir_path, 'mozinfo.json
')
224 if os.path.isfile(config_status_path) and os.path.isfile(mozinfo_path):
226 info = json.load(open(mozinfo_path))
227 if 'mozconfig
' in info and 'MOZCONFIG
' not in os.environ:
228 # If the MOZCONFIG environment variable is not already set, set it
229 # to the value from mozinfo.json. This will tell the build system
230 # to look for a config file at the path in $MOZCONFIG rather than
231 # its default locations.
233 # Note: subprocess requires native strings in os.environ on Windows
234 os.environ[b'MOZCONFIG
'] = str(info['mozconfig
'])
236 if 'topsrcdir
' in info:
237 # Continue searching for mach_bootstrap in the source directory.
238 dir_path = info['topsrcdir
']
240 mach = check_and_get_mach(dir_path)
244 # If we didn't
find a
source path by scanning
for a mozinfo.json
, check
245 # whether the directory containing this script is a source directory. We
246 # follow symlinks so mach can be run even if cwd is outside the srcdir.
247 return check_and_get_mach
(os.path.
dirname(os.path.realpath
(__file__
)))
252 print
('Could not run mach: No mach source directory found.')
254 sys.
exit(mach.run
(args
))
257 if __name__
== '__main__':