2014-05-21 06:27:30 +04:00
|
|
|
#!/bin/sh
|
2013-04-04 18:42:28 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-08-27 06:08:08 +03:00
|
|
|
# The beginning of this script is both valid POSIX shell and valid Python,
|
2014-05-21 06:27:30 +04:00
|
|
|
# such that the script starts with the shell and is reexecuted with
|
2019-08-27 06:08:08 +03:00
|
|
|
# the right Python.
|
|
|
|
|
|
|
|
# Embeds a shell script inside a Python triple quote. This pattern is valid
|
|
|
|
# shell because `''':'`, `':'` and `:` are all equivalent, and `:` is a no-op.
|
|
|
|
''':'
|
|
|
|
py2commands="
|
|
|
|
android
|
|
|
|
awsy-test
|
|
|
|
check-spidermonkey
|
|
|
|
cramtest
|
2020-05-29 22:47:30 +03:00
|
|
|
crashtest
|
2019-08-27 06:08:08 +03:00
|
|
|
devtools-css-db
|
|
|
|
firefox-ui-functional
|
|
|
|
geckodriver
|
|
|
|
geckodriver-test
|
2020-02-20 21:27:50 +03:00
|
|
|
hazards
|
2019-08-27 06:08:08 +03:00
|
|
|
jsapi-tests
|
|
|
|
jsshell-bench
|
2020-05-29 22:49:12 +03:00
|
|
|
marionette-test
|
2020-05-29 22:47:48 +03:00
|
|
|
jstestbrowser
|
|
|
|
jstests
|
2019-08-27 06:08:08 +03:00
|
|
|
mochitest
|
|
|
|
mozharness
|
|
|
|
prettier-format
|
2020-07-09 01:36:29 +03:00
|
|
|
python-test
|
2019-08-27 06:08:08 +03:00
|
|
|
raptor
|
|
|
|
raptor-test
|
2020-05-29 22:40:07 +03:00
|
|
|
reftest
|
2019-08-27 06:08:08 +03:00
|
|
|
talos-test
|
|
|
|
taskcluster-load-image
|
|
|
|
taskgraph
|
|
|
|
telemetry-tests-client
|
|
|
|
test
|
|
|
|
tps-build
|
|
|
|
visualmetrics
|
|
|
|
web-platform-tests
|
|
|
|
web-platform-tests-update
|
|
|
|
wpt
|
|
|
|
wpt-manifest-update
|
|
|
|
wpt-metadata-merge
|
|
|
|
wpt-metadata-summary
|
|
|
|
wpt-serve
|
2019-12-09 13:46:50 +03:00
|
|
|
wpt-test-paths
|
2019-08-27 06:08:08 +03:00
|
|
|
wpt-unittest
|
|
|
|
wpt-update
|
|
|
|
"
|
|
|
|
|
|
|
|
run_py() {
|
|
|
|
# Try to run a specific Python interpreter. Fall back to the system
|
|
|
|
# default Python if the specific interpreter couldn't be found.
|
|
|
|
py_executable="$1"
|
|
|
|
shift
|
|
|
|
if which "$py_executable" > /dev/null
|
|
|
|
then
|
|
|
|
exec "$py_executable" "$0" "$@"
|
|
|
|
elif [ "$py_executable" = "python2.7" ]; then
|
|
|
|
exec python "$0" "$@"
|
|
|
|
else
|
|
|
|
echo "This mach command requires $py_executable, which wasn't found on the system!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
first_arg=$1
|
2019-09-03 03:39:22 +03:00
|
|
|
if [ "$first_arg" = "help" ]; then
|
|
|
|
# When running `./mach help <command>`, the correct Python for <command>
|
|
|
|
# needs to be used.
|
|
|
|
first_arg=$2
|
2019-12-09 22:41:01 +03:00
|
|
|
elif [ "$first_arg" = "mach-completion" ]; then
|
|
|
|
# When running `./mach mach-completion /path/to/mach <command>`, the
|
|
|
|
# correct Python for <command> needs to be used.
|
|
|
|
first_arg=$3
|
2019-09-03 03:39:22 +03:00
|
|
|
fi
|
|
|
|
|
2019-08-27 06:08:08 +03:00
|
|
|
if [ -z "$first_arg" ]; then
|
2019-09-03 03:39:22 +03:00
|
|
|
# User ran `./mach` or `./mach help`, use Python 3.
|
|
|
|
run_py python3 "$@"
|
2019-08-27 06:08:08 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "${first_arg}" in
|
|
|
|
"-"*)
|
|
|
|
# We have global arguments which are tricky to parse from this shell
|
|
|
|
# script. So invoke `mach` with a special --print-command argument to
|
|
|
|
# return the name of the command. This adds extra overhead when using
|
|
|
|
# global arguments, but global arguments are an edge case and this hack
|
|
|
|
# is only needed temporarily for the Python 3 migration. We use Python
|
|
|
|
# 2.7 because using Python 3 hits this error in build tasks:
|
|
|
|
# https://searchfox.org/mozilla-central/rev/c7e8bc4996f9/build/moz.configure/init.configure#319
|
|
|
|
command=`run_py python2.7 --print-command "$@" | tail -n1`
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# In the common case, the first argument is the command.
|
|
|
|
command=${first_arg};
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Check for the mach subcommand in the Python 2 commands list and run it
|
|
|
|
# with the correct interpreter.
|
|
|
|
case " $(echo $py2commands) " in
|
|
|
|
*\ $command\ *)
|
|
|
|
run_py python2.7 "$@"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
run_py python3 "$@"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Run Python 3 for everything else.
|
|
|
|
run_py python3 "$@"
|
2014-05-21 06:27:30 +04:00
|
|
|
'''
|
|
|
|
|
2019-08-27 06:08:08 +03:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2013-04-04 18:42:28 +04:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def ancestors(path):
|
|
|
|
while path:
|
|
|
|
yield path
|
|
|
|
(path, child) = os.path.split(path)
|
|
|
|
if child == "":
|
|
|
|
break
|
|
|
|
|
2015-05-01 19:20:55 +03:00
|
|
|
def load_mach(dir_path, mach_path):
|
2019-08-27 06:08:08 +03:00
|
|
|
if sys.version_info < (3, 5):
|
|
|
|
import imp
|
|
|
|
mach_bootstrap = imp.load_source('mach_bootstrap', mach_path)
|
|
|
|
else:
|
|
|
|
import importlib.util
|
|
|
|
spec = importlib.util.spec_from_file_location('mach_bootstrap', mach_path)
|
|
|
|
mach_bootstrap = importlib.util.module_from_spec(spec)
|
|
|
|
spec.loader.exec_module(mach_bootstrap)
|
|
|
|
|
2015-05-01 19:20:55 +03:00
|
|
|
return mach_bootstrap.bootstrap(dir_path)
|
2013-04-04 18:42:28 +04:00
|
|
|
|
2014-07-03 02:15:31 +04:00
|
|
|
|
2015-04-24 22:12:50 +03:00
|
|
|
def check_and_get_mach(dir_path):
|
2015-05-01 19:20:55 +03:00
|
|
|
bootstrap_paths = (
|
|
|
|
'build/mach_bootstrap.py',
|
|
|
|
# test package bootstrap
|
|
|
|
'tools/mach_bootstrap.py',
|
|
|
|
)
|
|
|
|
for bootstrap_path in bootstrap_paths:
|
|
|
|
mach_path = os.path.join(dir_path, bootstrap_path)
|
|
|
|
if os.path.isfile(mach_path):
|
|
|
|
return load_mach(dir_path, mach_path)
|
2015-04-24 22:12:50 +03:00
|
|
|
return None
|
2014-07-03 02:15:31 +04:00
|
|
|
|
2015-05-01 19:20:55 +03:00
|
|
|
|
2019-10-08 16:58:33 +03:00
|
|
|
def setdefaultenv(key, value):
|
|
|
|
"""Compatibility shim to ensure the proper string type is used with
|
|
|
|
os.environ for the version of Python being used.
|
|
|
|
"""
|
|
|
|
encoding = "mbcs" if sys.platform == "win32" else "utf-8"
|
|
|
|
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
if isinstance(key, unicode):
|
|
|
|
key = key.encode(encoding)
|
|
|
|
if isinstance(value, unicode):
|
|
|
|
value = value.encode(encoding)
|
|
|
|
else:
|
|
|
|
if isinstance(key, bytes):
|
|
|
|
key = key.decode(encoding)
|
|
|
|
if isinstance(value, bytes):
|
|
|
|
value = value.decode(encoding)
|
|
|
|
|
|
|
|
os.environ.setdefault(key, value)
|
|
|
|
|
|
|
|
|
2015-04-24 22:12:50 +03:00
|
|
|
def get_mach():
|
2013-10-11 23:44:15 +04:00
|
|
|
# Check whether the current directory is within a mach src or obj dir.
|
|
|
|
for dir_path in ancestors(os.getcwd()):
|
2016-06-08 17:33:54 +03:00
|
|
|
# If we find a "config.status" and "mozinfo.json" file, we are in the objdir.
|
|
|
|
config_status_path = os.path.join(dir_path, 'config.status')
|
2013-10-11 23:44:15 +04:00
|
|
|
mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
|
2016-06-08 17:33:54 +03:00
|
|
|
if os.path.isfile(config_status_path) and os.path.isfile(mozinfo_path):
|
2013-10-11 23:44:15 +04:00
|
|
|
import json
|
|
|
|
info = json.load(open(mozinfo_path))
|
2019-10-08 16:58:33 +03:00
|
|
|
if 'mozconfig' in info:
|
2013-10-11 23:44:15 +04:00
|
|
|
# If the MOZCONFIG environment variable is not already set, set it
|
|
|
|
# to the value from mozinfo.json. This will tell the build system
|
|
|
|
# to look for a config file at the path in $MOZCONFIG rather than
|
|
|
|
# its default locations.
|
2019-10-08 16:58:33 +03:00
|
|
|
setdefaultenv('MOZCONFIG', info['mozconfig'])
|
2013-10-11 23:44:15 +04:00
|
|
|
|
|
|
|
if 'topsrcdir' in info:
|
|
|
|
# Continue searching for mach_bootstrap in the source directory.
|
|
|
|
dir_path = info['topsrcdir']
|
|
|
|
|
2015-04-24 22:12:50 +03:00
|
|
|
mach = check_and_get_mach(dir_path)
|
|
|
|
if mach:
|
|
|
|
return mach
|
2014-07-03 02:15:31 +04:00
|
|
|
|
|
|
|
# If we didn't find a source path by scanning for a mozinfo.json, check
|
2016-06-10 00:20:02 +03:00
|
|
|
# whether the directory containing this script is a source directory. We
|
|
|
|
# follow symlinks so mach can be run even if cwd is outside the srcdir.
|
|
|
|
return check_and_get_mach(os.path.dirname(os.path.realpath(__file__)))
|
2013-10-11 23:44:15 +04:00
|
|
|
|
2015-04-24 22:12:50 +03:00
|
|
|
def main(args):
|
|
|
|
mach = get_mach()
|
|
|
|
if not mach:
|
|
|
|
print('Could not run mach: No mach source directory found.')
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(mach.run(args))
|
2013-10-11 23:44:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-07-03 02:15:31 +04:00
|
|
|
main(sys.argv[1:])
|