author Mike Hommey <>
Tue, 14 Jan 2014 07:38:40 +0900
changeset 180228 1a1968da61b32a7dee6f1c08c15f7de9e825ec77
parent 179968 faafb9526e32b28f3b4647845442a3d3971183ec
child 180784 cdfa438e98171d3f7ec24ba7b5d3c5b2b715c098
permissions -rwxr-xr-x
Bug 950298 - Make the js build system use top-level as its root objdir. r=gps

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

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 == "":

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/')
        if os.path.isfile(mach_path):
            mach = load_mach(dir_path)

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

if __name__ == '__main__':