Esempio n. 1
0
    def _setup_node_packages(self, package_json_path):
        # Install the browsertime Node.js requirements.
        sys.path.append(mozpath.join(self.topsrcdir, "tools", "lint", "eslint"))
        import setup_helper

        if not setup_helper.check_node_executables_valid():
            return

        should_clobber = self.get_arg("clobber")
        # To use a custom `geckodriver`, set
        # os.environ[b"GECKODRIVER_BASE_URL"] = bytes(url)
        # to an endpoint with binaries named like
        # https://github.com/sitespeedio/geckodriver/blob/master/install.js#L31.
        if AUTOMATION:
            os.environ["CHROMEDRIVER_SKIP_DOWNLOAD"] = "true"
            os.environ["GECKODRIVER_SKIP_DOWNLOAD"] = "true"

        self.info(
            "Installing browsertime node module from {package_json}",
            package_json=package_json_path,
        )
        install_url = self.get_arg("install-url")

        setup_helper.package_setup(
            self.state_path,
            "browsertime",
            should_update=install_url is not None,
            should_clobber=should_clobber,
            no_optional=install_url or AUTOMATION,
        )
Esempio n. 2
0
    def setup(self, should_clobber=False):
        r'''Install browsertime and visualmetrics.py requirements.'''

        from mozbuild.action.tooltool import unpack_file
        from mozbuild.artifact_cache import ArtifactCache
        sys.path.append(mozpath.join(self.topsrcdir, 'tools', 'lint', 'eslint'))
        import setup_helper

        # Download the visualmetrics.py requirements.
        artifact_cache = ArtifactCache(self.artifact_cache_path,
                                       log=self.log, skip_cache=False)

        fetches = host_fetches[host_platform()]
        for tool, fetch in sorted(fetches.items()):
            archive = artifact_cache.fetch(fetch['url'])
            # TODO: assert type, verify sha256 (and size?).

            if fetch.get('unpack', True):
                cwd = os.getcwd()
                try:
                    os.chdir(self.state_path)
                    self.log(
                        logging.INFO,
                        'browsertime',
                        {'path': archive},
                        'Unpacking temporary location {path}')
                    unpack_file(archive)
                finally:
                    os.chdir(cwd)

        # Install the browsertime Node.js requirements.
        if not setup_helper.check_node_executables_valid():
            return 1

        self.log(
            logging.INFO,
            'browsertime',
            {'package_json': mozpath.join(BROWSERTIME_ROOT, 'package.json')},
            'Installing browsertime node module from {package_json}')
        status = setup_helper.package_setup(
            BROWSERTIME_ROOT,
            'browsertime',
            should_clobber=should_clobber)

        if status:
            return status

        return self.check()
Esempio n. 3
0
    def setup(self, should_clobber=False, new_upstream_url=""):
        r"""Install browsertime and visualmetrics.py prerequisites and the Node.js package."""

        sys.path.append(mozpath.join(self.topsrcdir, "tools", "lint",
                                     "eslint"))
        import setup_helper

        if not new_upstream_url:
            self.setup_prerequisites()

        if new_upstream_url:
            package_json_path = os.path.join(BROWSERTIME_ROOT, "package.json")

            self.log(
                logging.INFO,
                "browsertime",
                {
                    "new_upstream_url": new_upstream_url,
                    "package_json_path": package_json_path,
                },
                "Updating browsertime node module version in {package_json_path} "
                "to {new_upstream_url}",
            )

            if not re.search("/tarball/[a-f0-9]{40}$", new_upstream_url):
                raise ValueError(
                    "New upstream URL does not end with /tarball/[a-f0-9]{40}: '%s'"
                    % new_upstream_url)

            with open(package_json_path) as f:
                existing_body = json.loads(
                    f.read(), object_pairs_hook=collections.OrderedDict)

            existing_body["devDependencies"]["browsertime"] = new_upstream_url

            updated_body = json.dumps(existing_body)

            with open(package_json_path, "w") as f:
                f.write(updated_body)

        # Install the browsertime Node.js requirements.
        if not setup_helper.check_node_executables_valid():
            return 1

        # To use a custom `geckodriver`, set
        # os.environ[b"GECKODRIVER_BASE_URL"] = bytes(url)
        # to an endpoint with binaries named like
        # https://github.com/sitespeedio/geckodriver/blob/master/install.js#L31.
        if AUTOMATION:
            os.environ["CHROMEDRIVER_SKIP_DOWNLOAD"] = "true"
            os.environ["GECKODRIVER_SKIP_DOWNLOAD"] = "true"

        self.log(
            logging.INFO,
            "browsertime",
            {"package_json": mozpath.join(BROWSERTIME_ROOT, "package.json")},
            "Installing browsertime node module from {package_json}",
        )
        status = setup_helper.package_setup(
            BROWSERTIME_ROOT,
            "browsertime",
            should_update=new_upstream_url != "",
            should_clobber=should_clobber,
            no_optional=new_upstream_url or AUTOMATION,
        )

        if status:
            return status

        if new_upstream_url or AUTOMATION:
            return 0

        return self.check()
Esempio n. 4
0
    def setup(self, should_clobber=False):
        r'''Install browsertime and visualmetrics.py requirements.'''

        automation = bool(os.environ.get('MOZ_AUTOMATION'))

        from mozbuild.action.tooltool import unpack_file
        from mozbuild.artifact_cache import ArtifactCache
        sys.path.append(mozpath.join(self.topsrcdir, 'tools', 'lint', 'eslint'))
        import setup_helper

        if not os.environ.get('MOZ_AUTOMATION') and host_platform().startswith('linux'):
            # On Linux ImageMagick needs to be installed manually, and `mach bootstrap` doesn't
            # do that (yet).  Provide some guidance.
            try:
                from shutil import which
            except ImportError:
                from shutil_which import which

            im_programs = ('compare', 'convert', 'mogrify')
            for im_program in im_programs:
                prog = which(im_program)
                if not prog:
                    print('Error: On Linux, ImageMagick must be on the PATH. '
                          'Install ImageMagick manually and try again (or update PATH). '
                          'On Ubuntu and Debian, try `sudo apt-get install imagemagick`. '
                          'On Fedora, try `sudo dnf install imagemagick`. '
                          'On CentOS, try `sudo yum install imagemagick`.')
                    return 1

        # Download the visualmetrics.py requirements.
        artifact_cache = ArtifactCache(self.artifact_cache_path,
                                       log=self.log, skip_cache=False)

        fetches = host_fetches[host_platform()]
        for tool, fetch in sorted(fetches.items()):
            archive = artifact_cache.fetch(fetch['url'])
            # TODO: assert type, verify sha256 (and size?).

            if fetch.get('unpack', True):
                cwd = os.getcwd()
                try:
                    mkdir(self.state_path)
                    os.chdir(self.state_path)
                    self.log(
                        logging.INFO,
                        'browsertime',
                        {'path': archive},
                        'Unpacking temporary location {path}')
                    unpack_file(archive)

                    # Make sure the expected path exists after extraction
                    path = os.path.join(self.state_path, fetch.get('path'))
                    if not os.path.exists(path):
                        raise Exception("Cannot find an extracted directory: %s" % path)

                    try:
                        # Some archives provide binaries that don't have the
                        # executable bit set so we need to set it here
                        for root, dirs, files in os.walk(path):
                            for edir in dirs:
                                loc_to_change = os.path.join(root, edir)
                                st = os.stat(loc_to_change)
                                os.chmod(loc_to_change, st.st_mode | stat.S_IEXEC)
                            for efile in files:
                                loc_to_change = os.path.join(root, efile)
                                st = os.stat(loc_to_change)
                                os.chmod(loc_to_change, st.st_mode | stat.S_IEXEC)
                    except Exception as e:
                        raise Exception(
                            "Could not set executable bit in %s, error: %s" % (path, str(e))
                        )
                finally:
                    os.chdir(cwd)

        # Install the browsertime Node.js requirements.
        if not setup_helper.check_node_executables_valid():
            return 1

        if 'GECKODRIVER_BASE_URL' not in os.environ:
            # Use custom `geckodriver` with pre-release Android support.
            url = 'https://github.com/ncalexan/geckodriver/releases/download/v0.24.0-android/'
            os.environ['GECKODRIVER_BASE_URL'] = url

        self.log(
            logging.INFO,
            'browsertime',
            {'package_json': mozpath.join(BROWSERTIME_ROOT, 'package.json')},
            'Installing browsertime node module from {package_json}')
        status = setup_helper.package_setup(
            BROWSERTIME_ROOT,
            'browsertime',
            should_clobber=should_clobber,
            no_optional=automation)

        if status:
            return status

        if automation:
            return 0

        return self.check()
Esempio n. 5
0
    def setup(self, should_clobber=False):
        r'''Install browsertime and visualmetrics.py requirements.'''

        from mozbuild.action.tooltool import unpack_file
        from mozbuild.artifact_cache import ArtifactCache
        sys.path.append(mozpath.join(self.topsrcdir, 'tools', 'lint',
                                     'eslint'))
        import setup_helper

        if host_platform().startswith('linux'):
            # On Linux ImageMagick needs to be installed manually, and `mach bootstrap` doesn't
            # do that (yet).  Provide some guidance.
            import which
            im_programs = ('compare', 'convert', 'mogrify')
            try:
                for im_program in im_programs:
                    which.which(im_program)
            except which.WhichError as e:
                print(
                    'Error: {} On Linux, ImageMagick must be on the PATH. '
                    'Install ImageMagick manually and try again (or update PATH). '
                    'On Ubuntu and Debian, try `sudo apt-get install imagemagick`. '
                    'On Fedora, try `sudo dnf install imagemagick`. '
                    'On CentOS, try `sudo yum install imagemagick`.'.format(e))
                return 1

        # Download the visualmetrics.py requirements.
        artifact_cache = ArtifactCache(self.artifact_cache_path,
                                       log=self.log,
                                       skip_cache=False)

        fetches = host_fetches[host_platform()]
        for tool, fetch in sorted(fetches.items()):
            archive = artifact_cache.fetch(fetch['url'])
            # TODO: assert type, verify sha256 (and size?).

            if fetch.get('unpack', True):
                cwd = os.getcwd()
                try:
                    mkdir(self.state_path)
                    os.chdir(self.state_path)
                    self.log(logging.INFO, 'browsertime', {'path': archive},
                             'Unpacking temporary location {path}')
                    unpack_file(archive)
                finally:
                    os.chdir(cwd)

        # Install the browsertime Node.js requirements.
        if not setup_helper.check_node_executables_valid():
            return 1

        if 'GECKODRIVER_BASE_URL' not in os.environ:
            # Use custom `geckodriver` with pre-release Android support.
            url = 'https://github.com/ncalexan/geckodriver/releases/download/v0.24.0-android/'
            os.environ['GECKODRIVER_BASE_URL'] = url

        self.log(
            logging.INFO, 'browsertime',
            {'package_json': mozpath.join(BROWSERTIME_ROOT, 'package.json')},
            'Installing browsertime node module from {package_json}')
        status = setup_helper.package_setup(BROWSERTIME_ROOT,
                                            'browsertime',
                                            should_clobber=should_clobber)

        if status:
            return status

        return self.check()
Esempio n. 6
0
    def setup(self, should_clobber=False, new_upstream_url=''):
        r'''Install browsertime and visualmetrics.py prerequisites and the Node.js package.'''

        sys.path.append(mozpath.join(self.topsrcdir, 'tools', 'lint', 'eslint'))
        import setup_helper

        if not new_upstream_url:
            self.setup_prerequisites()

        if new_upstream_url:
            package_json_path = os.path.join(BROWSERTIME_ROOT, 'package.json')

            self.log(
                logging.INFO,
                'browsertime',
                {'new_upstream_url': new_upstream_url, 'package_json_path': package_json_path},
                'Updating browsertime node module version in {package_json_path} '
                'to {new_upstream_url}')

            if not re.search('/tarball/[a-f0-9]{40}$', new_upstream_url):
                raise ValueError("New upstream URL does not end with /tarball/[a-f0-9]{40}: '{}'"
                                 .format(new_upstream_url))

            with open(package_json_path) as f:
                existing_body = json.loads(f.read(), object_pairs_hook=collections.OrderedDict)

            existing_body['devDependencies']['browsertime'] = new_upstream_url

            updated_body = json.dumps(existing_body)

            with open(package_json_path, 'w') as f:
                f.write(updated_body)

        # Install the browsertime Node.js requirements.
        if not setup_helper.check_node_executables_valid():
            return 1

        # To use a custom `geckodriver`, set
        # os.environ[b"GECKODRIVER_BASE_URL"] = bytes(url)
        # to an endpoint with binaries named like
        # https://github.com/sitespeedio/geckodriver/blob/master/install.js#L31.
        if AUTOMATION:
            os.environ[b"CHROMEDRIVER_SKIP_DOWNLOAD"] = b"true"
            os.environ[b"GECKODRIVER_SKIP_DOWNLOAD"] = b"true"

        self.log(
            logging.INFO,
            'browsertime',
            {'package_json': mozpath.join(BROWSERTIME_ROOT, 'package.json')},
            'Installing browsertime node module from {package_json}')
        status = setup_helper.package_setup(
            BROWSERTIME_ROOT,
            'browsertime',
            should_update=new_upstream_url != '',
            should_clobber=should_clobber,
            no_optional=new_upstream_url or AUTOMATION)

        if status:
            return status

        if new_upstream_url or AUTOMATION:
            return 0

        return self.check()
Esempio n. 7
0
    def setup(self, should_clobber=False, new_upstream_url=""):
        """Install browsertime and visualmetrics.py prerequisites and the Node.js package.
        """
        super(BrowsertimeRunner, self).setup()

        # installing Python deps on the fly
        for dep in ("Pillow==%s" % PILLOW_VERSION,
                    "pyssim==%s" % PYSSIM_VERSION):
            if self._need_install(dep):
                self.virtualenv_manager._run_pip(["install", dep])

        # check if the browsertime package has been deployed correctly
        # for this we just check for the browsertime directory presence
        if os.path.exists(self.browsertime_js):
            return

        sys.path.append(mozpath.join(self.topsrcdir, "tools", "lint",
                                     "eslint"))
        import setup_helper

        if not new_upstream_url:
            self.setup_prerequisites()

        # preparing ~/.mozbuild/browsertime
        for file in ("package.json", "package-lock.json"):
            src = mozpath.join(BROWSERTIME_SRC_ROOT, file)
            target = mozpath.join(self.state_path, file)
            if not os.path.exists(target):
                shutil.copyfile(src, target)

        package_json_path = mozpath.join(self.state_path, "package.json")

        if new_upstream_url:
            self.info(
                "Updating browsertime node module version in {package_json_path} "
                "to {new_upstream_url}",
                new_upstream_url=new_upstream_url,
                package_json_path=package_json_path,
            )

            if not re.search("/tarball/[a-f0-9]{40}$", new_upstream_url):
                raise ValueError(
                    "New upstream URL does not end with /tarball/[a-f0-9]{40}: '{}'"
                    .format(new_upstream_url))

            with open(package_json_path) as f:
                existing_body = json.loads(
                    f.read(), object_pairs_hook=collections.OrderedDict)

            existing_body["devDependencies"]["browsertime"] = new_upstream_url

            updated_body = json.dumps(existing_body)

            with open(package_json_path, "w") as f:
                f.write(updated_body)

        # Install the browsertime Node.js requirements.
        if not setup_helper.check_node_executables_valid():
            return

        # To use a custom `geckodriver`, set
        # os.environ[b"GECKODRIVER_BASE_URL"] = bytes(url)
        # to an endpoint with binaries named like
        # https://github.com/sitespeedio/geckodriver/blob/master/install.js#L31.
        if AUTOMATION:
            os.environ["CHROMEDRIVER_SKIP_DOWNLOAD"] = "true"
            os.environ["GECKODRIVER_SKIP_DOWNLOAD"] = "true"

        self.info(
            "Installing browsertime node module from {package_json}",
            package_json=package_json_path,
        )
        setup_helper.package_setup(
            self.state_path,
            "browsertime",
            should_update=new_upstream_url != "",
            should_clobber=should_clobber,
            no_optional=new_upstream_url or AUTOMATION,
        )