author Andrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 26 May 2015 10:12:51 -0400
changeset 249667 43e3ece52f5572b6a11b39d15d89eb4d6620a580
parent 243773 7923a0c837b56efcd1376b95318fe4cdce03d5e8
child 251928 450f972140decc0067300bbe0d901a79b9dffd69
permissions -rw-r--r--
Bug 1171602 - Run mochitest using mach from a tests.zip, r=chmanchester

# 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 platform
import sys
import time


# Individual files providing mach commands.

    'testing': {
        'short': 'Testing',
        'long': 'Run tests.',
        'priority': 30,
    'devenv': {
        'short': 'Development Environment',
        'long': 'Set up and configure your development environment.',
        'priority': 20,
    'misc': {
        'short': 'Potpourri',
        'long': 'Potent potables and assorted snacks.',
        'priority': 10,
    'disabled': {
        'short': 'Disabled',
        'long': 'The disabled commands are hidden by default. Use -v to display them. These commands are unavailable for your current context, run "mach <command>" to see why.',
        'priority': 0,

def bootstrap(test_package_root):
    # Ensure we are running Python 2.7+. We put this check here so we generate a
    # user-friendly error message rather than a cryptic stack trace on module
    # import.
    if sys.version_info[0] != 2 or sys.version_info[1] < 7:
        print('Python 2.7 or above (but not Python 3) is required to run mach.')
        print('You are running Python', platform.python_version())

        import mach.main
    except ImportError:
        sys.path[0:0] = [os.path.join(test_package_root, path) for path in SEARCH_PATHS]
        import mach.main

    def populate_context(context, key=None):
        context.package_root = test_package_root
        context.certs_dir = os.path.join(test_package_root, 'certs')
        context.bin_dir = os.path.join(test_package_root, 'bin')
        context.modules_dir = os.path.join(test_package_root, 'modules')
        return context

    mach = mach.main.Mach(os.getcwd())
    mach.populate_context_handler = populate_context

    for category, meta in CATEGORIES.items():
        mach.define_category(category, meta['short'], meta['long'],

    for path in MACH_MODULES:
        mach.load_commands_from_file(os.path.join(test_package_root, path))

    return mach