mach

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mach	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +#!/bin/sh
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +# The beginning of this script is both valid shell and valid python,
    1.10 +# such that the script starts with the shell and is reexecuted with
    1.11 +# the right python.
    1.12 +'''which' python2.7 > /dev/null && exec python2.7 "$0" "$@" || exec python "$0" "$@"
    1.13 +'''
    1.14 +
    1.15 +from __future__ import print_function, unicode_literals
    1.16 +
    1.17 +import os
    1.18 +import sys
    1.19 +
    1.20 +def ancestors(path):
    1.21 +    while path:
    1.22 +        yield path
    1.23 +        (path, child) = os.path.split(path)
    1.24 +        if child == "":
    1.25 +            break
    1.26 +
    1.27 +def load_mach(topsrcdir):
    1.28 +    sys.path[0:0] = [os.path.join(topsrcdir, "build")]
    1.29 +    import mach_bootstrap
    1.30 +    return mach_bootstrap.bootstrap(topsrcdir)
    1.31 +
    1.32 +
    1.33 +def check_and_run_mach(dir_path, args):
    1.34 +    # If we find the mach bootstrap module, we are in the srcdir.
    1.35 +    mach_path = os.path.join(dir_path, 'build/mach_bootstrap.py')
    1.36 +    if os.path.isfile(mach_path):
    1.37 +        mach = load_mach(dir_path)
    1.38 +        sys.exit(mach.run(args))
    1.39 +
    1.40 +
    1.41 +def main(args):
    1.42 +    # Check whether the current directory is within a mach src or obj dir.
    1.43 +    for dir_path in ancestors(os.getcwd()):
    1.44 +        # If we find a "mozinfo.json" file, we are in the objdir.
    1.45 +        mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
    1.46 +        if os.path.isfile(mozinfo_path):
    1.47 +            import json
    1.48 +            info = json.load(open(mozinfo_path))
    1.49 +            if 'mozconfig' in info and 'MOZCONFIG' not in os.environ:
    1.50 +                # If the MOZCONFIG environment variable is not already set, set it
    1.51 +                # to the value from mozinfo.json.  This will tell the build system
    1.52 +                # to look for a config file at the path in $MOZCONFIG rather than
    1.53 +                # its default locations.
    1.54 +                #
    1.55 +                # Note: subprocess requires native strings in os.environ on Windows
    1.56 +                os.environ[b'MOZCONFIG'] = str(info['mozconfig'])
    1.57 +
    1.58 +            if 'topsrcdir' in info:
    1.59 +                # Continue searching for mach_bootstrap in the source directory.
    1.60 +                dir_path = info['topsrcdir']
    1.61 +
    1.62 +        check_and_run_mach(dir_path, args)
    1.63 +
    1.64 +    # If we didn't find a source path by scanning for a mozinfo.json, check
    1.65 +    # whether the directory containing this script is a source directory.
    1.66 +    check_and_run_mach(os.path.dirname(__file__), args)
    1.67 +
    1.68 +    print('Could not run mach: No mach source directory found.')
    1.69 +    sys.exit(1)
    1.70 +
    1.71 +
    1.72 +if __name__ == '__main__':
    1.73 +    main(sys.argv[1:])

mercurial