Backout a74bd5095902, Bug 959405 - Please update the Buri Moz-central, 1.3, 1.2 with...
[gecko.git] / mach
blob16efaa48a7ceed044beabe1ccb4407f02e71836f
1 #!/usr/bin/env python2.7
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 from __future__ import print_function, unicode_literals
8 import os
9 import sys
11 def ancestors(path):
12     while path:
13         yield path
14         (path, child) = os.path.split(path)
15         if child == "":
16             break
18 def load_mach(topsrcdir):
19     sys.path[0:0] = [os.path.join(topsrcdir, "build")]
20     import mach_bootstrap
21     return mach_bootstrap.bootstrap(topsrcdir)
23 def main(args):
24     # Check whether the current directory is within a mach src or obj dir.
25     for dir_path in ancestors(os.getcwd()):
26         # If we find a "mozinfo.json" file, we are in the objdir.
27         mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
28         if os.path.isfile(mozinfo_path):
29             import json
30             info = json.load(open(mozinfo_path))
31             if 'mozconfig' in info and 'MOZCONFIG' not in os.environ:
32                 # If the MOZCONFIG environment variable is not already set, set it
33                 # to the value from mozinfo.json.  This will tell the build system
34                 # to look for a config file at the path in $MOZCONFIG rather than
35                 # its default locations.
36                 #
37                 # Note: subprocess requires native strings in os.environ on Windows
38                 os.environ[b'MOZCONFIG'] = str(info['mozconfig'])
40             if 'topsrcdir' in info:
41                 # Continue searching for mach_bootstrap in the source directory.
42                 dir_path = info['topsrcdir']
44         # If we find the mach bootstrap module, we are in the srcdir.
45         mach_path = os.path.join(dir_path, 'build/mach_bootstrap.py')
46         if os.path.isfile(mach_path):
47             mach = load_mach(dir_path)
48             sys.exit(mach.run(args[1:]))
50     print('Could not run mach: No mach source directory found.')
51     sys.exit(1)
54 if __name__ == '__main__':
55     main(sys.argv)