예제 #1
0
파일: build.py 프로젝트: jhdcs/colcon-ros
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info(
            "Building ROS package in '{args.path}' with build type 'cmake'".
            format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask_()
        extension.set_context(context=self.context)

        rc = await extension.build(skip_hook_creation=True,
                                   environment_callback=add_app_to_cpp)

        # if the build has failed getting targets might not be possible
        try:
            has_install_target = await has_target(args.build_base, 'install')
        except Exception:
            if not rc:
                raise
            has_install_target = False

        additional_hooks = []
        if has_install_target:
            additional_hooks += create_pkg_config_path_environment_hooks(
                Path(args.install_base), self.context.pkg.name)

        create_environment_scripts(self.context.pkg,
                                   args,
                                   additional_hooks=additional_hooks)

        return rc
예제 #2
0
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info(
            "Building ROS package in '{args.path}' with build type 'catkin'".
            format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask()
        extension.set_context(context=self.context)

        # additional arguments
        if args.cmake_args is None:
            args.cmake_args = []
        args.cmake_args += ['-DCATKIN_INSTALL_INTO_PREFIX_ROOT=0']
        if args.test_result_base:
            # catkin appends the project name itself
            args.cmake_args.append('-DCATKIN_TEST_RESULTS_DIR=' +
                                   os.path.dirname(args.test_result_base))
        if args.catkin_cmake_args:
            args.cmake_args += args.catkin_cmake_args

        # additional hooks
        additional_hooks = create_environment_hook('ros_package_path',
                                                   Path(args.install_base),
                                                   self.context.pkg.name,
                                                   'ROS_PACKAGE_PATH',
                                                   'share',
                                                   mode='prepend')

        # for catkin packages add additional hooks after the package has
        # been built and installed depending on the installed files
        rc = await extension.build(skip_hook_creation=True)

        # add Python 2 specific path to PYTHONPATH if it exists
        if os.environ.get('ROS_PYTHON_VERSION', '2') == '2':
            for subdirectory in ('dist-packages', 'site-packages'):
                python_path = Path(args.install_base) / \
                    'lib' / 'python2.7' / subdirectory
                logger.log(1, "checking '%s'" % python_path)
                if python_path.exists():
                    rel_python_path = python_path.relative_to(
                        args.install_base)
                    additional_hooks += create_environment_hook(
                        'python2path',
                        Path(args.install_base),
                        self.context.pkg.name,
                        'PYTHONPATH',
                        str(rel_python_path),
                        mode='prepend')
        create_environment_scripts(self.context.pkg,
                                   args,
                                   additional_hooks=additional_hooks)

        # ensure that the install base has the marker file
        # identifying it as a catkin workspace
        marker = Path(args.install_base) / '.catkin'
        marker.touch(exist_ok=True)

        return rc
예제 #3
0
파일: build.py 프로젝트: seanyen/colcon-ros
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info("Building ROS package in '{args.path}' with build type "
                    "'ament_cmake'".format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask()
        extension.set_context(context=self.context)

        # additional arguments
        if args.test_result_base:
            if args.cmake_args is None:
                args.cmake_args = []
            # ament_cmake appends the project name itself
            args.cmake_args.append('-DAMENT_TEST_RESULTS_DIR=' +
                                   os.path.dirname(args.test_result_base))
        if args.symlink_install:
            if args.cmake_args is None:
                args.cmake_args = []
            args.cmake_args.append('-DAMENT_CMAKE_SYMLINK_INSTALL=1')
        if args.ament_cmake_args:
            if args.cmake_args is None:
                args.cmake_args = []
            args.cmake_args += args.ament_cmake_args

        rc = await extension.build(skip_hook_creation=False,
                                   environment_callback=add_app_to_cpp)

        # if the build has failed getting targets might not be possible
        try:
            has_install_target = await has_target(args.build_base, 'install')
        except Exception:  # noqa: B902
            if not rc:
                raise
            has_install_target = False

        # add a hook for each available shell
        # only if the package has an install target
        additional_hooks = []
        if has_install_target:
            shell_extensions = get_shell_extensions()
            file_extensions = []
            for shell_extensions_same_prio in shell_extensions.values():
                for shell_extension in shell_extensions_same_prio.values():
                    file_extensions += shell_extension.get_file_extensions()
            for ext in sorted(file_extensions):
                additional_hooks.append(
                    'share/{self.context.pkg.name}/local_setup.{ext}'.
                    format_map(locals()))

        create_environment_scripts(self.context.pkg,
                                   args,
                                   additional_hooks=additional_hooks)

        return rc
예제 #4
0
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info(
            "Building ROS package in '{args.path}' with build type 'cmake'".
            format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask_()
        extension.set_context(context=self.context)

        extend_cpp_with_app(args)

        return await extension.build()
예제 #5
0
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info("Building ROS package in '{args.path}' with build type "
                    "'ament_cmake'".format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask()
        extension.set_context(context=self.context)

        # add a hook for each available shell
        additional_hooks = create_environment_hook('ament_current_prefix',
                                                   Path(args.install_base),
                                                   self.context.pkg.name,
                                                   'AMENT_CURRENT_PREFIX',
                                                   '',
                                                   mode='prepend')
        shell_extensions = get_shell_extensions()
        file_extensions = []
        for shell_extensions_same_prio in shell_extensions.values():
            for shell_extension in shell_extensions_same_prio.values():
                file_extensions += shell_extension.get_file_extensions()
        for file_extension in sorted(file_extensions):
            additional_hooks.append(
                'share/{self.context.pkg.name}/local_setup.{file_extension}'.
                format_map(locals()))

        # additional arguments
        if args.test_result_base:
            if args.cmake_args is None:
                args.cmake_args = []
            # ament_cmake appends the project name itself
            args.cmake_args.append('-DAMENT_TEST_RESULTS_DIR=' +
                                   os.path.dirname(args.test_result_base))
        if args.symlink_install:
            if args.cmake_args is None:
                args.cmake_args = []
            args.cmake_args.append('-DAMENT_CMAKE_SYMLINK_INSTALL=1')
        if args.ament_cmake_args:
            if args.cmake_args is None:
                args.cmake_args = []
            args.cmake_args += args.ament_cmake_args

        return await extension.build(environment_callback=add_app_to_cpp,
                                     additional_hooks=additional_hooks)
예제 #6
0
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info(
            "Building ROS package in '{args.path}' with build type 'cmake'".
            format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask_()
        extension.set_context(context=self.context)

        rc = await extension.build(environment_callback=add_app_to_cpp)

        additional_hooks = create_pkg_config_path_environment_hooks(
            Path(args.install_base), self.context.pkg.name)

        create_environment_scripts(self.context.pkg,
                                   args,
                                   additional_hooks=additional_hooks)

        return rc
예제 #7
0
    async def build(self):  # noqa: D102
        args = self.context.args
        logger.info(
            "Building ROS package in '{args.path}' with build type 'catkin'".
            format_map(locals()))

        # reuse CMake build task with additional logic
        extension = CmakeBuildTask()
        extension.set_context(context=self.context)

        # additional arguments
        if args.cmake_args is None:
            args.cmake_args = []
        args.cmake_args += ['-DCATKIN_INSTALL_INTO_PREFIX_ROOT=0']
        if args.test_result_base:
            # catkin appends the project name itself
            args.cmake_args.append('-DCATKIN_TEST_RESULTS_DIR=' +
                                   os.path.dirname(args.test_result_base))
        if args.catkin_cmake_args:
            args.cmake_args += args.catkin_cmake_args

        # invoke the build
        additional_targets = []
        # if no specific target is specified consider building the 'tests'
        # target and continue if such a target doesn't exist
        if args.cmake_target is None:
            if not args.catkin_skip_building_tests:
                additional_targets.append('tests')
                args.cmake_target_skip_unavailable = True
        rc = await extension.build(skip_hook_creation=True,
                                   additional_targets=additional_targets)

        # for catkin packages add additional hooks after the package has
        # been built and installed depending on the installed files
        additional_hooks = create_environment_hook('ros_package_path',
                                                   Path(args.install_base),
                                                   self.context.pkg.name,
                                                   'ROS_PACKAGE_PATH',
                                                   'share',
                                                   mode='prepend')
        additional_hooks += create_pythonpath_environment_hook(
            Path(args.install_base), self.context.pkg.name)
        additional_hooks += create_pkg_config_path_environment_hooks(
            Path(args.install_base), self.context.pkg.name)

        # register hooks created via catkin_add_env_hooks
        shell_extensions = get_shell_extensions()
        file_extensions = OrderedDict()
        for shell_extensions_same_prio in shell_extensions.values():
            for shell_extension in shell_extensions_same_prio.values():
                for file_extension in shell_extension.get_file_extensions():
                    file_extensions[file_extension] = shell_extension
        custom_hooks_path = Path(args.install_base) / \
            'share' / self.context.pkg.name / 'catkin_env_hook'
        for file_extension, shell_extension in file_extensions.items():
            file_extension_hooks = sorted(
                custom_hooks_path.glob('*.{file_extension}'.format_map(
                    locals())))
            if file_extension_hooks:
                try:
                    # try to set CATKIN_ENV_HOOK_WORKSPACE explicitly before
                    # sourcing these hooks
                    additional_hooks.append(
                        shell_extension.create_hook_set_value(
                            'catkin_env_hook_workspace',
                            Path(args.install_base), self.context.pkg.name,
                            'CATKIN_ENV_HOOK_WORKSPACE',
                            '$COLCON_CURRENT_PREFIX'))
                except NotImplementedError:
                    # since not all shell extensions might implement this
                    pass
                additional_hooks += file_extension_hooks

        create_environment_scripts(self.context.pkg,
                                   args,
                                   additional_hooks=additional_hooks)

        # ensure that the install base has the marker file
        # identifying it as a catkin workspace
        marker = Path(args.install_base) / '.catkin'
        marker.touch(exist_ok=True)

        return rc
예제 #8
0
파일: ros.py 프로젝트: lelongg/colcon-ros
    async def build(self):  # noqa: D102
        args = self.context.args

        # get build type of package from manifest
        pkg, build_type = get_package_with_build_type(args.path)
        logger.info("Building ROS package in '{args.path}' with build type "
                    "'{build_type}'".format_map(locals()))

        # choose the task extension and additional hooks and arguments
        additional_hooks = []
        if build_type == 'ament_cmake':
            extension = CmakeBuildTask()
            additional_hooks += [
                'share/{pkg.name}/local_setup.bash'.format_map(locals()),
                'share/{pkg.name}/local_setup.bat'.format_map(locals()),
                'share/{pkg.name}/local_setup.ps1'.format_map(locals()),
                'share/{pkg.name}/local_setup.sh'.format_map(locals()),
            ]
            if args.test_result_base:
                if args.cmake_args is None:
                    args.cmake_args = []
                # ament_cmake appends the project name itself
                args.cmake_args.append('-DAMENT_TEST_RESULTS_DIR=' +
                                       os.path.dirname(args.test_result_base))
            if args.symlink_install:
                if args.cmake_args is None:
                    args.cmake_args = []
                args.cmake_args.append('-DAMENT_CMAKE_SYMLINK_INSTALL=1')
            if args.ament_cmake_args:
                if args.cmake_args is None:
                    args.cmake_args = []
                args.cmake_args += args.ament_cmake_args
            # extend CMAKE_PREFIX_PATH with AMENT_PREFIX_PATH
            ament_prefix_path = os.environ.get('AMENT_PREFIX_PATH')
            if ament_prefix_path:
                ament_prefix_path = ament_prefix_path.replace(os.pathsep, ';')
                if args.cmake_args is None:
                    args.cmake_args = []
                # check if the CMAKE_PREFIX_PATH is explicitly set
                prefix = '-DCMAKE_PREFIX_PATH='
                for i, value in reversed(list(enumerate(args.cmake_args))):
                    if not value.startswith(prefix):
                        continue
                    # extend the last existing entry
                    existing = value[len(prefix):]
                    if existing:
                        existing = ';' + existing
                    args.cmake_args[i] = \
                        '-DCMAKE_PREFIX_PATH={ament_prefix_path}{existing}' \
                        .format_map(locals())
                    break
                else:
                    # otherwise extend the environment variable
                    existing = os.environ.get('CMAKE_PREFIX_PATH', '')
                    if existing:
                        existing = ';' + existing.replace(os.pathsep, ';')
                    args.cmake_args.append(
                        '-DCMAKE_PREFIX_PATH={ament_prefix_path}{existing}'.
                        format_map(locals()))

        elif build_type == 'ament_python':
            extension = PythonBuildTask()
            additional_hooks += create_environment_hook('ament_prefix_path',
                                                        Path(
                                                            args.install_base),
                                                        pkg.name,
                                                        'AMENT_PREFIX_PATH',
                                                        '',
                                                        mode='prepend')
            # create package marker in ament resource index
            create_file(
                args, 'share/ament_index/resource_index/packages/{pkg.name}'.
                format_map(locals()))
            # copy / symlink package manifest
            install(args, 'package.xml',
                    'share/{pkg.name}/package.xml'.format_map(locals()))

        elif build_type == 'catkin':
            extension = CmakeBuildTask()
            if args.cmake_args is None:
                args.cmake_args = []
            args.cmake_args += ['-DCATKIN_INSTALL_INTO_PREFIX_ROOT=0']
            if args.test_result_base:
                # catkin appends the project name itself
                args.cmake_args.append('-DCATKIN_TEST_RESULTS_DIR=' +
                                       os.path.dirname(args.test_result_base))
            if args.catkin_cmake_args:
                args.cmake_args += args.catkin_cmake_args
            additional_hooks += create_environment_hook('ros_package_path',
                                                        Path(
                                                            args.install_base),
                                                        pkg.name,
                                                        'ROS_PACKAGE_PATH',
                                                        'share',
                                                        mode='prepend')

        elif build_type == 'cmake':
            extension = CmakeBuildTask()

        elif build_type == 'cargo':
            extension = CargoBuildTask()
            additional_hooks += create_environment_hook('ament_prefix_path',
                                                        Path(
                                                            args.install_base),
                                                        pkg.name,
                                                        'AMENT_PREFIX_PATH',
                                                        '',
                                                        mode='prepend')
            # create package marker in ament resource index
            create_file(
                args, 'share/ament_index/resource_index/packages/{pkg.name}'.
                format_map(locals()))
            # copy / symlink package manifest
            install(args, 'package.xml',
                    'share/{pkg.name}/package.xml'.format_map(locals()))

        else:
            assert False, 'Unknown build type: ' + build_type

        extension.set_context(context=self.context)
        if build_type != 'catkin':
            return await extension.build(additional_hooks=additional_hooks)
        else:
            # for catkin packages add additional hooks after the package has
            # been built and installed depending on the installed files
            rc = await extension.build(skip_hook_creation=True)

            # add Python 2 specific path to PYTHONPATH if it exists
            if os.environ.get('ROS_PYTHON_VERSION', '2') == '2':
                for subdirectory in ('dist-packages', 'site-packages'):
                    python_path = Path(args.install_base) / \
                        'lib' / 'python2.7' / subdirectory
                    logger.log(1, "checking '%s'" % python_path)
                    if python_path.exists():
                        rel_python_path = python_path.relative_to(
                            args.install_base)
                        additional_hooks += create_environment_hook(
                            'python2path',
                            Path(args.install_base),
                            pkg.name,
                            'PYTHONPATH',
                            str(rel_python_path),
                            mode='prepend')
            create_environment_scripts(self.context.pkg,
                                       args,
                                       additional_hooks=additional_hooks)

            # ensure that the install base has the marker file
            # identifying it as a catkin workspace
            marker = Path(args.install_base) / '.catkin'
            marker.touch(exist_ok=True)

            return rc