|
Packit |
f0b94e |
#!/bin/sh
|
|
Packit |
f0b94e |
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit |
f0b94e |
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit |
f0b94e |
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
# The beginning of this script is both valid shell and valid python,
|
|
Packit |
f0b94e |
# such that the script starts with the shell and is reexecuted with
|
|
Packit |
f0b94e |
# the right python.
|
|
Packit |
f0b94e |
'''which' python2.7 > /dev/null && exec python2.7 "$0" "$@" || exec python "$0" "$@"
|
|
Packit |
f0b94e |
'''
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
from __future__ import print_function, unicode_literals
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
import os
|
|
Packit |
f0b94e |
import sys
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
def ancestors(path):
|
|
Packit |
f0b94e |
while path:
|
|
Packit |
f0b94e |
yield path
|
|
Packit |
f0b94e |
(path, child) = os.path.split(path)
|
|
Packit |
f0b94e |
if child == "":
|
|
Packit |
f0b94e |
break
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
def load_mach(dir_path, mach_path):
|
|
Packit |
f0b94e |
import imp
|
|
Packit |
f0b94e |
with open(mach_path, 'r') as fh:
|
|
Packit |
f0b94e |
imp.load_module('mach_bootstrap', fh, mach_path,
|
|
Packit |
f0b94e |
('.py', 'r', imp.PY_SOURCE))
|
|
Packit |
f0b94e |
import mach_bootstrap
|
|
Packit |
f0b94e |
return mach_bootstrap.bootstrap(dir_path)
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
def check_and_get_mach(dir_path):
|
|
Packit |
f0b94e |
bootstrap_paths = (
|
|
Packit |
f0b94e |
'build/mach_bootstrap.py',
|
|
Packit |
f0b94e |
# test package bootstrap
|
|
Packit |
f0b94e |
'tools/mach_bootstrap.py',
|
|
Packit |
f0b94e |
)
|
|
Packit |
f0b94e |
for bootstrap_path in bootstrap_paths:
|
|
Packit |
f0b94e |
mach_path = os.path.join(dir_path, bootstrap_path)
|
|
Packit |
f0b94e |
if os.path.isfile(mach_path):
|
|
Packit |
f0b94e |
return load_mach(dir_path, mach_path)
|
|
Packit |
f0b94e |
return None
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
def get_mach():
|
|
Packit |
f0b94e |
# Check whether the current directory is within a mach src or obj dir.
|
|
Packit |
f0b94e |
for dir_path in ancestors(os.getcwd()):
|
|
Packit |
f0b94e |
# If we find a "config.status" and "mozinfo.json" file, we are in the objdir.
|
|
Packit |
f0b94e |
config_status_path = os.path.join(dir_path, 'config.status')
|
|
Packit |
f0b94e |
mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
|
|
Packit |
f0b94e |
if os.path.isfile(config_status_path) and os.path.isfile(mozinfo_path):
|
|
Packit |
f0b94e |
import json
|
|
Packit |
f0b94e |
info = json.load(open(mozinfo_path))
|
|
Packit |
f0b94e |
if 'mozconfig' in info and 'MOZCONFIG' not in os.environ:
|
|
Packit |
f0b94e |
# If the MOZCONFIG environment variable is not already set, set it
|
|
Packit |
f0b94e |
# to the value from mozinfo.json. This will tell the build system
|
|
Packit |
f0b94e |
# to look for a config file at the path in $MOZCONFIG rather than
|
|
Packit |
f0b94e |
# its default locations.
|
|
Packit |
f0b94e |
#
|
|
Packit |
f0b94e |
# Note: subprocess requires native strings in os.environ on Windows
|
|
Packit |
f0b94e |
os.environ[b'MOZCONFIG'] = str(info['mozconfig'])
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
if 'topsrcdir' in info:
|
|
Packit |
f0b94e |
# Continue searching for mach_bootstrap in the source directory.
|
|
Packit |
f0b94e |
dir_path = info['topsrcdir']
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
mach = check_and_get_mach(dir_path)
|
|
Packit |
f0b94e |
if mach:
|
|
Packit |
f0b94e |
return mach
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
# If we didn't find a source path by scanning for a mozinfo.json, check
|
|
Packit |
f0b94e |
# whether the directory containing this script is a source directory. We
|
|
Packit |
f0b94e |
# follow symlinks so mach can be run even if cwd is outside the srcdir.
|
|
Packit |
f0b94e |
return check_and_get_mach(os.path.dirname(os.path.realpath(__file__)))
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
def main(args):
|
|
Packit |
f0b94e |
mach = get_mach()
|
|
Packit |
f0b94e |
if not mach:
|
|
Packit |
f0b94e |
print('Could not run mach: No mach source directory found.')
|
|
Packit |
f0b94e |
sys.exit(1)
|
|
Packit |
f0b94e |
sys.exit(mach.run(args))
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
if __name__ == '__main__':
|
|
Packit |
f0b94e |
main(sys.argv[1:])
|