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 shell and valid python,
7 # such that the script starts with the shell and is reexecuted with
9 '''which' python2.7
> /dev
/null
&& exec python2.7
"$0" "$@" ||
exec python
"$0" "$@"
12 from __future__ import print_function, unicode_literals
20 (path, child) = os.path.split(path)
24 def load_mach(topsrcdir):
25 sys.path[0:0] = [os.path.join(topsrcdir, "build")]
27 return mach_bootstrap.bootstrap(topsrcdir)
30 # Check whether the current directory is within a mach src or obj dir.
31 for dir_path in ancestors(os.getcwd()):
32 # If we find a "mozinfo.json" file, we are in the objdir.
33 mozinfo_path = os.path.join(dir_path, 'mozinfo.json
')
34 if os.path.isfile(mozinfo_path):
36 info = json.load(open(mozinfo_path))
37 if 'mozconfig
' in info and 'MOZCONFIG
' not in os.environ:
38 # If the MOZCONFIG environment variable is not already set, set it
39 # to the value from mozinfo.json. This will tell the build system
40 # to look for a config file at the path in $MOZCONFIG rather than
41 # its default locations.
43 # Note: subprocess requires native strings in os.environ on Windows
44 os.environ[b'MOZCONFIG
'] = str(info['mozconfig
'])
46 if 'topsrcdir
' in info:
47 # Continue searching for mach_bootstrap in the source directory.
48 dir_path = info['topsrcdir
']
50 # If we find the mach bootstrap module, we are in the srcdir.
51 mach_path = os.path.join(dir_path, 'build
/mach_bootstrap.py
')
52 if os.path.isfile(mach_path):
53 mach = load_mach(dir_path)
54 sys.exit(mach.run(args[1:]))
56 print('Could not run mach
: No mach
source directory found.
')
60 if __name__ == '__main__
':