Esempio n. 1
0
    def run_installers(self, *, include_sources=False):
        """
        Invoke all installers to install packages into the bundle.

        :param include_sources: creates a sources tarball
        for all packages being installed that have sources
        available
        :return: true if all packages installed in the
        bundle are the same as the previous run
        """
        print('Collecting dependency information...')
        logger.info('Collecting dependency information...')

        print('Fetching and installing dependencies...')
        logger.info('Fetching and installing dependencies...')
        installer_metadata = {}
        for name, installer in self.installers.items():
            installer_metadata[name] = installer.install()

        installer_metadata_string = json.dumps(installer_metadata,
                                               sort_keys=True)

        installer_metadata_path = self._path_context.installer_metadata_path()
        dependency_match = False
        if os.path.exists(installer_metadata_path):
            with open(installer_metadata_path, 'r') as f:
                previous_metadata = f.read()
                if previous_metadata == installer_metadata_string:
                    dependency_match = True

        with open(installer_metadata_path, 'w') as f:
            f.write(installer_metadata_string)

        if include_sources:
            sources_tar_gz_path = self._path_context.sources_tar_gz_path()
            with tarfile.open(sources_tar_gz_path, 'w:gz',
                              compresslevel=5) as archive:
                for name, directory in self.installer_cache_dirs.items():
                    sources_path = os.path.join(directory, 'sources')
                    if not os.path.exists(sources_path):
                        continue
                    for filename in os.listdir(sources_path):
                        file_path = os.path.join(sources_path, filename)
                        archive.add(file_path,
                                    arcname=os.path.join(
                                        name, os.path.basename(file_path)))

        update_symlinks(self.prefix_path)
        # TODO: Update pkgconfig files?
        update_shebang(self.prefix_path)
        # TODO: Move this to colcon-ros-bundle
        rewrite_catkin_package_path(self.prefix_path)

        return dependency_match
Esempio n. 2
0
    def _manage_dependencies(self, context, path_context, upgrade_deps_graph):

        bundle_base = path_context.bundle_base()
        check_and_mark_install_layout(path_context.install_base(),
                                      merge_install=context.args.merge_install)
        self._create_path(bundle_base)
        check_and_mark_bundle_tool(bundle_base)

        destinations = self.task_argument_destinations
        decorators = get_packages(context.args,
                                  additional_argument_names=destinations,
                                  recursive_categories=('run', ))

        installers = self._setup_installers(context, path_context)

        print('Checking if dependency tarball exists...')
        logger.info('Checking if dependency tarball exists...')

        if not os.path.exists(path_context.dependencies_tar_gz_path()):
            self._check_package_dependency_update(path_context, decorators)
            self._check_installer_dependency_update(context, decorators,
                                                    installers, path_context)
        elif upgrade_deps_graph:
            self._check_package_dependency_update(path_context, decorators)
            print('Checking if dependency graph has changed since last '
                  'bundle...')
            logger.info('Checking if dependency graph has changed since last'
                        ' bundle...')
            if self._check_installer_dependency_update(context, decorators,
                                                       installers,
                                                       path_context):
                print('All dependencies in dependency graph not changed, '
                      'skipping dependencies update...')
                logger.info('All dependencies in dependency graph not changed,'
                            ' skipping dependencies update...')
                return False
        else:
            print('Checking if local dependencies have changed since last'
                  ' bundle...')
            logger.info(
                'Checking if local dependencies have changed since last'
                ' bundle...')
            if self._check_package_dependency_update(path_context, decorators):
                print('Local dependencies not changed, skipping dependencies'
                      ' update...')
                logger.info(
                    'Local dependencies not changed, skipping dependencies'
                    ' update...')
                return False
            self._check_installer_dependency_update(context, decorators,
                                                    installers, path_context)

        if context.args.include_sources:
            sources_tar_gz_path = path_context.sources_tar_gz_path()
            with tarfile.open(sources_tar_gz_path, 'w:gz',
                              compresslevel=5) as archive:
                for name, directory in self.installer_cache_dirs.items():
                    sources_path = os.path.join(directory, 'sources')
                    if not os.path.exists(sources_path):
                        continue
                    for filename in os.listdir(sources_path):
                        file_path = os.path.join(sources_path, filename)
                        archive.add(file_path,
                                    arcname=os.path.join(
                                        name, os.path.basename(file_path)))

        staging_path = path_context.staging_path()
        update_symlinks(staging_path)
        # TODO: Update pkgconfig files?
        update_shebang(staging_path)
        # TODO: Move this to colcon-ros-bundle
        rewrite_catkin_package_path(staging_path)

        return True
Esempio n. 3
0
    def _manage_dependencies(self, context, path_context, upgrade_deps_graph):

        bundle_base = path_context.bundle_base()
        bundle_version = context.args.bundle_version
        check_and_mark_install_layout(path_context.install_base(),
                                      merge_install=context.args.merge_install)
        # This must be first for backwards compatibility
        # reasons. We assume the folder was previously
        # used for v1 if it exists.
        check_and_mark_bundle_version(bundle_base,
                                      this_bundle_version=bundle_version)
        self._create_path(bundle_base)
        check_and_mark_bundle_tool(bundle_base)

        destinations = self.task_argument_destinations
        decorators = get_packages(context.args,
                                  additional_argument_names=destinations,
                                  recursive_categories=('run', ))
        if len(decorators) == 0:
            estr = 'We did not find any packages to add to the '\
                   'bundle. This might be because you are not '\
                   'in the right directory, or your workspace is '\
                   'not setup correctly for colcon. Please see '\
                   'https://github.com/colcon/colcon-ros-bundle/issues/13' \
                   'for some possible suggestions. If you are still having ' \
                   'trouble please post to our' \
                   'issues: https://github.com/colcon/colcon-bundle/issues '\
                   'and we will be happy to help.'
            raise RuntimeError(estr)

        installers = self._setup_installers(context, path_context)

        print('Checking if dependency tarball exists...')
        logger.info('Checking if dependency tarball exists...')

        if not os.path.exists(path_context.dependencies_tar_gz_path()):
            self._check_package_dependency_update(path_context, decorators)
            self._check_installer_dependency_update(context, decorators,
                                                    installers, path_context)
        elif upgrade_deps_graph:
            self._check_package_dependency_update(path_context, decorators)
            print('Checking if dependency graph has changed since last '
                  'bundle...')
            logger.info('Checking if dependency graph has changed since last'
                        ' bundle...')
            if self._check_installer_dependency_update(context, decorators,
                                                       installers,
                                                       path_context):
                print('All dependencies in dependency graph not changed, '
                      'skipping dependencies update...')
                logger.info('All dependencies in dependency graph not changed,'
                            ' skipping dependencies update...')
                return False
        else:
            print('Checking if local dependencies have changed since last'
                  ' bundle...')
            logger.info(
                'Checking if local dependencies have changed since last'
                ' bundle...')
            if self._check_package_dependency_update(path_context, decorators):
                print('Local dependencies not changed, skipping dependencies'
                      ' update...')
                logger.info(
                    'Local dependencies not changed, skipping dependencies'
                    ' update...')
                return False
            self._check_installer_dependency_update(context, decorators,
                                                    installers, path_context)

        if context.args.include_sources:
            sources_tar_gz_path = path_context.sources_tar_gz_path()
            with tarfile.open(sources_tar_gz_path, 'w:gz',
                              compresslevel=5) as archive:
                for name, directory in self.installer_cache_dirs.items():
                    sources_path = os.path.join(directory, 'sources')
                    if not os.path.exists(sources_path):
                        continue
                    for filename in os.listdir(sources_path):
                        file_path = os.path.join(sources_path, filename)
                        archive.add(file_path,
                                    arcname=os.path.join(
                                        name, os.path.basename(file_path)))

        staging_path = path_context.staging_path()
        update_symlinks(staging_path)
        # TODO: Update pkgconfig files?
        update_shebang(staging_path)
        # TODO: Move this to colcon-ros-bundle
        rewrite_catkin_package_path(staging_path)

        return True
Esempio n. 4
0
    def _manage_dependencies(self, context,
                             install_base, bundle_base,
                             staging_path, installer_metadata_path):

        check_and_mark_install_layout(
            install_base, merge_install=context.args.merge_install)
        self._create_path(bundle_base)
        check_and_mark_bundle_tool(bundle_base)

        destinations = self.task_argument_destinations
        decorators = get_packages(context.args,
                                  additional_argument_names=destinations,
                                  recursive_categories=('run',))

        installers = self._setup_installers(context)

        print('Collecting dependency information...')
        jobs = self._get_jobs(context.args, installers, decorators)
        rc = execute_jobs(context, jobs)
        if rc != 0:
            return rc

        print('Fetching and installing dependencies...')
        installer_metadata = {}
        for name, installer in installers.items():
            installer_metadata[name] = installer.install()

        installer_metadata_string = json.dumps(installer_metadata,
                                               sort_keys=True)

        dependencies_changed = True
        if os.path.exists(installer_metadata_path):
            with open(installer_metadata_path, 'r') as f:
                previous_metadata = f.read()
                if previous_metadata == installer_metadata_string:
                    dependencies_changed = False

        with open(installer_metadata_path, 'w') as f:
            f.write(installer_metadata_string)

        if context.args.include_sources and dependencies_changed:
            sources_tar_gz_path = os.path.join(bundle_base, 'sources.tar.gz')
            with tarfile.open(
                    sources_tar_gz_path, 'w:gz', compresslevel=5) as archive:
                for name, directory in self.installer_cache_dirs.items():
                    sources_path = os.path.join(directory, 'sources')
                    if not os.path.exists(sources_path):
                        continue
                    for filename in os.listdir(sources_path):
                        file_path = os.path.join(sources_path, filename)
                        archive.add(
                            file_path,
                            arcname=os.path.join(
                                name, os.path.basename(file_path)))

        if dependencies_changed:
            update_symlinks(staging_path)
            # TODO: Update pkgconfig files?
            update_shebang(staging_path)
            # TODO: Move this to colcon-ros-bundle
            rewrite_catkin_package_path(staging_path)

        return dependencies_changed