mach
author Ryan VanderMeulen <ryanvm@gmail.com>
Wed, 04 Jun 2014 16:07:06 -0400
changeset 206987 616163ca1aa528b7b418fe2edb84ac11973b851d
parent 204355 29a86e1eb5d2328d97fed43808a207a68d8e1b81
child 211820 a6b5b538815561ac3acdb37a3575a64e35c2ee8f
permissions -rwxr-xr-x
Backed out 5 changesets (bug 1015871, bug 1020257, bug 1015887, bug 1005888, bug 1015894) for desktop B2G mochitest failures on a CLOSED TREE. Backed out changeset dbcb9974b640 (bug 1020257) Backed out changeset 3220b7b2efc9 (bug 1015894) Backed out changeset 4e23647ae247 (bug 1015887) Backed out changeset 59df0cdacc15 (bug 1015871) Backed out changeset e7124b07804b (bug 1005888)

#!/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 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']

        # 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:]))

    print('Could not run mach: No mach source directory found.')
    sys.exit(1)


if __name__ == '__main__':
    main(sys.argv)