示例#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)

        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
示例#2
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)
示例#3
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
示例#4
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
示例#5
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
示例#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()
    else:
        return reftestcommandline.DesktopArgumentsParser()
示例#7
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)
示例#8
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)
示例#9
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
示例#10
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)
示例#11
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()
示例#12
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)
示例#13
0
def get_parser():
    global parser
    here = os.path.abspath(os.path.dirname(__file__))
    build_obj = MozbuildObject.from_environment(cwd=here)
    if conditions.is_android(build_obj):
        parser = reftestcommandline.RemoteArgumentsParser()
    else:
        parser = reftestcommandline.DesktopArgumentsParser()
    return parser
示例#14
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)
示例#15
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)
示例#16
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)
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
示例#17
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)
示例#18
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
示例#19
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"])
示例#20
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"])
示例#21
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)
    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 ADBAndroid
            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 = ADBAndroid(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)
示例#23
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('.')

        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']:
            params['threadCount'] = int((cpu_count() * 3) / 2)

        if conditions.is_android(self):
            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(e.message)
            return 1
示例#24
0
    def run_web_platform_tests(self, **params):
        self.setup()
        if conditions.is_android(self) and params["product"] != "fennec":
            if params["product"] is None:
                params["product"] = "fennec"
            else:
                raise ValueError("Must specify --product=fennec in Android environment.")
        if "test_objects" in params:
            for item in params["test_objects"]:
                params["include"].append(item["name"])
            del params["test_objects"]

        wpt_setup = self._spawn(WebPlatformTestsRunnerSetup)
        wpt_runner = WebPlatformTestsRunner(wpt_setup)
        return wpt_runner.run(**params)
示例#25
0
    def run_web_platform_tests(self, command_context, **params):
        self.setup()
        if params["product"] is None:
            if conditions.is_android(self):
                params["product"] = "firefox_android"
            else:
                params["product"] = "firefox"
        if "test_objects" in params:
            include = []
            test_types = set()
            for item in params["test_objects"]:
                include.append(item["name"])
                test_types.add(item.get("subsuite"))
            if None not in test_types:
                params["test_types"] = list(test_types)
            params["include"] = include
            del params["test_objects"]
        if params.get("debugger", None):
            import mozdebug

            if not mozdebug.get_debugger_info(params.get("debugger")):
                sys.exit(1)

        wpt_setup = self._spawn(WebPlatformTestsRunnerSetup)
        wpt_setup._mach_context = self._mach_context
        wpt_runner = WebPlatformTestsRunner(wpt_setup)

        logger = wpt_runner.setup_logging(**params)

        if conditions.is_android(
                self) and params["product"] != "firefox_android":
            logger.warning(
                "Must specify --product=firefox_android in Android environment."
            )

        return wpt_runner.run(logger, **params)
示例#26
0
    def run_web_platform_tests(self, **params):
        self.setup()
        if conditions.is_android(self) and params["product"] != "firefox_android":
            if params["product"] is None:
                params["product"] = "firefox_android"
        if "test_objects" in params:
            for item in params["test_objects"]:
                params["include"].append(item["name"])
            del params["test_objects"]
        if params.get('debugger', None):
            import mozdebug
            if not mozdebug.get_debugger_info(params.get('debugger')):
                sys.exit(1)

        wpt_setup = self._spawn(WebPlatformTestsRunnerSetup)
        wpt_setup._mach_context = self._mach_context
        wpt_runner = WebPlatformTestsRunner(wpt_setup)

        logger = wpt_runner.setup_logging(**params)

        if conditions.is_android(self) and params["product"] != "firefox_android":
            logger.warning("Must specify --product=firefox_android in Android environment.")

        return wpt_runner.run(logger, **params)
示例#27
0
    def __init__(self, app=None, **kwargs):
        ArgumentParser.__init__(
            self, usage=self.__doc__, conflict_handler="resolve", **kwargs
        )
        # XXX see if this list will vary depending on the flavor & app
        self.oldcwd = os.getcwd()
        self.app = app
        if not self.app and build_obj:
            if conditions.is_android(build_obj):
                self.app = "android"
        if not self.app:
            self.app = "generic"
        for name, options in Options.args.items():
            self.add_argument(name, **options)

        mozlog.commandline.add_logging_group(self)
        self.set_by_user = []
    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)
示例#29
0
    def run_raptor_test(self, **kwargs):

        build_obj = MozbuildObject.from_environment(cwd=HERE)

        if conditions.is_android(build_obj) or kwargs['app'] == 'geckoview':
            from mozrunner.devices.android_device import verify_android_device
            if not verify_android_device(build_obj, install=True, app=kwargs['binary']):
                return 1

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

        raptor = self._spawn(RaptorRunner)

        try:
            return raptor.run_test(sys.argv[2:], app=kwargs['app'])
        except Exception as e:
            print(str(e))
            return 1
示例#30
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)
        else:
            xpcshell = self._spawn(XPCShellRunner)

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
示例#31
0
    def run_raptor(self, **kwargs):
        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 ADBAndroid
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.YES
            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 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)
示例#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(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)
        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
示例#33
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,
            InstallIntent,
        )

        # verify device and xre
        verify_android_device(build_obj, install=InstallIntent.NO, xre=True)

    global parser
    parser = MochitestArgumentParser()
    return parser
示例#34
0
    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)
示例#35
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)
示例#36
0
    def __init__(self, app=None, **kwargs):
        ArgumentParser.__init__(self,
                                usage=self.__doc__,
                                conflict_handler="resolve",
                                **kwargs)
        # XXX see if this list will vary depending on the flavor & app
        self.groups = [GenericGroup]
        self.oldcwd = os.getcwd()
        self.app = app
        if not self.app and build_obj:
            if conditions.is_android(build_obj):
                self.app = "android"
        if not self.app:
            self.app = "generic"

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

        defaults = {}
        for klass in self.groups:
            defaults.update(klass.defaults)
            group = self.add_argument_group(klass.name, klass.__doc__)

            for cli, kwargs in klass.args:
                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)
示例#37
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)
示例#38
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)
示例#39
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)
示例#40
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

        # Remove mach global arguments from sys.argv to prevent them
        # from being consumed by raptor. Treat any item in sys.argv
        # occuring before "raptor" as a mach global argument.
        argv = []
        in_mach = True
        for arg in sys.argv:
            if not in_mach:
                argv.append(arg)
            if arg.startswith("raptor"):
                in_mach = False

        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(argv, 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)
示例#41
0
def get_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)
    if conditions.is_android(build_obj):
        return parser_remote()
    else:
        return parser_desktop()
示例#42
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'])
示例#43
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
示例#44
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", "Build", "ForceBuild"],
        default="Build",
        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
    elif options.backend == "Build":
        from mozbuild.backend.visualstudio import VisualStudioBackend

        backend_cls = VisualStudioBackend
    elif options.backend == "ForceBuild":
        from mozbuild.backend.visualstudio import VisualStudioBackend

        backend_cls = VisualStudioBackend

    the_backend = backend_cls(env)
    if options.backend == "Build":
        if the_backend.try_build():
            return
    elif options.backend == "ForceBuild":
        the_backend.full_build()

    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)
示例#45
0
def is_firefox_or_android(cls):
    """Must have Firefox build or Android build."""
    return conditions.is_firefox(cls) or conditions.is_android(cls)
示例#46
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('Walking the dog...', 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)
示例#47
0
def is_firefox_or_android(cls):
    """Must have Firefox build or Android build."""
    return conditions.is_firefox(cls) or conditions.is_android(cls)
示例#48
0
def config_status(topobjdir='.',
                  topsrcdir='.',
                  defines=None,
                  non_global_defines=None,
                  substs=None,
                  source=None,
                  mozconfig=None,
                  args=sys.argv[1:]):
    '''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(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
        if hasattr(obj, 'gyp_summary'):
            summary = obj.gyp_summary()
            print(summary, file=sys.stderr)

    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)
示例#49
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)