Пример #1
0
    def _build_action(self, context):
        environment_hooks_path = os.path.join('share',
                                              context.package_manifest.name,
                                              'environment')

        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_environment_hook = os.path.join(environment_hooks_path,
                                             'path' + ext)
        # expand environment hook for PYTHONPATH
        ext = '.sh.in' if not IS_WINDOWS else '.bat.in'
        template_path = get_environment_hook_template_path('pythonpath' + ext)
        content = configure_file(
            template_path, {
                'PYTHON_INSTALL_DIR': self._get_python_lib(context),
            })
        pythonpath_environment_hook = os.path.join(
            environment_hooks_path,
            os.path.basename(template_path)[:-3])
        destination_path = os.path.join(context.build_space,
                                        pythonpath_environment_hook)
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_path, 'w') as h:
            h.write(content)

        environment_hooks = [
            path_environment_hook,
            pythonpath_environment_hook,
        ]

        # expand package-level setup files
        expand_package_level_setup_files(context, environment_hooks,
                                         environment_hooks_path)
Пример #2
0
    def _build_action(self, context):
        environment_hooks_path = os.path.join(
            'share', context.package_manifest.name, 'environment')

        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_environment_hook = os.path.join(
            environment_hooks_path, 'path' + ext)
        # expand environment hook for PYTHONPATH
        ext = '.sh.in' if not IS_WINDOWS else '.bat.in'
        template_path = get_environment_hook_template_path('pythonpath' + ext)
        content = configure_file(template_path, {
            'PYTHON_INSTALL_DIR': self._get_python_lib(context),
        })
        pythonpath_environment_hook = os.path.join(
            environment_hooks_path, os.path.basename(template_path)[:-3])
        destination_path = os.path.join(
            context.build_space, pythonpath_environment_hook)
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_path, 'w') as h:
            h.write(content)

        environment_hooks = [
            path_environment_hook,
            pythonpath_environment_hook,
        ]

        # expand package-level setup files
        expand_package_level_setup_files(context, environment_hooks, environment_hooks_path)
Пример #3
0
    def on_build(self, context):
        cmd_args = [
            '-Pament.build_space=' + context.build_space,
            '-Pament.install_space=' + context.install_space,
            '-Pament.dependencies=' + ':'.join(context.build_dependencies),
            '-Pament.build_tests=' + str(context.build_tests),
        ]
        cmd_args += context.ament_gradle_args

        cmd = [get_gradle_executable(context)]
        cmd += cmd_args
        cmd += ['assemble']

        yield BuildAction(cmd, cwd=context.source_space)

        environment_hooks_path = os.path.join('share',
                                              context.package_manifest.name,
                                              'environment')

        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_environment_hook = os.path.join(environment_hooks_path,
                                             'path' + ext)

        # expand environment hook for JAVAPATH
        ext = '.sh.in' if not IS_WINDOWS else '.bat.in'
        template_path = self.get_environment_hook_template_path('javapath' +
                                                                ext)
        javapath = os.path.join('$AMENT_CURRENT_PREFIX', 'share',
                                context.package_manifest.name, 'java', '*')
        javapath_depends = os.path.join('$AMENT_CURRENT_PREFIX', 'lib', 'java',
                                        '*')
        content = configure_file(template_path, {
            'JAVAPATH': javapath,
            'JAVAPATH_DEPENDS': javapath_depends
        })
        javapath_environment_hook = os.path.join(
            environment_hooks_path,
            os.path.basename(template_path)[:-3])
        destination_path = os.path.join(context.build_space,
                                        javapath_environment_hook)
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_path, 'w') as h:
            h.write(content)

        environment_hooks = [
            path_environment_hook,
            javapath_environment_hook,
        ]

        # expand package-level setup files
        expand_package_level_setup_files(context, environment_hooks,
                                         environment_hooks_path)
Пример #4
0
    def on_install(self, context):
        # First determine the files being deployed with skip_if_exists=True and remove them.
        environment_hooks_path = \
            os.path.join('share', context.package_manifest.name, 'environment')

        environment_hooks_to_be_deployed = []
        environment_hooks = []

        # Prepare to deploy AMENT_PREFIX_PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        ament_prefix_path_template_path = get_environment_hook_template_path(
            'ament_prefix_path' + ext)
        environment_hooks_to_be_deployed.append(
            ament_prefix_path_template_path)
        environment_hooks.append(
            os.path.join(environment_hooks_path, 'ament_prefix_path' + ext))

        # Prepare to deploy PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_template_path = get_environment_hook_template_path('path' + ext)
        environment_hooks_to_be_deployed.append(path_template_path)
        environment_hooks.append(
            os.path.join(environment_hooks_path, 'path' + ext))

        # Prepare to deploy library path environment hook if not on Windows
        if not IS_WINDOWS:
            library_template_path = get_environment_hook_template_path(
                'library_path.sh')
            environment_hooks_to_be_deployed.append(library_template_path)
            environment_hooks.append(
                os.path.join(environment_hooks_path, 'library_path.sh'))

        # Expand package level setup files
        destinations = \
            expand_package_level_setup_files(context, environment_hooks, environment_hooks_path)

        # Remove package level setup files so they can be replaced correctly either in the
        # cmake install step or later with deploy_file(..., skip_if_exists=True)
        for destination in destinations:
            destination_path = compute_deploy_destination(
                context, os.path.basename(destination),
                os.path.dirname(
                    os.path.relpath(destination, context.build_space)))
            if os.path.exists(destination_path) or os.path.islink(
                    destination_path):
                os.remove(destination_path)

        # Call cmake common on_install (defined in CmakeBuildType)
        for step in self._common_cmake_on_install(context):
            yield step

        # Install files needed to extend the environment for build dependents to use this package
        # create marker file
        marker_file = os.path.join(context.install_space, 'share',
                                   'ament_index', 'resource_index', 'packages',
                                   context.package_manifest.name)
        if not os.path.exists(marker_file):
            os.makedirs(os.path.dirname(marker_file), exist_ok=True)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        # Deploy environment hooks
        for environment_hook in environment_hooks_to_be_deployed:
            deploy_file(context,
                        os.path.dirname(environment_hook),
                        os.path.basename(environment_hook),
                        dst_subfolder=environment_hooks_path)

        # Expand package-level setup files
        for destination in destinations:
            deploy_file(context,
                        os.path.dirname(destination),
                        os.path.basename(destination),
                        dst_subfolder=os.path.dirname(
                            os.path.relpath(destination, context.build_space)),
                        skip_if_exists=True)
Пример #5
0
    def on_build(self, context):
        environment_hooks_path = os.path.join('share', context.package_manifest.name, 'environment')

        ext = '.sh' if not IS_WINDOWS else '.bat'
        # expand environment hook for AMENT_PREFIX_PATH
        ament_prefix_path_environment_hook = os.path.join(environment_hooks_path,
                                                          'ament_prefix_path' + ext)
        # expand environment hook for PATH
        path_environment_hook = os.path.join(environment_hooks_path, 'path' + ext)

        # expand environment hook for CLASSPATH
        classpath_filename = 'classpath' + ext
        template = get_environment_hook_classpath_template_path()

        # If using the Gradle Ament Plugin, JAR files are installed into
        # $AMENT_CURRENT_PREFIX/share/$PROJECT_NAME/java/$PROJECT_NAME.jar
        classpath = os.path.join('$AMENT_CURRENT_PREFIX', 'share', context.package_manifest.name,
                                 'java', context.package_manifest.name + ".jar")

        content = configure_string(template, {'_AMENT_EXPORT_JARS_CLASSPATH': classpath, })

        classpath_environment_hook = os.path.join(environment_hooks_path,
                                                  os.path.basename(classpath_filename))

        destination_path = os.path.join(context.build_space, classpath_environment_hook)
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_path, 'w') as h:
            h.write(content)

        environment_hooks = [
            ament_prefix_path_environment_hook,
            classpath_environment_hook,
            path_environment_hook,
        ]

        # expand package-level setup files
        expand_package_level_setup_files(context, environment_hooks,
                                         environment_hooks_path)

        # remove anything that's on the destination tree but not in the source tree
        src_package_src_dir = os.path.join(context.source_space, 'src')
        dst_package_src_dir = os.path.join(context.build_space, 'src')

        src_dirnames, src_filenames = self._build_file_tree(src_package_src_dir)
        dst_dirnames, dst_filenames = self._build_file_tree(dst_package_src_dir)

        prune_dirnames = dst_dirnames - src_dirnames
        prune_filenames = dst_filenames - src_filenames

        for prune_filename in prune_filenames:
            os.remove(os.path.join(dst_package_src_dir, prune_filename))
        for prune_dirname in prune_dirnames:
            if os.path.exists(prune_dirname):
                shutil.rmtree(os.path.join(dst_package_src_dir, prune_dirname))

        # copy files from source_space to build_space to avoid poluting the latter
        # during the build process
        dir_util.copy_tree(context.source_space, context.build_space, update=1)

        yield BuildAction(
            self._prepare_cmd(
                context, gradle_task='assemble'), cwd=context.build_space)
Пример #6
0
    def on_install(self, context):
        # First determine the files being deployed with skip_if_exists=True and remove them.
        environment_hooks_path = \
            os.path.join('share', context.package_manifest.name, 'environment')

        environment_hooks_to_be_deployed = []
        environment_hooks = []

        # Prepare to deploy AMENT_PREFIX_PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        ament_prefix_path_template_path = get_environment_hook_template_path(
            'ament_prefix_path' + ext)
        environment_hooks_to_be_deployed.append(ament_prefix_path_template_path)
        environment_hooks.append(os.path.join(environment_hooks_path, 'ament_prefix_path' + ext))

        # Prepare to deploy PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_template_path = get_environment_hook_template_path('path' + ext)
        environment_hooks_to_be_deployed.append(path_template_path)
        environment_hooks.append(os.path.join(environment_hooks_path, 'path' + ext))

        # Prepare to deploy library path environment hook if not on Windows
        if not IS_WINDOWS:
            library_template_path = get_environment_hook_template_path('library_path.sh')
            environment_hooks_to_be_deployed.append(library_template_path)
            environment_hooks.append(os.path.join(environment_hooks_path, 'library_path.sh'))

        # Prepare to deploy PKG_CONFIG_PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        template_path = get_environment_hook_template_path('pkg_config_path' + ext)
        environment_hooks_to_be_deployed.append(template_path)
        environment_hooks.append(os.path.join(environment_hooks_path, 'pkg_config_path' + ext))

        # Expand package level setup files
        destinations = \
            expand_package_level_setup_files(context, environment_hooks, environment_hooks_path)

        # Remove package level setup files so they can be replaced correctly either in the
        # cmake install step or later with deploy_file(..., skip_if_exists=True)
        for destination in destinations:
            destination_path = compute_deploy_destination(
                context,
                os.path.basename(destination),
                os.path.dirname(os.path.relpath(destination, context.build_space)))
            if os.path.exists(destination_path) or os.path.islink(destination_path):
                os.remove(destination_path)

        # Call cmake common on_install (defined in CmakeBuildType)
        for step in self._common_cmake_on_install(context):
            yield step

        # Install files needed to extend the environment for build dependents to use this package
        # create marker file
        marker_file = os.path.join(
            context.install_space,
            'share', 'ament_index', 'resource_index', 'packages',
            context.package_manifest.name)
        if not os.path.exists(marker_file):
            os.makedirs(os.path.dirname(marker_file), exist_ok=True)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        # check if install space has any pkg-config files
        has_pkg_config_files = False
        pkg_config_path = os.path.join(context.install_space, 'lib', 'pkgconfig')
        if os.path.isdir(pkg_config_path):
            for name in os.listdir(pkg_config_path):
                if name.endswith('.pc'):
                    has_pkg_config_files = True
                    break
        if not has_pkg_config_files:
            # remove pkg_config_path hook if not needed
            environment_hooks_to_be_deployed = [
                h for h in environment_hooks_to_be_deployed
                if os.path.splitext(os.path.basename(h))[0] != 'pkg_config_path']
            environment_hooks = [
                h for h in environment_hooks
                if os.path.splitext(os.path.basename(h))[0] != 'pkg_config_path']
            # regenerate package level setup files
            destinations = expand_package_level_setup_files(
                context, environment_hooks, environment_hooks_path)

        # Deploy environment hooks
        for environment_hook in environment_hooks_to_be_deployed:
            deploy_file(
                context, os.path.dirname(environment_hook), os.path.basename(environment_hook),
                dst_subfolder=environment_hooks_path)

        # Expand package-level setup files
        for destination in destinations:
            deploy_file(
                context,
                os.path.dirname(destination), os.path.basename(destination),
                dst_subfolder=os.path.dirname(os.path.relpath(destination, context.build_space)),
                skip_if_exists=True)
Пример #7
0
    def on_install(self, context):
        # First determine the files being deployed with skip_if_exists=True and remove them.
        environment_hooks_path = \
            os.path.join('share', context.package_manifest.name, 'environment')

        environment_hooks_to_be_deployed = []

        # Prepare to deploy PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_template_path = get_environment_hook_template_path('path' + ext)
        environment_hooks_to_be_deployed.append(path_template_path)
        environment_hooks = [os.path.join(environment_hooks_path, 'path' + ext)]

        # Prepare to deploy library path environment hook if not on Windows
        if not IS_WINDOWS:
            library_template_path = get_environment_hook_template_path('library_path.sh')
            environment_hooks_to_be_deployed.append(library_template_path)
            environment_hooks.append(os.path.join(environment_hooks_path, 'library_path.sh'))

        # Expand package level setup files
        destinations = \
            expand_package_level_setup_files(context, environment_hooks, environment_hooks_path)

        # Remove package level setup files so they can be replaced correctly either in the
        # cmake install step or later with deploy_file(..., skip_if_exists=True)
        for destination in destinations:
            destination_path = compute_deploy_destination(
                context,
                os.path.basename(destination),
                os.path.dirname(os.path.relpath(destination, context.build_space))
            )
            if os.path.exists(destination_path) or os.path.islink(destination_path):
                os.remove(destination_path)

        # Call cmake common on_install (defined in CmakeBuildType)
        for step in self._common_cmake_on_install(context):
            yield step

        # Install files needed to extend the environment for build dependents to use this package
        # create marker file
        marker_file = os.path.join(
            context.install_space,
            'share', 'ament_index', 'resource_index', 'packages',
            context.package_manifest.name)
        if not os.path.exists(marker_file):
            marker_dir = os.path.dirname(marker_file)
            if not os.path.exists(marker_dir):
                os.makedirs(marker_dir)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        # Deploy environment hooks
        for environment_hook in environment_hooks_to_be_deployed:
            deploy_file(
                context, os.path.dirname(environment_hook), os.path.basename(environment_hook),
                dst_subfolder=environment_hooks_path)

        # Expand package-level setup files
        for destination in destinations:
            deploy_file(
                context,
                os.path.dirname(destination), os.path.basename(destination),
                dst_subfolder=os.path.dirname(os.path.relpath(destination, context.build_space)),
                skip_if_exists=True)