Bug 1031180 - Fallback to checking whether the directory mach lives in contains mach_bootstrap.py. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 03 Jul 2014 07:15:31 +0900
changeset 192037 588203633ba714cc4ee0e1f03cf9844faee41e09
parent 192036 3ee4eaf0c38e0480514c0f9ea42fd80ae61efc0e
child 192038 ce1c57e03b885eedfbe58a191e5306b17b04fc65
push id27073
push usercbook@mozilla.com
push dateThu, 03 Jul 2014 11:47:13 +0000
treeherdermozilla-central@0ddb94bb72c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1031180
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1031180 - Fallback to checking whether the directory mach lives in contains mach_bootstrap.py. r=gps
mach
--- a/mach
+++ b/mach
@@ -21,16 +21,25 @@ def ancestors(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))
@@ -42,21 +51,21 @@ def main(args):
                 #
                 # 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']
 
-        # 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[1:]))
+        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__':
     if sys.platform == 'win32':
         # This is a complete hack to work around the fact that Windows
@@ -100,9 +109,9 @@ if __name__ == '__main__':
 	    # levels of indentation (12 spaces).
             fork_string = ''.join(x[12:] for x in fork_code[1:])
             cmdline = orig_command_line()
             cmdline[2] = fork_string
             return cmdline
         orig_command_line = forking.get_command_line
         forking.get_command_line = my_get_command_line
 
-    main(sys.argv)
+    main(sys.argv[1:])