2014-05-21 02:27:30 +00:00
|
|
|
#!/bin/sh
|
2013-04-04 14:42:28 +00: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/.
|
|
|
|
|
2014-05-21 02:27:30 +00:00
|
|
|
# The beginning of this script is both valid shell and valid python,
|
|
|
|
# such that the script starts with the shell and is reexecuted with
|
|
|
|
# the right python.
|
|
|
|
'''which' python2.7 > /dev/null && exec python2.7 "$0" "$@" || exec python "$0" "$@"
|
|
|
|
'''
|
|
|
|
|
2013-04-04 14:42:28 +00:00
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def ancestors(path):
|
|
|
|
while path:
|
|
|
|
yield path
|
|
|
|
(path, child) = os.path.split(path)
|
|
|
|
if child == "":
|
|
|
|
break
|
|
|
|
|
2015-05-01 16:20:55 +00:00
|
|
|
def load_mach(dir_path, mach_path):
|
|
|
|
import imp
|
|
|
|
with open(mach_path, 'r') as fh:
|
|
|
|
imp.load_module('mach_bootstrap', fh, mach_path,
|
|
|
|
('.py', 'r', imp.PY_SOURCE))
|
2013-04-04 14:42:28 +00:00
|
|
|
import mach_bootstrap
|
2015-05-01 16:20:55 +00:00
|
|
|
return mach_bootstrap.bootstrap(dir_path)
|
2013-04-04 14:42:28 +00:00
|
|
|
|
2014-07-02 22:15:31 +00:00
|
|
|
|
2015-04-24 19:12:50 +00:00
|
|
|
def check_and_get_mach(dir_path):
|
2015-05-01 16:20:55 +00: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 19:12:50 +00:00
|
|
|
return None
|
2014-07-02 22:15:31 +00:00
|
|
|
|
2015-05-01 16:20:55 +00:00
|
|
|
|
2015-04-24 19:12:50 +00:00
|
|
|
def get_mach():
|
2013-10-11 19:44:15 +00:00
|
|
|
# Check whether the current directory is within a mach src or obj dir.
|
|
|
|
for dir_path in ancestors(os.getcwd()):
|
2016-06-08 14:33:54 +00: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 19:44:15 +00:00
|
|
|
mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
|
2016-06-08 14:33:54 +00:00
|
|
|
if os.path.isfile(config_status_path) and os.path.isfile(mozinfo_path):
|
2013-10-11 19:44:15 +00:00
|
|
|
import json
|
|
|
|
info = json.load(open(mozinfo_path))
|
|
|
|
if 'mozconfig' in info and 'MOZCONFIG' not in os.environ:
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Note: subprocess requires native strings in os.environ on Windows
|
|
|
|
os.environ[b'MOZCONFIG'] = str(info['mozconfig'])
|
|
|
|
|
|
|
|
if 'topsrcdir' in info:
|
|
|
|
# Continue searching for mach_bootstrap in the source directory.
|
|
|
|
dir_path = info['topsrcdir']
|
|
|
|
|
2015-04-24 19:12:50 +00:00
|
|
|
mach = check_and_get_mach(dir_path)
|
|
|
|
if mach:
|
|
|
|
return mach
|
2014-07-02 22:15:31 +00:00
|
|
|
|
|
|
|
# If we didn't find a source path by scanning for a mozinfo.json, check
|
2016-06-09 21:20:02 +00: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 19:44:15 +00:00
|
|
|
|
2015-04-24 19:12:50 +00: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 19:44:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-07-02 22:15:31 +00:00
|
|
|
main(sys.argv[1:])
|