mach
author Wes Kocher <wkocher@mozilla.com>
Thu, 19 Sep 2013 17:56:18 -0700
changeset 162779 1f6d484652904ce39c0145050c9c2a69dffe4d3a
parent 155640 3fc5338cc5b1fb9b42e2f35bc25e66c516285668
child 165305 c1c61b305ce0b58450ec0092457f98cd7119d4ee
permissions -rwxr-xr-x
Backed out 5 changesets (bug 907926, bug 911393, bug 917703) due to OSX reftest bustage during an unrelated CLOSED TREE Backed out changeset 94a6733b01dc (bug 907926) Backed out changeset 44108fb6f7cc (bug 917703) Backed out changeset f2dd2a27af69 (bug 911393) Backed out changeset fdb0d1053128 (bug 907926) Backed out changeset b3616b786e8f (bug 907926)

#!/usr/bin/env python
# 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/.

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)

# 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(sys.argv[1:]))

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