Beispiel #1
0
 def _get_configuration_from_cmake(self, build_base):
     # get for CMake build type from the CMake cache
     build_type = get_variable_from_cmake_cache(build_base,
                                                'CMAKE_BUILD_TYPE')
     if build_type in ('Debug', 'MinSizeRel', 'RelWithDebInfo'):
         return build_type
     return 'Release'
Beispiel #2
0
def create_pythonpath_environment_hook(build_base, install_base, pkg_name):
    """
    Create a hook script for each primary shell to prepend to the PYTHONPATH.

    :param str build_base: The path of the build directory
    :param Path install_base: The path of the install prefix
    :param str pkg_name: The package name
    :returns: The relative paths to the created hook scripts
    :rtype: list
    """
    hooks = []
    # catkin packages might use `--install-layout deb`
    # therefore getting the used install directory from the CMake cache
    # since it might not match distutils.sysconfig.get_python_lib()
    rel_python_path = get_variable_from_cmake_cache(build_base,
                                                    'PYTHON_INSTALL_DIR')
    # prepend Python specific path to PYTHONPATH if it exists
    if rel_python_path:
        abs_python_path = install_base / rel_python_path
        logger.log(1, "checking '%s'" % abs_python_path)
        if abs_python_path.exists():
            hooks += create_environment_hook('catkin_pythonpath',
                                             install_base,
                                             pkg_name,
                                             'PYTHONPATH',
                                             rel_python_path,
                                             mode='prepend')
    return hooks
Beispiel #3
0
    async def build(  # noqa: D102
            self,
            *,
            additional_hooks=None,
            skip_hook_creation=False,
            environment_callback=None,
            additional_targets=None):
        pkg = self.context.pkg
        args = self.context.args

        logger.info("Building CMake package in '{args.path}'".format_map(
            locals()))

        try:
            env = await get_command_environment('build', args.build_base,
                                                self.context.dependencies)
        except RuntimeError as e:
            logger.error(str(e))
            return 1

        if environment_callback is not None:
            environment_callback(env)

        rc = await self._reconfigure(args, env)
        if rc:
            return rc

        # ensure that CMake cache contains the project name
        project_name = get_variable_from_cmake_cache(args.build_base,
                                                     'CMAKE_PROJECT_NAME')
        if project_name is None:
            # if not the CMake code hasn't called project() and can't be built
            logger.warning(
                "Could not build CMake package '{pkg.name}' because the "
                "CMake cache has no 'CMAKE_PROJECT_NAME' variable".format_map(
                    locals()))
            return

        rc = await self._build(args,
                               env,
                               additional_targets=additional_targets)
        if rc:
            return rc

        # skip install step if a specific target was requested
        if not args.cmake_target:
            if await has_target(args.build_base, 'install'):
                completed = await self._install(args, env)
                if completed.returncode:
                    return completed.returncode
            else:
                logger.warning(
                    "Could not run installation step for package '{pkg.name}' "
                    "because it has no 'install' target".format_map(locals()))

        if not skip_hook_creation:
            create_environment_scripts(pkg,
                                       args,
                                       additional_hooks=additional_hooks)
Beispiel #4
0
 def _get_configuration(self, args):
     # check for CMake build type in the command line arguments
     arg_prefix = '-DCMAKE_BUILD_TYPE='
     build_type = None
     for cmake_arg in (args.cmake_args or []):
         if cmake_arg.startswith(arg_prefix):
             build_type = cmake_arg[len(arg_prefix):]
     if build_type is None:
         # get the CMake build type from the CMake cache
         build_type = get_variable_from_cmake_cache(args.build_base,
                                                    'CMAKE_BUILD_TYPE')
     if build_type in ('Debug', 'MinSizeRel', 'RelWithDebInfo'):
         return build_type
     return 'Release'