author Mike Hommey <>
Thu, 11 May 2017 13:23:07 +0900
changeset 1125540 faae5fbdd01ddaf171810c446a645ea00085aa54
parent 919661 1f85e7bfe97d54892bc08f3d5a80e9bab52f0189
child 931184 625abaf8b15c73f5bd9de76cadf6286d83243024
child 1206535 d500961f79c553b7e0e986bf4d3910fffaac562a
child 1804795 32fb6bbf5cf5d45587cf83418feee21c4df4b4bb
child 2110045 5fa7b16506287c43be2bb11bcedec27953c4e4cc
child 2140599 b08b21faff52a003dd4733fd302bdb22526e8f2f
child 2172495 53009469a2fb9a07b16df0f3e0655fb2411c0582
child 2203336 93c8b1b7064b88eec6e5ae52b6309e8a86286703
child 2204416 ae68b67551b713e185681641ccfefb118f48ea94
child 2209355 888c8a8401964d01b10f5243b7efe97b4d18f30c
child 2215690 f3df6fc78fbf6d7d9bf18b6f814a501dab778b68
child 2215806 9847ded310e1ff6f407d12810f1409f331247c69
child 2216130 810d8aa2ad4a4722fad477ad1960152f37598c70
child 2229240 25a1352abc3cf0577c4344a54998dcf1edc74faa
child 2237865 a2e02d1ac250809033be46566084cad6e7ae5b8d
permissions -rwxr-xr-x
Bug 1363992 - Remove jemalloc 4. r=njn

# 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

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

def load_mach(dir_path, mach_path):
    import imp
    with open(mach_path, 'r') as fh:
        imp.load_module('mach_bootstrap', fh, mach_path,
                        ('.py', 'r', imp.PY_SOURCE))
    import mach_bootstrap
    return mach_bootstrap.bootstrap(dir_path)

def check_and_get_mach(dir_path):
    bootstrap_paths = (
        # test package bootstrap
    for bootstrap_path in bootstrap_paths:
        mach_path = os.path.join(dir_path, bootstrap_path)
        if os.path.isfile(mach_path):
            return load_mach(dir_path, mach_path)
    return None

def get_mach():
    # Check whether the current directory is within a mach src or obj dir.
    for dir_path in ancestors(os.getcwd()):
        # If we find a "config.status" and "mozinfo.json" file, we are in the objdir.
        config_status_path = os.path.join(dir_path, 'config.status')
        mozinfo_path = os.path.join(dir_path, 'mozinfo.json')
        if os.path.isfile(config_status_path) and 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']

        mach = check_and_get_mach(dir_path)
        if mach:
            return mach

    # 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. We
    # follow symlinks so mach can be run even if cwd is outside the srcdir.
    return check_and_get_mach(os.path.dirname(os.path.realpath(__file__)))

def main(args):
    mach = get_mach()
    if not mach:
        print('Could not run mach: No mach source directory found.')

if __name__ == '__main__':