forked from haqistan/torb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mach
executable file
·70 lines (55 loc) · 2.5 KB
/
mach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# 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/.
# 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" "$@"
'''
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
def load_mach(topsrcdir):
sys.path[0:0] = [os.path.join(topsrcdir, "build")]
import mach_bootstrap
return mach_bootstrap.bootstrap(topsrcdir)
def check_and_run_mach(dir_path, args):
# If we find the mach bootstrap module, we are in the srcdir.
mach_path = os.path.join(dir_path, 'build/mach_bootstrap.py')
if os.path.isfile(mach_path):
mach = load_mach(dir_path)
sys.exit(mach.run(args))
def main(args):
# Check whether the current directory is within a mach src or obj dir.
for dir_path in ancestors(os.getcwd()):
# If we find a "mozinfo.json" file, we are in the objdir.
mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
if os.path.isfile(mozinfo_path):
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']
check_and_run_mach(dir_path, args)
# If we didn't find a source path by scanning for a mozinfo.json, check
# whether the directory containing this script is a source directory.
check_and_run_mach(os.path.dirname(__file__), args)
print('Could not run mach: No mach source directory found.')
sys.exit(1)
if __name__ == '__main__':
main(sys.argv[1:])