Example #1
0
    def run_xpcshell_test(self, **params):
        from mozbuild.controller.building import BuildDriver

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        driver = self._spawn(BuildDriver)
        driver.install_tests(remove=False)

        structured.commandline.formatter_option_defaults['verbose'] = True
        params['log'] = structured.commandline.setup_logging("XPCShellTests",
                                                             params,
                                                             {"mach": sys.stdout})

        if conditions.is_android(self):
            xpcshell = self._spawn(AndroidXPCShellRunner)
        elif conditions.is_b2g(self):
            xpcshell = self._spawn(B2GXPCShellRunner)
            params['b2g_home'] = self.b2g_home
            params['device_name'] = self.device_name
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #2
0
 def run_mochitest_chrome(self, test_paths, **kwargs):
     if conditions.is_firefox(self):
         return self.run_mochitest(test_paths, 'chrome', **kwargs)
     elif conditions.is_b2g(self) and conditions.is_emulator(self):
         return self.run_mochitest_remote(test_paths, chrome=True, **kwargs)
     elif conditions.is_android(self):
         return self.run_mochitest_android(test_paths, chrome=True, **kwargs)
Example #3
0
    def run_xpcshell_test(self, **params):
        from mozbuild.controller.building import BuildDriver

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        driver = self._spawn(BuildDriver)
        driver.install_tests(remove=False)

        if conditions.is_android(self):
            xpcshell = self._spawn(AndroidXPCShellRunner)
        elif conditions.is_b2g(self):
            xpcshell = self._spawn(B2GXPCShellRunner)
            params['b2g_home'] = self.b2g_home
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #4
0
def get_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)
    if conditions.is_android(build_obj):
        return parser_remote()
    elif conditions.is_b2g(build_obj):
        return parser_b2g()
    else:
        return parser_desktop()
Example #5
0
 def run_mochitest_plain(self, test_paths, **kwargs):
     if is_platform_in('firefox', 'mulet')(self):
         return self.run_mochitest(test_paths, 'plain', **kwargs)
     elif conditions.is_emulator(self):
         return self.run_mochitest_remote(test_paths, **kwargs)
     elif conditions.is_b2g_desktop(self):
         return self.run_mochitest_b2g_desktop(test_paths, **kwargs)
     elif conditions.is_android(self):
         return self.run_mochitest_android(test_paths, **kwargs)
Example #6
0
def get_parser():
    here = os.path.abspath(os.path.dirname(__file__))
    build_obj = MozbuildObject.from_environment(cwd=here)
    if conditions.is_android(build_obj):
        return reftestcommandline.RemoteArgumentsParser()
    elif conditions.is_mulet(build_obj):
        return reftestcommandline.B2GArgumentParser()
    else:
        return reftestcommandline.DesktopArgumentsParser()
Example #7
0
 def _run_reftest(self, **kwargs):
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True)
         return reftest.run_android_test(**kwargs)
     elif conditions.is_mulet(self):
         return reftest.run_mulet_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #8
0
    def test_info(self, **params):

        import which
        from mozbuild.base import MozbuildObject

        self.branches = params['branches']
        self.start = params['start']
        self.end = params['end']
        self.show_info = params['show_info']
        self.show_results = params['show_results']
        self.show_durations = params['show_durations']
        self.show_bugs = params['show_bugs']
        self.verbose = params['verbose']

        if (not self.show_info and
            not self.show_results and
            not self.show_durations and
                not self.show_bugs):
            # by default, show everything
            self.show_info = True
            self.show_results = True
            self.show_durations = True
            self.show_bugs = True

        here = os.path.abspath(os.path.dirname(__file__))
        build_obj = MozbuildObject.from_environment(cwd=here)

        self._hg = None
        if conditions.is_hg(build_obj):
            if self._is_windows():
                self._hg = which.which('hg.exe')
            else:
                self._hg = which.which('hg')

        self._git = None
        if conditions.is_git(build_obj):
            if self._is_windows():
                self._git = which.which('git.exe')
            else:
                self._git = which.which('git')

        for test_name in params['test_names']:
            print("===== %s =====" % test_name)
            self.test_name = test_name
            if len(self.test_name) < 6:
                print("'%s' is too short for a test name!" % self.test_name)
                continue
            if self.show_info:
                self.set_test_name()
            if self.show_results:
                self.report_test_results()
            if self.show_durations:
                self.report_test_durations()
            if self.show_bugs:
                self.report_bugs()
Example #9
0
def format_files(command_context, paths, extra_args=[], **kwargs):
    linters = kwargs["linters"]

    formatters = VALID_FORMATTERS
    if conditions.is_android(command_context):
        formatters |= VALID_ANDROID_FORMATTERS

    if not linters:
        linters = formatters
    else:
        invalid_linters = set(linters) - formatters
        if invalid_linters:
            print(
                "error: One or more linters passed are not valid formatters. "
                "Note that only the following linters are valid formatters:")
            print("\n".join(sorted(formatters)))
            return 1

    kwargs["linters"] = list(linters)

    kwargs["fix"] = True
    command_context._mach_context.commands.dispatch(
        "lint",
        command_context._mach_context,
        paths=paths,
        argv=extra_args,
        **kwargs)
Example #10
0
    def run_cppunit_test(self, **params):
        from mozlog import commandline

        log = params.get("log")
        if not log:
            log = commandline.setup_logging("cppunittest", {}, {"tbpl": sys.stdout})

        # See if we have crash symbols
        symbols_path = os.path.join(self.distdir, "crashreporter-symbols")
        if not os.path.isdir(symbols_path):
            symbols_path = None

        # If no tests specified, run all tests in main manifest
        tests = params["test_files"]
        if not tests:
            tests = [os.path.join(self.distdir, "cppunittests")]
            manifest_path = os.path.join(self.topsrcdir, "testing", "cppunittest.ini")
        else:
            manifest_path = None

        utility_path = self.bindir

        if conditions.is_android(self):
            from mozrunner.devices.android_device import (
                verify_android_device,
                InstallIntent,
            )

            verify_android_device(self, install=InstallIntent.NO)
            return self.run_android_test(tests, symbols_path, manifest_path, log)

        return self.run_desktop_test(
            tests, symbols_path, manifest_path, utility_path, log
        )
Example #11
0
    def __init__(self, environment):
        if not MachCommandConditions.is_android(environment):
            raise Exception(
                'The Android Eclipse backend is not available with this '
                'configuration.')

        super(AndroidEclipseBackend, self).__init__(environment)
Example #12
0
def setup_argument_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)

    build_path = os.path.join(build_obj.topobjdir, 'build')
    if build_path not in sys.path:
        sys.path.append(build_path)

    mochitest_dir = os.path.join(build_obj.topobjdir, '_tests', 'testing', 'mochitest')

    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

        import imp
        path = os.path.join(build_obj.topobjdir, mochitest_dir, 'runtests.py')
        if not os.path.exists(path):
            path = os.path.join(here, "runtests.py")

        with open(path, 'r') as fh:
            imp.load_module('mochitest', fh, path,
                            ('.py', 'r', imp.PY_SOURCE))

        from mochitest_options import MochitestArgumentParser

    if conditions.is_android(build_obj):
        # On Android, check for a connected device (and offer to start an
        # emulator if appropriate) before running tests. This check must
        # be done in this admittedly awkward place because
        # MochitestArgumentParser initialization fails if no device is found.
        from mozrunner.devices.android_device import verify_android_device
        verify_android_device(build_obj, install=True, xre=True)

    global parser
    parser = MochitestArgumentParser()
    return parser
Example #13
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest
            m = TestManifest()
            m.tests.extend(test_objects)
            params['manifest'] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests(test_objects)

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        params['log'] = structured.commandline.setup_logging("XPCShellTests",
                                                             params,
                                                             {"mach": sys.stdout},
                                                             {"verbose": True})

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
def get_parser():
    here = os.path.abspath(os.path.dirname(__file__))
    build_obj = MozbuildObject.from_environment(cwd=here)
    if conditions.is_android(build_obj):
        return reftestcommandline.RemoteArgumentsParser()
    else:
        return reftestcommandline.DesktopArgumentsParser()
Example #15
0
    def run_cppunit_test(self, **params):
        from mozlog import commandline

        log = params.get('log')
        if not log:
            log = commandline.setup_logging("cppunittest",
                                            {},
                                            {"tbpl": sys.stdout})

        # See if we have crash symbols
        symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
        if not os.path.isdir(symbols_path):
            symbols_path = None

        # If no tests specified, run all tests in main manifest
        tests = params['test_files']
        if len(tests) == 0:
            tests = [os.path.join(self.distdir, 'cppunittests')]
            manifest_path = os.path.join(
                self.topsrcdir, 'testing', 'cppunittest.ini')
        else:
            manifest_path = None

        utility_path = self.bindir

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self, install=False)
            return self.run_android_test(tests, symbols_path, manifest_path, log)

        return self.run_desktop_test(tests, symbols_path, manifest_path,
                                     utility_path, log)
Example #16
0
    def init_variables(self, raptor_args, kwargs):
        self.raptor_args = raptor_args

        if kwargs.get('host') == 'HOST_IP':
            kwargs['host'] = os.environ['HOST_IP']
        self.host = kwargs['host']
        self.is_release_build = kwargs['is_release_build']
        self.memory_test = kwargs['memory_test']
        self.power_test = kwargs['power_test']
        self.cpu_test = kwargs['cpu_test']

        if Conditions.is_android(
                self) or kwargs["app"] in FIREFOX_ANDROID_BROWSERS:
            self.binary_path = None
        else:
            self.binary_path = kwargs.get("binary") or self.get_binary_path()

        self.python = sys.executable

        self.raptor_dir = os.path.join(self.topsrcdir, 'testing', 'raptor')
        self.mozharness_dir = os.path.join(self.topsrcdir, 'testing',
                                           'mozharness')
        self.config_file_path = os.path.join(self._topobjdir, 'testing',
                                             'raptor-in_tree_conf.json')

        self.virtualenv_script = os.path.join(self.topsrcdir, 'third_party',
                                              'python', 'virtualenv',
                                              'virtualenv.py')
        self.virtualenv_path = os.path.join(self._topobjdir, 'testing',
                                            'raptor-venv')
Example #17
0
    def init_variables(self, raptor_args, kwargs):
        self.raptor_args = raptor_args

        if kwargs.get("host") == "HOST_IP":
            kwargs["host"] = os.environ["HOST_IP"]
        self.host = kwargs["host"]
        self.is_release_build = kwargs["is_release_build"]
        self.memory_test = kwargs["memory_test"]
        self.power_test = kwargs["power_test"]
        self.cpu_test = kwargs["cpu_test"]
        self.live_sites = kwargs["live_sites"]
        self.disable_perf_tuning = kwargs["disable_perf_tuning"]
        self.conditioned_profile_scenario = kwargs[
            "conditioned_profile_scenario"]
        self.device_name = kwargs["device_name"]

        if Conditions.is_android(self) or kwargs["app"] in ANDROID_BROWSERS:
            self.binary_path = None
        else:
            self.binary_path = kwargs.get("binary") or self.get_binary_path()

        self.python = sys.executable

        self.raptor_dir = os.path.join(self.topsrcdir, "testing", "raptor")
        self.mozharness_dir = os.path.join(self.topsrcdir, "testing",
                                           "mozharness")
        self.config_file_path = os.path.join(self._topobjdir, "testing",
                                             "raptor-in_tree_conf.json")

        self.virtualenv_script = os.path.join(self.topsrcdir, "third_party",
                                              "python", "virtualenv",
                                              "virtualenv.py")
        self.virtualenv_path = os.path.join(self._topobjdir, "testing",
                                            "raptor-venv")
Example #18
0
def get_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)
    if (conditions.is_android(build_obj)
            or build_obj.substs.get("MOZ_BUILD_APP") == "b2g"):
        return parser_remote()
    else:
        return parser_desktop()
Example #19
0
def setup_argument_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)

    build_path = os.path.join(build_obj.topobjdir, 'build')
    if build_path not in sys.path:
        sys.path.append(build_path)

    mochitest_dir = os.path.join(build_obj.topobjdir, '_tests', 'testing',
                                 'mochitest')

    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

        import imp
        path = os.path.join(build_obj.topobjdir, mochitest_dir, 'runtests.py')
        if not os.path.exists(path):
            path = os.path.join(here, "runtests.py")

        with open(path, 'r') as fh:
            imp.load_module('mochitest', fh, path, ('.py', 'r', imp.PY_SOURCE))

        from mochitest_options import MochitestArgumentParser

    if conditions.is_android(build_obj):
        # On Android, check for a connected device (and offer to start an
        # emulator if appropriate) before running tests. This check must
        # be done in this admittedly awkward place because
        # MochitestArgumentParser initialization fails if no device is found.
        from mozrunner.devices.android_device import verify_android_device
        # verify device and xre
        verify_android_device(build_obj, install=False, xre=True)

    global parser
    parser = MochitestArgumentParser()
    return parser
Example #20
0
    def __init__(self, environment):
        if not MachCommandConditions.is_android(environment):
            raise Exception(
                'The Android Eclipse backend is not available with this '
                'configuration.')

        super(AndroidEclipseBackend, self).__init__(environment)
Example #21
0
    def run_raptor(self, **kwargs):
        build_obj = self

        is_android = Conditions.is_android(build_obj) or \
            kwargs['app'] in FIREFOX_ANDROID_BROWSERS

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            from mozdevice import ADBAndroid
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.PROMPT
            if not verify_android_device(
                    build_obj, install=install, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)
        device = None

        try:
            if kwargs['power_test'] and is_android:
                device = ADBAndroid(verbose=True)
                disable_charging(device)
            return raptor.run_test(sys.argv[2:], kwargs)
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            if kwargs['power_test'] and device:
                enable_charging(device)
Example #22
0
    def run_awsy_test(self, tests, **kwargs):
        """mach awsy-test runs the in-tree version of the Are We Slim Yet
        (AWSY) tests.

        awsy-test is implemented as a marionette test and marionette
        test arguments also apply although they are not necessary
        since reasonable defaults will be chosen.

        The AWSY specific arguments can be found in the Command
        Arguments for AWSY section below.

        awsy-test will automatically download the tp5n.zip talos
        pageset from tooltool and install it under
        topobjdir/_tests/awsy/html. You can specify your own page set
        by specifying --web-root and --page-manifest.

        The results of the test will be placed in the results
        directory specified by the --results argument.

        """
        kwargs['logger_name'] = 'Awsy Tests'
        if 'test_objects' in kwargs:
            tests = []
            for obj in kwargs['test_objects']:
                tests.append(obj['file_relpath'])
            del kwargs['test_objects']

        if not kwargs.get('binary') and conditions.is_firefox(self):
            kwargs['binary'] = self.get_binary_path('app')
        return self.run_awsy(tests, **kwargs)
Example #23
0
    def run_cppunit_test(self, **params):
        import mozinfo
        from mozlog import commandline
        log = commandline.setup_logging("cppunittest",
                                        {},
                                        {"tbpl": sys.stdout})

        # See if we have crash symbols
        symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
        if not os.path.isdir(symbols_path):
            symbols_path = None

        # If no tests specified, run all tests in main manifest
        tests = params['test_files']
        if len(tests) == 0:
            tests = [os.path.join(self.distdir, 'cppunittests')]
            manifest_path = os.path.join(self.topsrcdir, 'testing', 'cppunittest.ini')
        else:
            manifest_path = None

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self, install=False)
            return self.run_android_test(tests, symbols_path, manifest_path, log)

        return self.run_desktop_test(tests, symbols_path, manifest_path, log)
Example #24
0
 def _run_reftest(self, **kwargs):
     kwargs["topsrcdir"] = self.topsrcdir
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     # Unstructured logging must be enabled prior to calling
     # adb which uses an unstructured logger in its constructor.
     reftest.log_manager.enable_unstructured()
     if conditions.is_android(self):
         from mozrunner.devices.android_device import (
             verify_android_device, InstallIntent)
         install = InstallIntent.NO if kwargs.get(
             'no_install') else InstallIntent.YES
         verbose = False
         if kwargs.get('log_mach_verbose') or kwargs.get('log_tbpl_level') == 'debug' or \
            kwargs.get('log_mach_level') == 'debug' or kwargs.get('log_raw_level') == 'debug':
             verbose = True
         verify_android_device(self,
                               install=install,
                               xre=True,
                               network=True,
                               app=kwargs["app"],
                               device_serial=kwargs["deviceSerial"],
                               verbose=verbose)
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #25
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest
            m = TestManifest()
            m.tests.extend(test_objects)
            params['manifest'] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests(test_objects)

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        params['log'] = structured.commandline.setup_logging(
            "XPCShellTests", params, {"mach": sys.stdout}, {"verbose": True})

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #26
0
 def telemetry_test(self, tests, **kwargs):
     if "test_objects" in kwargs:
         tests = []
         for obj in kwargs["test_objects"]:
             tests.append(obj["file_relpath"])
         del kwargs["test_objects"]
     if not kwargs.get("binary") and conditions.is_firefox(self):
         try:
             kwargs["binary"] = self.get_binary_path("app")
         except BinaryNotFoundException as e:
             self.log(
                 logging.ERROR,
                 "telemetry-tests-client",
                 {"error": str(e)},
                 "ERROR: {error}",
             )
             self.log(
                 logging.INFO, "telemetry-tests-client", {"help": e.help()}, "{help}"
             )
             return 1
     if not kwargs.get("server_root"):
         kwargs[
             "server_root"
         ] = "toolkit/components/telemetry/tests/marionette/harness/www"
     return run_telemetry(tests, topsrcdir=self.topsrcdir, **kwargs)
Example #27
0
    def emulator(self, version, wait=False, force_update=False, verbose=False):
        from mozrunner.devices.android_device import AndroidEmulator

        emulator = AndroidEmulator(version, verbose, substs=self.substs,
                                   device_serial='emulator-5554')
        if emulator.is_running():
            # It is possible to run multiple emulators simultaneously, but:
            #  - if more than one emulator is using the same avd, errors may
            #    occur due to locked resources;
            #  - additional parameters must be specified when running tests,
            #    to select a specific device.
            # To avoid these complications, allow just one emulator at a time.
            self.log(logging.ERROR, "emulator", {},
                     "An Android emulator is already running.\n"
                     "Close the existing emulator and re-run this command.")
            return 1

        if not emulator.is_available():
            self.log(logging.WARN, "emulator", {},
                     "Emulator binary not found.\n"
                     "Install the Android SDK and make sure 'emulator' is in your PATH.")
            return 2

        if not emulator.check_avd(force_update):
            self.log(logging.INFO, "emulator", {},
                     "Fetching and installing AVD. This may take a few minutes...")
            emulator.update_avd(force_update)

        self.log(logging.INFO, "emulator", {},
                 "Starting Android emulator running %s..." %
                 emulator.get_avd_description())
        emulator.start()
        if emulator.wait_for_start():
            self.log(logging.INFO, "emulator", {},
                     "Android emulator is running.")
        else:
            # This is unusual but the emulator may still function.
            self.log(logging.WARN, "emulator", {},
                     "Unable to verify that emulator is running.")

        if conditions.is_android(self):
            self.log(logging.INFO, "emulator", {},
                     "Use 'mach install' to install or update Firefox on your emulator.")
        else:
            self.log(logging.WARN, "emulator", {},
                     "No Firefox for Android build detected.\n"
                     "Switch to a Firefox for Android build context or use 'mach bootstrap'\n"
                     "to setup an Android build environment.")

        if wait:
            self.log(logging.INFO, "emulator", {},
                     "Waiting for Android emulator to close...")
            rc = emulator.wait()
            if rc is not None:
                self.log(logging.INFO, "emulator", {},
                         "Android emulator completed with return code %d." % rc)
            else:
                self.log(logging.WARN, "emulator", {},
                         "Unable to retrieve Android emulator return code.")
        return 0
Example #28
0
    def emulator(self, version, wait=False, force_update=False, verbose=False):
        from mozrunner.devices.android_device import AndroidEmulator

        emulator = AndroidEmulator(version, verbose, substs=self.substs, device_serial='emulator-5554')
        if emulator.is_running():
            # It is possible to run multiple emulators simultaneously, but:
            #  - if more than one emulator is using the same avd, errors may
            #    occur due to locked resources;
            #  - additional parameters must be specified when running tests,
            #    to select a specific device.
            # To avoid these complications, allow just one emulator at a time.
            self.log(logging.ERROR, "emulator", {},
                     "An Android emulator is already running.\n"
                     "Close the existing emulator and re-run this command.")
            return 1

        if not emulator.is_available():
            self.log(logging.WARN, "emulator", {},
                     "Emulator binary not found.\n"
                     "Install the Android SDK and make sure 'emulator' is in your PATH.")
            return 2

        if not emulator.check_avd(force_update):
            self.log(logging.INFO, "emulator", {},
                     "Fetching and installing AVD. This may take a few minutes...")
            emulator.update_avd(force_update)

        self.log(logging.INFO, "emulator", {},
                 "Starting Android emulator running %s..." %
                 emulator.get_avd_description())
        emulator.start()
        if emulator.wait_for_start():
            self.log(logging.INFO, "emulator", {},
                     "Android emulator is running.")
        else:
            # This is unusual but the emulator may still function.
            self.log(logging.WARN, "emulator", {},
                     "Unable to verify that emulator is running.")

        if conditions.is_android(self):
            self.log(logging.INFO, "emulator", {},
                     "Use 'mach install' to install or update Firefox on your emulator.")
        else:
            self.log(logging.WARN, "emulator", {},
                     "No Firefox for Android build detected.\n"
                     "Switch to a Firefox for Android build context or use 'mach bootstrap'\n"
                     "to setup an Android build environment.")

        if wait:
            self.log(logging.INFO, "emulator", {},
                     "Waiting for Android emulator to close...")
            rc = emulator.wait()
            if rc is not None:
                self.log(logging.INFO, "emulator", {},
                         "Android emulator completed with return code %d." % rc)
            else:
                self.log(logging.WARN, "emulator", {},
                         "Unable to retrieve Android emulator return code.")
        return 0
Example #29
0
 def _run_reftest(self, **kwargs):
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True)
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #30
0
    def run_raptor(self, **kwargs):
        # Defers this import so that a transitive dependency doesn't
        # stop |mach bootstrap| from running
        from raptor.power import enable_charging, disable_charging

        build_obj = self

        is_android = (Conditions.is_android(build_obj)
                      or kwargs["app"] in ANDROID_BROWSERS)

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device,
                InstallIntent,
            )
            from mozdevice import ADBDeviceFactory

            install = (InstallIntent.NO if kwargs.pop("noinstall", False) else
                       InstallIntent.YES)
            verbose = False
            if (kwargs.get("log_mach_verbose")
                    or kwargs.get("log_tbpl_level") == "debug"
                    or kwargs.get("log_mach_level") == "debug"
                    or kwargs.get("log_raw_level") == "debug"):
                verbose = True
            if not verify_android_device(
                    build_obj,
                    install=install,
                    app=kwargs["binary"],
                    verbose=verbose,
                    xre=True,
            ):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = "--debug-command"
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)
        device = None

        try:
            if kwargs["power_test"] and is_android:
                device = ADBDeviceFactory(verbose=True)
                disable_charging(device)
            return raptor.run_test(sys.argv[2:], kwargs)
        except BinaryNotFoundException as e:
            self.log(logging.ERROR, "raptor", {"error": str(e)},
                     "ERROR: {error}")
            self.log(logging.INFO, "raptor", {"help": e.help()}, "{help}")
            return 1
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            if kwargs["power_test"] and device:
                enable_charging(device)
    def __init__(self, app=None, **kwargs):
        ArgumentParser.__init__(self,
                                usage=self.__doc__,
                                conflict_handler='resolve',
                                **kwargs)

        self.oldcwd = os.getcwd()
        self.app = app
        if not self.app and build_obj:
            if conditions.is_android(build_obj):
                self.app = 'android'
            elif conditions.is_b2g(build_obj) or conditions.is_b2g_desktop(
                    build_obj):
                self.app = 'b2g'
        if not self.app:
            # platform can't be determined and app wasn't specified explicitly,
            # so just use generic arguments and hope for the best
            self.app = 'generic'

        if self.app not in container_map:
            self.error("Unrecognized app '{}'! Must be one of: {}".format(
                self.app, ', '.join(container_map.keys())))

        defaults = {}
        for container in self.containers:
            defaults.update(container.defaults)
            group = self.add_argument_group(container.__class__.__name__,
                                            container.__doc__)

            for cli, kwargs in container.args:
                # Allocate new lists so references to original don't get mutated.
                # allowing multiple uses within a single process.
                if "default" in kwargs and isinstance(kwargs['default'], list):
                    kwargs["default"] = []

                if 'suppress' in kwargs:
                    if kwargs['suppress']:
                        kwargs['help'] = SUPPRESS
                    del kwargs['suppress']

                group.add_argument(*cli, **kwargs)

        self.set_defaults(**defaults)
        mozlog.commandline.add_logging_group(self)
Example #32
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest

            m = TestManifest()
            m.tests.extend(test_objects)
            params["manifest"] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests()

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists(".")

        if not params.get("log"):
            log_defaults = {
                self._mach_context.settings["test"]["format"]: sys.stdout
            }
            fmt_defaults = {
                "level": self._mach_context.settings["test"]["level"],
                "verbose": True,
            }
            params["log"] = structured.commandline.setup_logging(
                "XPCShellTests", params, log_defaults, fmt_defaults)

        if not params["threadCount"]:
            # pylint --py3k W1619
            params["threadCount"] = int((cpu_count() * 3) / 2)

        if conditions.is_android(self) or self.substs.get(
                "MOZ_BUILD_APP") == "b2g":
            from mozrunner.devices.android_device import (
                verify_android_device,
                get_adb_path,
            )

            device_serial = params.get("deviceSerial")
            verify_android_device(self,
                                  network=True,
                                  device_serial=device_serial)
            if not params["adbPath"]:
                params["adbPath"] = get_adb_path(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(str(e))
            return 1
Example #33
0
    def run_marionette_test(self, tests, **kwargs):
        if 'test_objects' in kwargs:
            tests = []
            for obj in kwargs['test_objects']:
                tests.append(obj['file_relpath'])
            del kwargs['test_objects']

        if not kwargs.get('binary') and conditions.is_firefox(self):
            kwargs['binary'] = self.get_binary_path('app')
        return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
Example #34
0
    def run_marionette_test(self, tests, **kwargs):
        if "test_objects" in kwargs:
            tests = []
            for obj in kwargs["test_objects"]:
                tests.append(obj["file_relpath"])
            del kwargs["test_objects"]

        if not kwargs.get("binary") and conditions.is_firefox(self):
            kwargs["binary"] = self.get_binary_path("app")
        return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
Example #35
0
    def marionette_test(self, tests, **kwargs):
        if "test_objects" in kwargs:
            tests = []
            for obj in kwargs["test_objects"]:
                tests.append(obj["file_relpath"])
            del kwargs["test_objects"]

        if not kwargs.get("binary") and conditions.is_firefox(self):
            kwargs["binary"] = self.get_binary_path("app")
        return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
Example #36
0
 def _run_reftest(self, **kwargs):
     kwargs["topsrcdir"] = self.topsrcdir
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True, app=kwargs["app"],
                               device_serial=kwargs["deviceSerial"])
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #37
0
    def run_luciddream_test(self, browser_path, b2g_desktop_path, test_paths, consoles, **params):
        # import luciddream lazily as its marionette dependency make ./mach clobber fails
        # early on TBPL
        import luciddream.runluciddream

        # get_binary_path is going to throw if we haven't built any product
        # but luciddream can still be run if we provide both binaries...
        binary_path = False
        try:
            binary_path = self.get_binary_path()
        except Exception:
            pass

        # otherwise, if we have a build, automatically fetch the binary
        if conditions.is_b2g(self):
            if not b2g_desktop_path and binary_path:
                b2g_desktop_path = binary_path
        else:
            if not browser_path and binary_path:
                browser_path = binary_path

        if not browser_path:
            print "Need firefox binary path via --browser_path argument"
            return 1
        elif not os.path.exists(browser_path):
            print "Firefox binary doesn't exists: " + browser_path
            return 1

        if not b2g_desktop_path:
            print "Need b2g desktop binary path via --b2g-desktop argument"
            return 1
        elif not os.path.exists(b2g_desktop_path):
            print "B2G desktop binary doesn't exists: " + b2g_desktop_path
            return 1

        if not test_paths or len(test_paths) == 0:
            print "Please specify a test manifest to run"
            return 1

        browser_args = None
        if consoles:
            browser_args = ["-jsconsole"]
            if "app_args" in params and isinstance(params["app_args"], list):
                params["app_args"].append("-jsconsole")
            else:
                params["app_args"] = ["-jsconsole"]

        for test in test_paths:
            luciddream.runluciddream.run(
                browser_path=browser_path,
                b2g_desktop_path=b2g_desktop_path,
                manifest=test,
                browser_args=browser_args,
                **params
            )
Example #38
0
def marionette_test(command_context, tests, **kwargs):
    if "test_objects" in kwargs:
        tests = []
        for obj in kwargs["test_objects"]:
            tests.append(obj["file_relpath"])
        del kwargs["test_objects"]

    if not tests:
        if conditions.is_thunderbird(command_context):
            tests = [
                os.path.join(
                    command_context.topsrcdir,
                    "comm/testing/marionette/unit-tests.ini",
                )
            ]
        else:
            tests = [
                os.path.join(
                    command_context.topsrcdir,
                    "testing/marionette/harness/marionette_harness/tests/unit-tests.ini",
                )
            ]

    if not kwargs.get("binary") and (
        conditions.is_firefox(command_context)
        or conditions.is_thunderbird(command_context)
    ):
        try:
            kwargs["binary"] = command_context.get_binary_path("app")
        except BinaryNotFoundException as e:
            command_context.log(
                logging.ERROR,
                "marionette-test",
                {"error": str(e)},
                "ERROR: {error}",
            )
            command_context.log(
                logging.INFO, "marionette-test", {"help": e.help()}, "{help}"
            )
            return 1

    return run_marionette(tests, topsrcdir=command_context.topsrcdir, **kwargs)
Example #39
0
    def run_raptor_test(self, **kwargs):

        build_obj = MozbuildObject.from_environment(cwd=HERE)

        firefox_android_browsers = ["fennec", "geckoview", "refbrow", "fenix"]

        if conditions.is_android(
                build_obj) or kwargs['app'] in firefox_android_browsers:
            from mozrunner.devices.android_device import verify_android_device
            from mozdevice import ADBAndroid, ADBHost
            if not verify_android_device(
                    build_obj, install=True, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)

        try:
            if kwargs['app'] in firefox_android_browsers and kwargs[
                    'power_test']:
                device = ADBAndroid(verbose=True)
                adbhost = ADBHost(verbose=True)
                device_serial = "%s:5555" % device.get_ip_address()
                device.command_output(["tcpip", "5555"])
                raw_input(
                    "Please disconnect your device from USB then press Enter/return..."
                )
                adbhost.command_output(["connect", device_serial])
                while len(adbhost.devices()) > 1:
                    raw_input(
                        "You must disconnect your device from USB before continuing."
                    )
                # must reset the environment DEVICE_SERIAL which was set during
                # verify_android_device to match our new tcpip value.
                os.environ["DEVICE_SERIAL"] = device_serial
            return raptor.run_test(sys.argv[2:], kwargs)
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            try:
                if kwargs['app'] in firefox_android_browsers and kwargs[
                        'power_test']:
                    raw_input(
                        "Connect device via USB and press Enter/return...")
                    device = ADBAndroid(device=device_serial, verbose=True)
                    device.command_output(["usb"])
                    adbhost.command_output(["disconnect", device_serial])
            except Exception:
                adbhost.command_output(["kill-server"])
Example #40
0
    def run_luciddream_test(self, browser_path, b2g_desktop_path, test_paths,
                            consoles, **params):
        # import luciddream lazily as its marionette dependency make ./mach clobber fails
        # early on TBPL
        import luciddream.runluciddream

        # get_binary_path is going to throw if we haven't built any product
        # but luciddream can still be run if we provide both binaries...
        binary_path = False
        try:
            binary_path = self.get_binary_path()
        except Exception:
            pass

        # otherwise, if we have a build, automatically fetch the binary
        if conditions.is_b2g(self):
            if not b2g_desktop_path and binary_path:
                b2g_desktop_path = binary_path
        else:
            if not browser_path and binary_path:
                browser_path = binary_path

        if not browser_path:
            print "Need firefox binary path via --browser_path argument"
            return 1
        elif not os.path.exists(browser_path):
            print "Firefox binary doesn't exists: " + browser_path
            return 1

        if not b2g_desktop_path:
            print "Need b2g desktop binary path via --b2g-desktop argument"
            return 1
        elif not os.path.exists(b2g_desktop_path):
            print "B2G desktop binary doesn't exists: " + b2g_desktop_path
            return 1

        if not test_paths or len(test_paths) == 0:
            print "Please specify a test manifest to run"
            return 1

        browser_args = None
        if consoles:
            browser_args = ["-jsconsole"]
            if "app_args" in params and isinstance(params["app_args"], list):
                params["app_args"].append("-jsconsole")
            else:
                params["app_args"] = ["-jsconsole"]

        for test in test_paths:
            luciddream.runluciddream.run(browser_path=browser_path,
                                         b2g_desktop_path=b2g_desktop_path,
                                         manifest=test,
                                         browser_args=browser_args,
                                         **params)
Example #41
0
    def run_raptor(self, **kwargs):
        build_obj = self

        is_android = Conditions.is_android(build_obj) or \
            kwargs['app'] in FIREFOX_ANDROID_BROWSERS

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            from mozdevice import ADBAndroid, ADBHost
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.PROMPT
            if not verify_android_device(
                    build_obj, install=install, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)

        try:
            if is_android and kwargs['power_test']:
                device = ADBAndroid(verbose=True)
                adbhost = ADBHost(verbose=True)
                device_serial = "{}:5555".format(device.get_ip_address())
                device.command_output(["tcpip", "5555"])
                six.input(
                    "Please disconnect your device from USB then press Enter/return..."
                )
                adbhost.command_output(["connect", device_serial])
                while len(adbhost.devices()) > 1:
                    six.input(
                        "You must disconnect your device from USB before continuing."
                    )
                # must reset the environment DEVICE_SERIAL which was set during
                # verify_android_device to match our new tcpip value.
                os.environ["DEVICE_SERIAL"] = device_serial
            return raptor.run_test(sys.argv[2:], kwargs)
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            try:
                if is_android and kwargs['power_test']:
                    six.input(
                        "Connect device via USB and press Enter/return...")
                    device = ADBAndroid(device=device_serial, verbose=True)
                    device.command_output(["usb"])
                    adbhost.command_output(["disconnect", device_serial])
            except Exception:
                adbhost.command_output(["kill-server"])
Example #42
0
 def telemetry_test(self, tests, **kwargs):
     if "test_objects" in kwargs:
         tests = []
         for obj in kwargs["test_objects"]:
             tests.append(obj["file_relpath"])
         del kwargs["test_objects"]
     if not kwargs.get("binary") and conditions.is_firefox(self):
         kwargs["binary"] = self.get_binary_path("app")
     if not kwargs.get("server_root"):
         kwargs[
             "server_root"] = "toolkit/components/telemetry/tests/marionette/harness/www"
     return run_telemetry(tests, topsrcdir=self.topsrcdir, **kwargs)
Example #43
0
    def _make_artifacts(self, tree=None, job=None, skip_cache=False,
                        download_tests=True, download_symbols=False,
                        download_host_bins=False,
                        download_maven_zip=False,
                        no_process=False):
        state_dir = self._mach_context.state_dir
        cache_dir = os.path.join(state_dir, 'package-frontend')

        hg = None
        if conditions.is_hg(self):
            hg = self.substs['HG']

        git = None
        if conditions.is_git(self):
            git = self.substs['GIT']

        # If we're building Thunderbird, we should be checking for comm-central artifacts.
        topsrcdir = self.substs.get('commtopsrcdir', self.topsrcdir)

        if download_maven_zip:
            if download_tests:
                raise ValueError('--maven-zip requires --no-tests')
            if download_symbols:
                raise ValueError('--maven-zip requires no --symbols')
            if download_host_bins:
                raise ValueError('--maven-zip requires no --host-bins')
            if not no_process:
                raise ValueError('--maven-zip requires --no-process')

        from mozbuild.artifacts import Artifacts
        artifacts = Artifacts(tree, self.substs, self.defines, job,
                              log=self.log, cache_dir=cache_dir,
                              skip_cache=skip_cache, hg=hg, git=git,
                              topsrcdir=topsrcdir,
                              download_tests=download_tests,
                              download_symbols=download_symbols,
                              download_host_bins=download_host_bins,
                              download_maven_zip=download_maven_zip,
                              no_process=no_process)
        return artifacts
    def __init__(self, app=None, **kwargs):
        ArgumentParser.__init__(self, usage=self.__doc__, conflict_handler='resolve', **kwargs)

        self.oldcwd = os.getcwd()
        self.app = app
        if not self.app and build_obj:
            if conditions.is_android(build_obj):
                self.app = 'android'
            elif conditions.is_b2g(build_obj) or conditions.is_b2g_desktop(build_obj):
                self.app = 'b2g'
        if not self.app:
            # platform can't be determined and app wasn't specified explicitly,
            # so just use generic arguments and hope for the best
            self.app = 'generic'

        if self.app not in container_map:
            self.error("Unrecognized app '{}'! Must be one of: {}".format(
                self.app, ', '.join(container_map.keys())))

        defaults = {}
        for container in self.containers:
            defaults.update(container.defaults)
            group = self.add_argument_group(container.__class__.__name__, container.__doc__)

            for cli, kwargs in container.args:
                # Allocate new lists so references to original don't get mutated.
                # allowing multiple uses within a single process.
                if "default" in kwargs and isinstance(kwargs['default'], list):
                    kwargs["default"] = []

                if 'suppress' in kwargs:
                    if kwargs['suppress']:
                        kwargs['help'] = SUPPRESS
                    del kwargs['suppress']

                group.add_argument(*cli, **kwargs)

        self.set_defaults(**defaults)
        structured.commandline.add_logging_group(self)
Example #45
0
    def run_marionette_test(self, tests, **kwargs):
        if 'test_objects' in kwargs:
            tests = []
            for obj in kwargs['test_objects']:
                tests.append(obj['file_relpath'])
            del kwargs['test_objects']

        if conditions.is_firefox(self):
            bin_path = self.get_binary_path('app')
            if kwargs.get('binary') is not None:
                print "Warning: ignoring '--binary' option, using binary at " + bin_path
            kwargs['binary'] = bin_path
        return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
Example #46
0
 def _run_reftest(self, **kwargs):
     kwargs["topsrcdir"] = self.topsrcdir
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     # Unstructured logging must be enabled prior to calling
     # adb which uses an unstructured logger in its constructor.
     reftest.log_manager.enable_unstructured()
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True, network=True,
                               app=kwargs["app"], device_serial=kwargs["deviceSerial"])
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #47
0
    def run_marionette_test(self, tests, **kwargs):
        print >> sys.stderr, ("warning: ./mach marionette-test is deprecated; "
                              "please use ./mach marionette test")

        if "test_objects" in kwargs:
            tests = []
            for obj in kwargs["test_objects"]:
                tests.append(obj["file_relpath"])
            del kwargs["test_objects"]

        if not kwargs.get("binary") and conditions.is_firefox(self):
            kwargs["binary"] = self.get_binary_path("app")
        return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
    def run_b2g_test(self, b2g_home=None, xre_path=None, **kwargs):
        """Runs a b2g reftest.

        filter is a regular expression (in JS syntax, as could be passed to the
        RegExp constructor) to select which reftests to run from the manifest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.

        suite is the type of reftest to run. It can be one of ('reftest',
        'crashtest').
        """
        if kwargs["suite"] not in ('reftest', 'crashtest'):
            raise Exception('None or unrecognized reftest suite type.')

        sys.path.insert(0, self.reftest_dir)

        test_subdir = {"reftest": os.path.join('layout', 'reftests'),
                       "crashtest": os.path.join('layout', 'crashtest')}[kwargs["suite"]]

        # Find the manifest file
        if not kwargs["tests"]:
            if not os.path.exists(os.path.join(self.topsrcdir, test_subdir)):
                test_file = mozpath.relpath(os.path.abspath(test_subdir),
                                            self.topsrcdir)
            kwargs["tests"] = [test_subdir]

        tests = os.path.join(self.reftest_dir, 'tests')
        if not os.path.isdir(tests):
            os.symlink(self.topsrcdir, tests)

        for i, path in enumerate(kwargs["tests"]):
            # Non-absolute paths are relative to the packaged directory, which
            # has an extra tests/ at the start
            if os.path.exists(os.path.abspath(path)):
                path = os.path.relpath(path, os.path.join(self.topsrcdir))
            kwargs["tests"][i] = os.path.join('tests', path)

        if conditions.is_b2g_desktop(self):
            return self.run_b2g_desktop(**kwargs)

        return self.run_b2g_remote(b2g_home, xre_path, **kwargs)
Example #49
0
    def run_awsy_test(self, tests, **kwargs):
        """mach awsy-test runs the in-tree version of the Are We Slim Yet
        (AWSY) tests.

        awsy-test is implemented as a marionette test and marionette
        test arguments also apply although they are not necessary
        since reasonable defaults will be chosen.

        The AWSY specific arguments can be found in the Command
        Arguments for AWSY section below.

        awsy-test will automatically download the tp5n.zip talos
        pageset from tooltool and install it under
        topobjdir/_tests/awsy/html. You can specify your own page set
        by specifying --web-root and --page-manifest.

        The results of the test will be placed in the results
        directory specified by the --results argument.

        On Windows, you may experience problems due to path length
        errors when extracting the tp5n.zip file containing the
        test pages or when attempting to write checkpoints to the
        results directory. In that case, you should specify both
        the --web-root and --results arguments pointing to a location
        with a short path. For example:

        --web-root=c:\\\\tmp\\\\html --results=c:\\\\tmp\\\\results

        Note that the double backslashes are required.
        """
        kwargs['logger_name'] = 'Awsy Tests'
        if 'test_objects' in kwargs:
            tests = []
            for obj in kwargs['test_objects']:
                tests.append(obj['file_relpath'])
            del kwargs['test_objects']

        if not kwargs.get('binary') and conditions.is_firefox(self):
            kwargs['binary'] = self.get_binary_path('app')
        return self.run_awsy(tests, **kwargs)
Example #50
0
    def run_b2g_test(self, test_paths=None, b2g_home=None, xre_path=None,
                     total_chunks=None, this_chunk=None, no_window=None,
                     **kwargs):
        """Runs a b2g mochitest.

        test_paths is an enumerable of paths to tests. It can be a relative path
        from the top source directory, an absolute filename, or a directory
        containing test files.
        """
        # Need to call relpath before os.chdir() below.
        test_path = ''
        if test_paths:
            if len(test_paths) > 1:
                print('Warning: Only the first test path will be used.')
            test_path = self._wrap_path_argument(test_paths[0]).relpath()

        # TODO without os.chdir, chained imports fail below
        os.chdir(self.mochitest_dir)

        # The imp module can spew warnings if the modules below have
        # already been imported, ignore them.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')

            import imp
            path = os.path.join(self.mochitest_dir, 'runtestsb2g.py')
            with open(path, 'r') as fh:
                imp.load_module('mochitest', fh, path,
                    ('.py', 'r', imp.PY_SOURCE))

            import mochitest
            from mochitest_options import B2GOptions

        parser = B2GOptions()
        options = parser.parse_args([])[0]

        test_path_dir = False;
        if test_path:
            test_root_file = mozpack.path.join(self.mochitest_dir, 'tests', test_path)
            if not os.path.exists(test_root_file):
                print('Specified test path does not exist: %s' % test_root_file)
                return 1
            if os.path.isdir(test_root_file):
                test_path_dir = True;
            options.testPath = test_path

        for k, v in kwargs.iteritems():
            setattr(options, k, v)
        options.noWindow = no_window
        options.totalChunks = total_chunks
        options.thisChunk = this_chunk

        options.symbolsPath = os.path.join(self.distdir, 'crashreporter-symbols')

        options.consoleLevel = 'INFO'
        if conditions.is_b2g_desktop(self):

            options.profile = options.profile or os.environ.get('GAIA_PROFILE')
            if not options.profile:
                print(GAIA_PROFILE_NOT_FOUND % 'mochitest-b2g-desktop')
                return 1

            if os.path.isfile(os.path.join(options.profile, 'extensions', \
                    '*****@*****.**')):
                print(GAIA_PROFILE_IS_DEBUG % ('mochitest-b2g-desktop',
                                               options.profile))
                return 1

            options.desktop = True
            options.app = self.get_binary_path()
            if not options.app.endswith('-bin'):
                options.app = '%s-bin' % options.app
            if not os.path.isfile(options.app):
                options.app = options.app[:-len('-bin')]

            return mochitest.run_desktop_mochitests(parser, options)

        try:
            which.which('adb')
        except which.WhichError:
            # TODO Find adb automatically if it isn't on the path
            print(ADB_NOT_FOUND % ('mochitest-remote', b2g_home))
            return 1

        options.b2gPath = b2g_home
        options.logcat_dir = self.mochitest_dir
        options.httpdPath = self.mochitest_dir
        options.xrePath = xre_path
        return mochitest.run_remote_mochitests(parser, options)
Example #51
0
    def run_b2g_test(self, b2g_home=None, xre_path=None, test_file=None,
                     suite=None, **kwargs):
        """Runs a b2g reftest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.

        suite is the type of reftest to run. It can be one of ('reftest',
        'crashtest').
        """
        if suite not in ('reftest', 'crashtest'):
            raise Exception('None or unrecognized reftest suite type.')

        # Find the manifest file
        if not test_file:
            if suite == 'reftest':
                test_file = mozpack.path.join('layout', 'reftests')
            elif suite == 'crashtest':
                test_file = mozpack.path.join('testing', 'crashtest')

        if not os.path.exists(os.path.join(self.topsrcdir, test_file)):
            test_file = mozpack.path.relpath(os.path.abspath(test_file),
                                             self.topsrcdir)

        manifest = self._find_manifest(suite, test_file)
        if not os.path.exists(mozpack.path.join(self.topsrcdir, manifest)):
            raise Exception('No manifest file was found at %s.' % manifest)

        # Need to chdir to reftest_dir otherwise imports fail below.
        os.chdir(self.reftest_dir)

        # The imp module can spew warnings if the modules below have
        # already been imported, ignore them.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')

            import imp
            path = os.path.join(self.reftest_dir, 'runreftestb2g.py')
            with open(path, 'r') as fh:
                imp.load_module('reftest', fh, path, ('.py', 'r', imp.PY_SOURCE))
            import reftest

        # Set up the reftest options.
        parser = reftest.B2GOptions()
        options, args = parser.parse_args([])

        # Tests need to be served from a subdirectory of the server. Symlink
        # topsrcdir here to get around this.
        tests = os.path.join(self.reftest_dir, 'tests')
        if not os.path.isdir(tests):
            os.symlink(self.topsrcdir, tests)
        args.insert(0, os.path.join('tests', manifest))

        for k, v in kwargs.iteritems():
            setattr(options, k, v)

        if conditions.is_b2g_desktop(self):
            if self.substs.get('ENABLE_MARIONETTE') != '1':
                print(MARIONETTE_DISABLED % ('mochitest-b2g-desktop',
                                             self.mozconfig['path']))
                return 1

            options.profile = options.profile or os.environ.get('GAIA_PROFILE')
            if not options.profile:
                print(GAIA_PROFILE_NOT_FOUND % 'reftest-b2g-desktop')
                return 1

            if os.path.isfile(os.path.join(options.profile, 'extensions', \
                    '*****@*****.**')):
                print(GAIA_PROFILE_IS_DEBUG % ('mochitest-b2g-desktop',
                                               options.profile))
                return 1

            options.desktop = True
            options.app = self.get_binary_path()
            if options.oop:
                options.browser_arg = '-oop'
            if not options.app.endswith('-bin'):
                options.app = '%s-bin' % options.app
            if not os.path.isfile(options.app):
                options.app = options.app[:-len('-bin')]

            return reftest.run_desktop_reftests(parser, options, args)


        try:
            which.which('adb')
        except which.WhichError:
            # TODO Find adb automatically if it isn't on the path
            raise Exception(ADB_NOT_FOUND % ('%s-remote' % suite, b2g_home))

        options.b2gPath = b2g_home
        options.logcat_dir = self.reftest_dir
        options.httpdPath = os.path.join(self.topsrcdir, 'netwerk', 'test', 'httpserver')
        options.xrePath = xre_path
        options.ignoreWindowSize = True

        # Don't enable oop for crashtest until they run oop in automation
        if suite == 'reftest':
            options.oop = True

        return reftest.run_remote_reftests(parser, options, args)
    def validate(self, parser, options, context):
        """Validate b2g options."""

        if options.desktop and not options.app:
            if not (build_obj and conditions.is_b2g_desktop(build_obj)):
                parser.error(
                    "--desktop specified, but no b2g desktop build detected! Either "
                    "build for b2g desktop, or point --appname to a b2g desktop binary.")
        elif build_obj and conditions.is_b2g_desktop(build_obj):
            options.desktop = True
            if not options.app:
                options.app = build_obj.get_binary_path()
                if not options.app.endswith('-bin'):
                    options.app = '%s-bin' % options.app
                if not os.path.isfile(options.app):
                    options.app = options.app[:-len('-bin')]

        if options.remoteWebServer is None:
            if os.name != "nt":
                options.remoteWebServer = moznetwork.get_ip()
            else:
                parser.error(
                    "You must specify a --remote-webserver=<ip address>")
        options.webServer = options.remoteWebServer

        if not options.b2gPath and hasattr(context, 'b2g_home'):
            options.b2gPath = context.b2g_home

        if hasattr(context, 'device_name') and not options.emulator:
            if context.device_name.startswith('emulator'):
                options.emulator = 'x86' if 'x86' in context.device_name else 'arm'

        if options.geckoPath and not options.emulator:
            parser.error(
                "You must specify --emulator if you specify --gecko-path")

        if options.logdir and not options.emulator:
            parser.error("You must specify --emulator if you specify --logdir")
        elif not options.logdir and options.emulator and build_obj:
            options.logdir = os.path.join(
                build_obj.topobjdir, '_tests', 'testing', 'mochitest')

        if hasattr(context, 'xre_path'):
            options.xrePath = context.xre_path

        if not os.path.isdir(options.xrePath):
            parser.error("--xre-path '%s' is not a directory" % options.xrePath)

        xpcshell = os.path.join(options.xrePath, 'xpcshell')
        if not os.access(xpcshell, os.F_OK):
            parser.error('xpcshell not found at %s' % xpcshell)

        if self.elf_arm(xpcshell):
            parser.error('--xre-path points to an ARM version of xpcshell; it '
                         'should instead point to a version that can run on '
                         'your desktop')

        if not options.httpdPath and build_obj:
            options.httpdPath = os.path.join(
                build_obj.topobjdir, '_tests', 'testing', 'mochitest')

        # Bug 1071866 - B2G Mochitests do not always produce a leak log.
        options.ignoreMissingLeaks.append("default")
        # Bug 1070068 - Leak logging does not work for tab processes on B2G.
        options.ignoreMissingLeaks.append("tab")

        if options.pidFile != "":
            f = open(options.pidFile, 'w')
            f.write("%s" % os.getpid())
            f.close()

        return options
Example #53
0
def is_platform_supported(cls):
    """Must have a Firefox, Android or B2G build."""
    return conditions.is_android(cls) or \
           conditions.is_b2g(cls) or \
           conditions.is_firefox(cls)
Example #54
0
def config_status(topobjdir='.', topsrcdir='.', defines=None,
                  non_global_defines=None, substs=None, source=None,
                  mozconfig=None):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
            'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
            'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
            '%s' % topsrcdir)

    default_backends = ['RecursiveMake']
    default_backends = (substs or {}).get('BUILD_BACKENDS', ['RecursiveMake'])

    parser = ArgumentParser()
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
                        help='display verbose output')
    parser.add_argument('-n', dest='not_topobjdir', action='store_true',
                        help='do not consider current directory as top object directory')
    parser.add_argument('-d', '--diff', action='store_true',
                        help='print diffs of changed files.')
    parser.add_argument('-b', '--backend', nargs='+', choices=sorted(backends),
                        default=default_backends,
                        help='what backend to build (default: %s).' %
                        ' '.join(default_backends))
    parser.add_argument('--dry-run', action='store_true',
                        help='do everything except writing files out.')
    options = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir, topobjdir, defines=defines,
            non_global_defines=non_global_defines, substs=substs,
            source=source, mozconfig=mozconfig)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    cpu_start = time.clock()
    time_start = time.time()

    # Make appropriate backend instances, defaulting to RecursiveMakeBackend,
    # or what is in BUILD_BACKENDS.
    selected_backends = [get_backend_class(b)(env) for b in options.backend]

    if options.dry_run:
        for b in selected_backends:
            b.dry_run = True

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Reticulating splines...', file=sys.stderr)
    if len(selected_backends) > 1:
        definitions = list(definitions)

    for the_backend in selected_backends:
        the_backend.consume(definitions)

    execution_time = 0.0
    for obj in chain((reader, emitter), selected_backends):
        summary = obj.summary()
        print(summary, file=sys.stderr)
        execution_time += summary.execution_time

    cpu_time = time.clock() - cpu_start
    wall_time = time.time() - time_start
    efficiency = cpu_time / wall_time if wall_time else 100
    untracked = wall_time - execution_time

    print(
        'Total wall time: {:.2f}s; CPU time: {:.2f}s; Efficiency: '
        '{:.0%}; Untracked: {:.2f}s'.format(
            wall_time, cpu_time, efficiency, untracked),
        file=sys.stderr
    )

    if options.diff:
        for the_backend in selected_backends:
            for path, diff in sorted(the_backend.file_diffs.items()):
                print('\n'.join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == 'nt' and 'VisualStudio' not in options.backend:
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Eclipse if it is appropriate.
    if MachCommandConditions.is_android(env):
        if 'AndroidEclipse' not in options.backend:
            print(ANDROID_IDE_ADVERTISEMENT)
    def run_b2g_test(
        self, test_file=None, b2g_home=None, xre_path=None, total_chunks=None, this_chunk=None, no_window=None, **kwargs
    ):
        """Runs a b2g mochitest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.
        """
        # Need to call relpath before os.chdir() below.
        test_path = ""
        if test_file:
            test_path = self._wrap_path_argument(test_file).relpath()

        # TODO without os.chdir, chained imports fail below
        os.chdir(self.mochitest_dir)

        # The imp module can spew warnings if the modules below have
        # already been imported, ignore them.
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")

            import imp

            path = os.path.join(self.mochitest_dir, "runtestsb2g.py")
            with open(path, "r") as fh:
                imp.load_module("mochitest", fh, path, (".py", "r", imp.PY_SOURCE))

            import mochitest
            from mochitest_options import B2GOptions

        parser = B2GOptions()
        options = parser.parse_args([])[0]

        if test_path:
            test_root_file = mozpack.path.join(self.mochitest_dir, "tests", test_path)
            if not os.path.exists(test_root_file):
                print("Specified test path does not exist: %s" % test_root_file)
                return 1
            options.testPath = test_path
        elif conditions.is_b2g_desktop(self):
            options.testManifest = "b2g-desktop.json"
        else:
            options.testManifest = "b2g.json"

        for k, v in kwargs.iteritems():
            setattr(options, k, v)
        options.noWindow = no_window
        options.totalChunks = total_chunks
        options.thisChunk = this_chunk

        options.symbolsPath = os.path.join(self.distdir, "crashreporter-symbols")

        options.consoleLevel = "INFO"
        if conditions.is_b2g_desktop(self):
            if self.substs.get("ENABLE_MARIONETTE") != "1":
                print(MARIONETTE_DISABLED % ("mochitest-b2g-desktop", self.mozconfig["path"]))
                return 1

            options.profile = options.profile or os.environ.get("GAIA_PROFILE")
            if not options.profile:
                print(GAIA_PROFILE_NOT_FOUND % "mochitest-b2g-desktop")
                return 1

            if os.path.isfile(os.path.join(options.profile, "extensions", "*****@*****.**")):
                print(GAIA_PROFILE_IS_DEBUG % ("mochitest-b2g-desktop", options.profile))
                return 1

            options.desktop = True
            options.app = self.get_binary_path()
            if not options.app.endswith("-bin"):
                options.app = "%s-bin" % options.app
            if not os.path.isfile(options.app):
                options.app = options.app[: -len("-bin")]

            return mochitest.run_desktop_mochitests(parser, options)

        try:
            which.which("adb")
        except which.WhichError:
            # TODO Find adb automatically if it isn't on the path
            print(ADB_NOT_FOUND % ("mochitest-remote", b2g_home))
            return 1

        options.b2gPath = b2g_home
        options.logcat_dir = self.mochitest_dir
        options.httpdPath = self.mochitest_dir
        options.xrePath = xre_path
        return mochitest.run_remote_mochitests(parser, options)
    def run_b2g_test(self, test_file=None, b2g_home=None, xre_path=None, **kwargs):
        """Runs a b2g mochitest.

        test_file is a path to a test file. It can be a relative path from the
        top source directory, an absolute filename, or a directory containing
        test files.
        """
        # Need to call relpath before os.chdir() below.
        test_path = ''
        if test_file:
            test_path = self._wrap_path_argument(test_file).relpath()

        # TODO without os.chdir, chained imports fail below
        os.chdir(self.mochitest_dir)

        # The imp module can spew warnings if the modules below have
        # already been imported, ignore them.
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')

            import imp
            path = os.path.join(self.mochitest_dir, 'runtestsb2g.py')
            with open(path, 'r') as fh:
                imp.load_module('mochitest', fh, path,
                    ('.py', 'r', imp.PY_SOURCE))

            import mochitest
            from mochitest_options import B2GOptions

        parser = B2GOptions()
        options = parser.parse_args([])[0]

        if test_path:
            test_root_file = mozpack.path.join(self.mochitest_dir, 'tests', test_path)
            if not os.path.exists(test_root_file):
                print('Specified test path does not exist: %s' % test_root_file)
                return 1
            options.testPath = test_path
        else:
            options.testManifest = 'b2g.json'

        for k, v in kwargs.iteritems():
            setattr(options, k, v)

        options.consoleLevel = 'INFO'
        if conditions.is_b2g_desktop(self):
            if self.substs.get('ENABLE_MARIONETTE') != '1':
                print(MARIONETTE_DISABLED % ('mochitest-b2g-desktop',
                                             self.mozconfig['path']))
                return 1

            options.profile = options.profile or os.environ.get('GAIA_PROFILE')
            if not options.profile:
                print(GAIA_PROFILE_NOT_FOUND % 'mochitest-b2g-desktop')
                return 1

            if os.path.isfile(os.path.join(options.profile, 'extensions', \
                    '*****@*****.**')):
                print(GAIA_PROFILE_IS_DEBUG % ('mochitest-b2g-desktop',
                                               options.profile))
                return 1

            options.desktop = True
            options.app = self.get_binary_path()
            if not options.app.endswith('-bin'):
                options.app = '%s-bin' % options.app
            if not os.path.isfile(options.app):
                options.app = options.app[:-len('-bin')]

            return mochitest.run_desktop_mochitests(parser, options)

        try:
            which.which('adb')
        except which.WhichError:
            # TODO Find adb automatically if it isn't on the path
            print(ADB_NOT_FOUND % ('mochitest-remote', b2g_home))
            return 1

        options.b2gPath = b2g_home
        options.logcat_dir = self.mochitest_dir
        options.httpdPath = self.mochitest_dir
        options.xrePath = xre_path
        return mochitest.run_remote_mochitests(parser, options)
Example #57
0
def is_firefox_or_android(cls):
    """Must have Firefox build or Android build."""
    return conditions.is_firefox(cls) or conditions.is_android(cls)
Example #58
0
def config_status(topobjdir='.', topsrcdir='.',
        defines=[], non_global_defines=[], substs=[], source=None):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The --recheck option, like with the original config.status, runs configure
    again, with the options given in the "ac_configure_args" subst.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
            'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
            'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
            '%s' % topsrcdir)

    default_backends = ['RecursiveMake']
    # We have a chicken/egg problem, where we only have a dict for substs after
    # creating the ConfigEnvironment, which requires argument parsing to have
    # occurred.
    for name, value in substs:
        if name == 'BUILD_BACKENDS':
            default_backends = value
            break

    parser = ArgumentParser()
    parser.add_argument('--recheck', dest='recheck', action='store_true',
                        help='update config.status by reconfiguring in the same conditions')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
                        help='display verbose output')
    parser.add_argument('-n', dest='not_topobjdir', action='store_true',
                        help='do not consider current directory as top object directory')
    parser.add_argument('-d', '--diff', action='store_true',
                        help='print diffs of changed files.')
    parser.add_argument('-b', '--backend', nargs='+',
                        choices=['RecursiveMake', 'AndroidEclipse', 'CppEclipse',
                                 'VisualStudio', 'FasterMake', 'CompileDB'],
                        default=default_backends,
                        help='what backend to build (default: %s).' %
                        ' '.join(default_backends))
    options = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir, topobjdir, defines=defines,
            non_global_defines=non_global_defines, substs=substs, source=source)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    # Make an appropriate backend instance, defaulting to RecursiveMakeBackend.
    backends_cls = []
    for backend in options.backend:
        if backend == 'AndroidEclipse':
            from mozbuild.backend.android_eclipse import AndroidEclipseBackend
            if not MachCommandConditions.is_android(env):
                raise Exception('The Android Eclipse backend is not available with this configuration.')
            backends_cls.append(AndroidEclipseBackend)
        elif backend == 'CppEclipse':
            from mozbuild.backend.cpp_eclipse import CppEclipseBackend
            backends_cls.append(CppEclipseBackend)
            if os.name == 'nt':
              raise Exception('Eclipse is not supported on Windows. Consider using Visual Studio instead.')
        elif backend == 'VisualStudio':
            from mozbuild.backend.visualstudio import VisualStudioBackend
            backends_cls.append(VisualStudioBackend)
        elif backend == 'FasterMake':
            from mozbuild.backend.fastermake import FasterMakeBackend
            backends_cls.append(FasterMakeBackend)
        elif backend == 'CompileDB':
            from mozbuild.compilation.database import CompileDBBackend
            backends_cls.append(CompileDBBackend)
        else:
            backends_cls.append(RecursiveMakeBackend)

    cpu_start = time.clock()
    time_start = time.time()

    backends = [cls(env) for cls in backends_cls]

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    if options.recheck:
        # Execute configure from the top object directory
        os.chdir(topobjdir)
        os.execlp('sh', 'sh', '-c', ' '.join([os.path.join(topsrcdir, 'configure'), env.substs['ac_configure_args'], '--no-create', '--no-recursion']))

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Reticulating splines...', file=sys.stderr)
    if len(backends) > 1:
        definitions = list(definitions)

    for the_backend in backends:
        the_backend.consume(definitions)

    execution_time = 0.0
    for obj in chain((reader, emitter), backends):
        summary = obj.summary()
        print(summary, file=sys.stderr)
        execution_time += summary.execution_time

    cpu_time = time.clock() - cpu_start
    wall_time = time.time() - time_start
    efficiency = cpu_time / wall_time if wall_time else 100
    untracked = wall_time - execution_time

    print(
        'Total wall time: {:.2f}s; CPU time: {:.2f}s; Efficiency: '
        '{:.0%}; Untracked: {:.2f}s'.format(
            wall_time, cpu_time, efficiency, untracked),
        file=sys.stderr
    )

    if options.diff:
        for the_backend in backends:
            for path, diff in sorted(the_backend.file_diffs.items()):
                print('\n'.join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == 'nt' and 'VisualStudio' not in options.backend:
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Eclipse if it is appropriate.
    if MachCommandConditions.is_android(env):
        if 'AndroidEclipse' not in options.backend:
            print(ANDROID_IDE_ADVERTISEMENT)

    if env.substs.get('MOZ_ARTIFACT_BUILDS', False):
        # Execute |mach artifact install| from the top source directory.
        os.chdir(topsrcdir)
        return subprocess.check_call([sys.executable, os.path.join(topsrcdir, 'mach'), 'artifact', 'install'])
Example #59
0
def config_status(topobjdir='.', topsrcdir='.',
        defines=[], non_global_defines=[], substs=[], source=None):
    '''Main function, providing config.status functionality.

    Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
    variables.

    Without the -n option, this program acts as config.status and considers
    the current directory as the top object directory, even when config.status
    is in a different directory. It will, however, treat the directory
    containing config.status as the top object directory with the -n option.

    The --recheck option, like with the original config.status, runs configure
    again, with the options given in the "ac_configure_args" subst.

    The options to this function are passed when creating the
    ConfigEnvironment. These lists, as well as the actual wrapper script
    around this function, are meant to be generated by configure.
    See build/autoconf/config.status.m4.
    '''

    if 'CONFIG_FILES' in os.environ:
        raise Exception('Using the CONFIG_FILES environment variable is not '
            'supported.')
    if 'CONFIG_HEADERS' in os.environ:
        raise Exception('Using the CONFIG_HEADERS environment variable is not '
            'supported.')

    if not os.path.isabs(topsrcdir):
        raise Exception('topsrcdir must be defined as an absolute directory: '
            '%s' % topsrcdir)

    parser = OptionParser()
    parser.add_option('--recheck', dest='recheck', action='store_true',
                      help='update config.status by reconfiguring in the same conditions')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      help='display verbose output')
    parser.add_option('-n', dest='not_topobjdir', action='store_true',
                      help='do not consider current directory as top object directory')
    parser.add_option('-d', '--diff', action='store_true',
                      help='print diffs of changed files.')
    parser.add_option('-b', '--backend',
                      choices=['RecursiveMake', 'AndroidEclipse', 'CppEclipse', 'VisualStudio'],
                      default='RecursiveMake',
                      help='what backend to build (default: RecursiveMake).')
    options, args = parser.parse_args()

    # Without -n, the current directory is meant to be the top object directory
    if not options.not_topobjdir:
        topobjdir = os.path.abspath('.')

    env = ConfigEnvironment(topsrcdir, topobjdir, defines=defines,
            non_global_defines=non_global_defines, substs=substs, source=source)

    # mozinfo.json only needs written if configure changes and configure always
    # passes this environment variable.
    if 'WRITE_MOZINFO' in os.environ:
        write_mozinfo(os.path.join(topobjdir, 'mozinfo.json'), env, os.environ)

    # Make an appropriate backend instance, defaulting to RecursiveMakeBackend.
    backend_cls = RecursiveMakeBackend
    if options.backend == 'AndroidEclipse':
        from mozbuild.backend.android_eclipse import AndroidEclipseBackend
        if not MachCommandConditions.is_android(env):
            raise Exception('The Android Eclipse backend is not available with this configuration.')
        backend_cls = AndroidEclipseBackend
    elif options.backend == 'CppEclipse':
        from mozbuild.backend.cpp_eclipse import CppEclipseBackend
        backend_cls = CppEclipseBackend
        if os.name == 'nt':
          raise Exception('Eclipse is not supported on Windows. Consider using Visual Studio instead.')
    elif options.backend == 'VisualStudio':
        from mozbuild.backend.visualstudio import VisualStudioBackend
        backend_cls = VisualStudioBackend

    the_backend = backend_cls(env)

    reader = BuildReader(env)
    emitter = TreeMetadataEmitter(env)
    # This won't actually do anything because of the magic of generators.
    definitions = emitter.emit(reader.read_topsrcdir())

    if options.recheck:
        # Execute configure from the top object directory
        os.chdir(topobjdir)
        os.execlp('sh', 'sh', '-c', ' '.join([os.path.join(topsrcdir, 'configure'), env.substs['ac_configure_args'], '--no-create', '--no-recursion']))

    log_level = logging.DEBUG if options.verbose else logging.INFO
    log_manager.add_terminal_logging(level=log_level)
    log_manager.enable_unstructured()

    print('Reticulating splines...', file=sys.stderr)
    summary = the_backend.consume(definitions)

    for line in summary.summaries():
        print(line, file=sys.stderr)

    if options.diff:
        for path, diff in sorted(summary.file_diffs.items()):
            print('\n'.join(diff))

    # Advertise Visual Studio if appropriate.
    if os.name == 'nt' and options.backend == 'RecursiveMake':
        print(VISUAL_STUDIO_ADVERTISEMENT)

    # Advertise Eclipse if it is appropriate.
    if MachCommandConditions.is_android(env):
        if options.backend == 'RecursiveMake':
            print(ANDROID_IDE_ADVERTISEMENT)