Exemplo n.º 1
0
def make_isolated_main():
    args = _parse_args()

    # disable colors if asked
    if args.no_color:
        terminal_color.disable_ANSI_colors()

    # Default paths
    base_path = os.path.abspath('.')
    source_path = os.path.join(base_path, 'src')
    build_path = os.path.join(base_path, 'build')
    devel_path = os.path.join(base_path, 'devel')
    install_path = config_cache.get_install_prefix_from_config_cmake()
    unused_catkin_toplevel, catkin_python_path, catkin_cmake_path = common.find_catkin()

    # Clear out previous temporaries if requested
    if args.pre_clean:
        console.pretty_print("Pre-cleaning before building.", console.cyan)
        shutil.rmtree(devel_path, ignore_errors=True)
        shutil.rmtree(build_path, ignore_errors=True)
        shutil.rmtree(install_path, ignore_errors=True)


    if not os.path.exists(build_path):
        os.mkdir(build_path)

    make.validate_build_space(base_path)  # raises a RuntimeError if there is a problem

    build_workspace_isolated(
        workspace=base_path,
        sourcespace=source_path,
        buildspace=build_path,
        develspace=devel_path,
        installspace=install_path,
        merge=args.merge,
        install=args.install,
        jobs=args.jobs,
        force_cmake=args.force_cmake,
        build_packages=args.packages,
        quiet=args.quiet,
        cmake_args=args.cmake_args,
        make_args=args.make_args,
        catkin_cmake_path=catkin_cmake_path,
        catkin_python_path=catkin_python_path
    )
Exemplo n.º 2
0
def make_main():
    args = _parse_args()
    cmake_args = args.cmake_args

    # disable colors if asked
    if args.no_color:
        terminal_color.disable_ANSI_colors()

    # Default paths
    base_path = os.path.abspath('.')
    build_path = os.path.join(base_path, 'build')
    devel_path = os.path.join(base_path, 'devel')
    source_path = os.path.join(base_path, 'src')

    validate_build_space(base_path)  # raises a RuntimeError if there is a problem

    # Clear out previous temporaries if requested
    if args.pre_clean:
        console.pretty_print("Pre-cleaning before building.", console.cyan)
        shutil.rmtree(devel_path, ignore_errors=True)
        shutil.rmtree(build_path, ignore_errors=True)

    # check for new build
    if not os.path.exists(build_path):
        os.mkdir(build_path)
    #if not os.path.exists(devel_path):
    #    os.mkdir(devel_path)

    # ensure toplevel cmake file exists
    toplevel_cmake = os.path.join(source_path, 'CMakeLists.txt')
    if not os.path.exists(toplevel_cmake):
        return fmt('@{rf}No toplevel cmake file@')

    packages = find_packages(source_path, exclude_subspaces=True)

    # verify that specified package exists in workspace
    if args.pkg:
        packages_by_name = {p.name: path for path, p in packages.iteritems()}
        if args.pkg not in packages_by_name:
            raise RuntimeError('Package %s not found in the workspace' % args.pkg)

    # check if cmake must be run (either for a changed list of package paths or changed cmake arguments)
    force_cmake, _ = builder.cmake_input_changed(packages, build_path, cmake_args=cmake_args)

    # check if toolchain.cmake, config.cmake exist
    toolchain_cmd = "-DCMAKE_TOOLCHAIN_FILE=%s" % os.path.join(base_path, 'toolchain.cmake') if os.path.isfile(os.path.join(base_path, 'toolchain.cmake')) else None
    config_cmd = "-C%s" % os.path.join(base_path, 'config.cmake') if os.path.isfile(os.path.join(base_path, 'config.cmake')) else None

    # Help find catkin cmake and python
    unused_catkin_toplevel, catkin_python_path, unused_catkin_cmake_path = common.find_catkin()
    env = os.environ.copy()
    try:
        env['PYTHONPATH'] = env['PYTHONPATH'] + os.pathsep + catkin_python_path
    except KeyError:
        env['PYTHONPATH'] = catkin_python_path

    # consider calling cmake
    makefile = os.path.join(build_path, 'Makefile')
    if not os.path.exists(makefile) or args.force_cmake or force_cmake:
        cmd = ['cmake', source_path]
        if toolchain_cmd:
            cmd.append(toolchain_cmd)
        if config_cmd:
            cmd.append(config_cmd)
        cmd += cmake_args

        try:
            builder.print_command_banner(cmd, build_path, color=not args.no_color)
            if args.no_color:
                builder.run_command(cmd, build_path, env=env)
            else:
                builder.run_command_colorized(cmd, build_path, env=env)
        except subprocess.CalledProcessError:
            return fmt('@{rf}Invoking @{boldon}"cmake"@{boldoff} failed')
    else:
        cmd = ['make', 'cmake_check_build_system']
        try:
            builder.print_command_banner(cmd, build_path, color=not args.no_color)
            if args.no_color:
                builder.run_command(cmd, build_path, env=env)
            else:
                builder.run_command_colorized(cmd, build_path, env=env)
        except subprocess.CalledProcessError:
            return fmt('@{rf}Invoking @{boldon}"make cmake_check_build_system"@{boldoff} failed')

    # invoke make
    if args.install:
        cmd = ['make', 'install']
    elif args.tests:
        cmd = ['make', 'tests']
    elif args.run_tests:
        cmd = ['make', 'run_tests']
    else:
        cmd = ['make']
    jobs = args.jobs
    if args.jobs == '':
        cmd.append('-j')
    else:
        jobs = args.jobs
        if not jobs:
            if 'ROS_PARALLEL_JOBS' in os.environ:
                ros_parallel_jobs = os.environ['ROS_PARALLEL_JOBS']
                cmd += [arg for arg in ros_parallel_jobs.split(' ') if arg]
            else:
                jobs = multiprocessing.cpu_count()
        if jobs:
            cmd.append('-j%d' % jobs)
            cmd.append('-l%d' % jobs)
    cmd += args.make_args
    try:
        make_path = build_path
        if args.pkg:
            make_path = os.path.join(make_path, packages_by_name[args.pkg])
        builder.print_command_banner(cmd, make_path, color=not args.no_color)
        builder.run_command(cmd, make_path, env=env)
    except subprocess.CalledProcessError:
        return fmt('@{rf}Invoking @{boldon}"make"@{boldoff} failed')
Exemplo n.º 3
0
def init_configured_build(build_dir_="./", source_dir_="./src", underlays_="/opt/ros/groovy", install_prefix_="./install", release_=False, toolchain_="", platform_=""):
    '''
      This one is used with pre-configured parameters. Note that
      init_build generates parameters parsed from the command line and then
      calls this function.
    '''
    # Help us build the name for the eclipse workspace...usually we call in the workspace itself.
    workspace_dir = os.getcwd()

    ##########################
    # Build directory
    ##########################
    if os.path.isabs(build_dir_):
        build_dir = build_dir_
    else:
        if build_dir_ == "." or build_dir_ == "./":
            build_dir = os.getcwd()
        else:
            build_dir = os.path.join(os.getcwd(), build_dir_)
    if not os.path.isfile(os.path.join(build_dir, "Makefile")):
        if not os.path.isdir(build_dir):  # remember ./ is a valid build dir, even if it's not populated yet
            os.mkdir(build_dir)
    else:
        raise RuntimeError("This build directory is already initialised")

    ##########################
    # Source directory
    ##########################
    source_dir = os.path.abspath(source_dir_)
    build_source_dir = os.path.join(build_dir, 'src')
    if not os.path.isdir(source_dir):
        raise RuntimeError("Specified source space does not exist [" + source_dir + "]")
    if not os.path.isfile(os.path.join(source_dir, ".rosinstall")):
        raise RuntimeError("Could not find a valid source folder (must contain a .rosinstall file therein)'")
    if os.path.exists(build_source_dir):
        if not source_dir == build_source_dir:
            raise RuntimeError("The build directory already has a ./src directory which doesn't match the desired source directory [%s]" % source_dir)
    else:
        os.mkdir(build_source_dir)
        source_subdirectories = os.walk(source_dir).next()[1]
        for d in source_subdirectories:
            common.create_symlink(os.path.join(source_dir, d), os.path.join(build_source_dir, d))

    ##########################
    # Underlays
    ##########################
    try:
        env_underlays = os.environ['CMAKE_PREFIX_PATH']
    except KeyError:
        env_underlays = ""
    underlays_list = [underlay for underlay in underlays_.split(';') if underlay]
    env_underlays_list = [underlay for underlay in env_underlays.split(':') if underlay]
    for underlay in env_underlays_list:
        if underlay not in underlays_list:
            underlays_list.append(underlay)

    ##########################
    # Locate Catkin
    ##########################
    catkin_toplevel = None
    if os.path.isfile(os.path.join(source_dir, 'catkin', 'cmake', 'toplevel.cmake')):
        catkin_toplevel = os.path.join(source_dir, 'catkin', 'cmake', 'toplevel.cmake')
    else:
        catkin_toplevel, unused_catkin_python_path, unused_catkin_cmake_path = common.find_catkin(underlays_list)

    ##########################
    # Add toplevel if exists
    ##########################
    if not catkin_toplevel:
        # Add the default track underlay
        default_track = settings.get_default_track()
        if os.path.isfile(os.path.join("/opt/ros/%s" % default_track, 'share', 'catkin', 'cmake', 'toplevel.cmake')):
            catkin_toplevel = os.path.join("/opt/ros/%s" % default_track, 'share', 'catkin', 'cmake', 'toplevel.cmake')
            unused_catkin_python_path = os.path.join("/opt/ros/%s" % default_track, 'lib', 'python2.7', 'dist-packages')
            console.pretty_println("No catkin found, adding the default track underlay (use yujin_tools_settings to change) [/opt/ros/%s]" % default_track, console.cyan)
            underlays_list.append("/opt/ros/%s" % default_track)
        else:
            raise RuntimeError("Could not find an underlying catkin installation.")
    common.create_symlink(catkin_toplevel, os.path.join(build_source_dir, "CMakeLists.txt"))
    underlays = ';'.join(underlays_list)

    ##########################
    # Other Args
    ##########################
    if install_prefix_ == "/not_set_directory":
        install_prefix = os.path.join(build_dir, "install")
    else:
        install_prefix = install_prefix_
    if release_:
        build_type = "Release"
    else:
        build_type = "DebugWithRelSymbols"
    name = os.path.basename(workspace_dir) + "_" + os.path.basename(build_dir)

    print_build_details(build_dir, source_dir, install_prefix, build_type, underlays, name, toolchain_, platform_)
    os.chdir(build_dir)

    ##########################
    # Toolchain
    ##########################
    if not toolchain_ == "":
        toolchains_dir = os.path.join(os.path.dirname(__file__), 'toolchains')
        custom_toolchains_dir = os.path.join(settings.yujin_tools_home(), 'toolchains')
        tmp_list = toolchain_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError("Toolchain specification invalid, must be <family>/<tuple> [%s]" % toolchain_)
        family = tmp_list[0]
        toolchain_tuple = tmp_list[1]
        toolchains = get_toolchains_or_platforms(toolchains_dir)
        custom_toolchains = get_toolchains_or_platforms(custom_toolchains_dir)
        if not family in toolchains and not family in custom_toolchains:
            raise RuntimeError("No toolchains available for family %s" % family)
        if family in toolchains and toolchain_tuple in toolchains[family]:
            toolchain_file = os.path.join(toolchains_dir, family, toolchain_tuple + ".cmake")
        elif family in custom_toolchains and toolchain_tuple in custom_toolchains[family]:
            toolchain_file = os.path.join(custom_toolchains_dir, family, toolchain_tuple + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." % (family, toolchain_tuple))
        if os.path.isfile(toolchain_file):
            shutil.copy(toolchain_file, os.path.join(build_dir, "toolchain.cmake"))
        else:
            raise RuntimeError("Toolchain module not available [%s]" % toolchain_file)

    ##########################
    # Platform
    ##########################
    platform_content = ""
    platforms_dir = os.path.join(os.path.dirname(__file__), 'platforms')
    custom_platforms_dir = os.path.join(settings.yujin_tools_home(), 'platforms')
    if not platform_ == "default":
        tmp_list = platform_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError("Platform specification invalid, must be <family>/<platform type> [%s]" % platform_)
        family = tmp_list[0]
        platform = tmp_list[1]
        platforms = get_toolchains_or_platforms(platforms_dir)
        custom_platforms = get_toolchains_or_platforms(custom_platforms_dir)
        if not family in platforms and not family in custom_platforms:
            raise RuntimeError("No platforms available for family %s" % family)
        if family in platforms and platform in platforms[family]:
            platform_file = os.path.join(platforms_dir, family, platform + ".cmake")
        elif family in custom_platforms and platform in custom_platforms[family]:
            platform_file = os.path.join(custom_platforms_dir, family, platform + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." % (family, platform))
    else:
        platform_file = os.path.join(platforms_dir, 'default.cmake')
    if os.path.isfile(platform_file):
        f = open(platform_file, 'r')
        try:
            platform_content = f.read()
        finally:
            f.close()
    else:
        raise RuntimeError("Platform configuration not available [%s]" % platform_)

    ##########################
    # Cache
    ##########################
    instantiate_config_cmake(platform_content, build_dir, build_type, install_prefix, underlays)

    ##########################
    # Templates
    ##########################
    instantiate_template('.bashrc', name, build_dir)
    instantiate_template('konsole', name, build_dir)
    instantiate_template('gnome-terminal', name, build_dir)
    instantiate_template('eclipse', name, build_dir)
Exemplo n.º 4
0
def init_configured_build(default_underlay,
                          build_dir_="./",
                          source_dir_="./src",
                          underlays_="/opt/ros/groovy",
                          install_prefix_="./install",
                          doc_prefix_="./doc",
                          release_=False,
                          toolchain_="",
                          platform_=""):
    '''
      This one is used with pre-configured parameters. Note that
      init_build generates parameters parsed from the command line and then
      calls this function.
    '''
    # Help us build the name for the eclipse workspace...usually we call in the workspace itself.
    workspace_dir = os.getcwd()

    ##########################
    # Build directory
    ##########################
    if os.path.isabs(build_dir_):
        build_dir = build_dir_
    else:
        if build_dir_ == "." or build_dir_ == "./":
            build_dir = os.getcwd()
        else:
            build_dir = os.path.join(os.getcwd(), build_dir_)
    if not os.path.isfile(os.path.join(build_dir, "Makefile")):
        if not os.path.isdir(
                build_dir
        ):  # remember ./ is a valid build dir, even if it's not populated yet
            os.mkdir(build_dir)
    else:
        raise RuntimeError("This build directory is already initialised")

    ##########################
    # Source directory
    ##########################
    source_dir = os.path.abspath(source_dir_)
    build_source_dir = os.path.join(build_dir, 'src')
    if not os.path.isdir(source_dir):
        raise RuntimeError("Specified source space does not exist [" +
                           source_dir + "]")
    if not os.path.isfile(os.path.join(source_dir, ".rosinstall")):
        raise RuntimeError(
            "Could not find a valid source folder (must contain a .rosinstall file therein)'"
        )
    if os.path.exists(build_source_dir):
        if not source_dir == build_source_dir:
            raise RuntimeError(
                "The build directory already has a ./src directory which doesn't match the desired source directory [%s]"
                % source_dir)
    else:
        os.mkdir(build_source_dir)
        source_subdirectories = os.walk(source_dir).next()[1]
        for d in source_subdirectories:
            common.create_symlink(os.path.join(source_dir, d),
                                  os.path.join(build_source_dir, d))
    write_yujin_init_build_configuration(build_source_dir, source_dir)

    ##########################
    # Underlays
    ##########################
    try:
        env_underlays = os.environ['CMAKE_PREFIX_PATH']
    except KeyError:
        env_underlays = ""
    underlays_list = [
        underlay for underlay in underlays_.split(';') if underlay
    ]
    env_underlays_list = [
        underlay for underlay in env_underlays.split(':') if underlay
    ]
    for underlay in env_underlays_list:
        if underlay not in underlays_list:
            underlays_list.append(underlay)

    ##########################
    # Locate Catkin
    ##########################
    catkin_toplevel = None
    if os.path.isfile(
            os.path.join(source_dir, 'catkin', 'cmake', 'toplevel.cmake')):
        catkin_toplevel = os.path.join(source_dir, 'catkin', 'cmake',
                                       'toplevel.cmake')
    else:
        catkin_toplevel, unused_catkin_python_path, unused_catkin_cmake_path = common.find_catkin(
            build_dir, underlays_list)

    ##########################
    # Add toplevel if exists
    ##########################
    if not catkin_toplevel:
        # Add the default underlay
        if default_underlay is not None and os.path.isfile(
                os.path.join("/opt/ros/%s" % default_underlay, 'share',
                             'catkin', 'cmake', 'toplevel.cmake')):
            catkin_toplevel = os.path.join("/opt/ros/%s" % default_underlay,
                                           'share', 'catkin', 'cmake',
                                           'toplevel.cmake')
            unused_catkin_python_path = os.path.join(
                "/opt/ros/%s" % default_underlay, 'lib', 'python2.7',
                'dist-packages')
            console.pretty_println(
                "No catkin found, adding the default underlay (use yujin_tools_settings to change) [/opt/ros/%s]"
                % default_underlay, console.cyan)
            underlays_list.append("/opt/ros/%s" % default_underlay)
        else:
            raise RuntimeError(
                "Could not find an underlying catkin installation.")
    common.create_symlink(catkin_toplevel,
                          os.path.join(build_source_dir, "CMakeLists.txt"))
    underlays = ';'.join(underlays_list)

    ##########################
    # Other Args
    ##########################
    if install_prefix_ == "/not_set_directory":
        install_prefix = os.path.join(build_dir, "install")
    else:
        install_prefix = install_prefix_

    if doc_prefix_ == "/not_set_directory":
        doc_prefix = os.path.join(build_dir, "doc")
    else:
        doc_prefix = doc_prefix_

    if release_:
        build_type = "Release"
    else:
        build_type = "RelWithDebInfo"
    name = os.path.basename(workspace_dir) + "_" + os.path.basename(build_dir)

    print_build_details(build_dir, source_dir, install_prefix, doc_prefix,
                        build_type, underlays, name, toolchain_, platform_)
    os.chdir(build_dir)

    ##########################
    # Toolchain
    ##########################
    if not toolchain_ == "":
        toolchains_dir = os.path.join(os.path.dirname(__file__), 'toolchains')
        custom_toolchains_dir = os.path.join(settings.yujin_tools_home(),
                                             'toolchains')
        tmp_list = toolchain_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError(
                "Toolchain specification invalid, must be <family>/<tuple> [%s]"
                % toolchain_)
        family = tmp_list[0]
        toolchain_tuple = tmp_list[1]
        toolchains = get_toolchains_or_platforms(toolchains_dir)
        custom_toolchains = get_toolchains_or_platforms(custom_toolchains_dir)
        if not family in toolchains and not family in custom_toolchains:
            raise RuntimeError("No toolchains available for family %s" %
                               family)
        if family in custom_toolchains and toolchain_tuple in custom_toolchains[
                family]:
            toolchain_file = os.path.join(custom_toolchains_dir, family,
                                          toolchain_tuple + ".cmake")
        elif family in toolchains and toolchain_tuple in toolchains[family]:
            toolchain_file = os.path.join(toolchains_dir, family,
                                          toolchain_tuple + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." %
                               (family, toolchain_tuple))
        if os.path.isfile(toolchain_file):
            shutil.copy(toolchain_file,
                        os.path.join(build_dir, "toolchain.cmake"))
        else:
            raise RuntimeError("Toolchain module not available [%s]" %
                               toolchain_file)

    ##########################
    # Platform
    ##########################
    platform_content = ""
    platforms_dir = os.path.join(os.path.dirname(__file__), 'platforms')
    custom_platforms_dir = os.path.join(settings.yujin_tools_home(),
                                        'platforms')
    if not platform_ == "default":
        tmp_list = platform_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError(
                "Platform specification invalid, must be <family>/<platform type> [%s]"
                % platform_)
        family = tmp_list[0]
        platform = tmp_list[1]
        platforms = get_toolchains_or_platforms(platforms_dir)
        custom_platforms = get_toolchains_or_platforms(custom_platforms_dir)
        if not family in platforms and not family in custom_platforms:
            raise RuntimeError("No platforms available for family %s" % family)
        if family in custom_platforms and platform in custom_platforms[family]:
            platform_file = os.path.join(custom_platforms_dir, family,
                                         platform + ".cmake")
        elif family in platforms and platform in platforms[family]:
            platform_file = os.path.join(platforms_dir, family,
                                         platform + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." %
                               (family, platform))
    else:
        platform_file = os.path.join(platforms_dir, 'default.cmake')

    if os.path.isfile(platform_file):
        f = open(platform_file, 'r')
        try:
            platform_content = f.read()
        finally:
            f.close()
    else:
        raise RuntimeError("Platform configuration not available [%s]" %
                           platform_)

    ##########################
    # Cache
    ##########################
    instantiate_config_cmake(platform_content, build_dir, build_type,
                             install_prefix, doc_prefix, underlays)

    ##########################
    # Templates
    ##########################
    instantiate_template('.bashrc', name, build_dir)
    instantiate_template('konsole', name, build_dir)
    instantiate_template('gnome-terminal', name, build_dir)
    instantiate_template('eclipse', name, build_dir)
    instantiate_template('android-studio', name, build_dir)
Exemplo n.º 5
0
def make_main():
    args = _parse_args()
    cmake_args = args.cmake_args

    if args.no_color:
        terminal_color.disable_ANSI_colors()

    (base_path, build_path, devel_path, source_path) = common.get_default_paths()
    doc_path = config_cache.get_doc_prefix_from_config_cmake(base_path)

    validate_build_space(base_path)  # raises a RuntimeError if there is a problem

    # Install rosdeps if requested
    if args.install_rosdeps:
        install_rosdeps(base_path, source_path, settings.get_default_track(), args.no_color)
        return
    if args.install_rosdeps_track is not None:
        install_rosdeps(source_path, args.install_rosdeps_track, args.no_color)
        return

    # Clear out previous temporaries if requested
    if args.pre_clean:
        console.pretty_print("Pre-cleaning before building.", console.cyan)
        shutil.rmtree(devel_path, ignore_errors=True)
        shutil.rmtree(build_path, ignore_errors=True)
        shutil.rmtree(doc_path, ignore_errors=True)

    # check for new build
    if not os.path.exists(build_path):
        os.mkdir(build_path)
    #if not os.path.exists(devel_path):
    #    os.mkdir(devel_path)

    # ensure toplevel cmake file exists
    toplevel_cmake = os.path.join(source_path, 'CMakeLists.txt')
    if not os.path.exists(toplevel_cmake):
        return fmt('@{rf}No toplevel cmake file@')

    # did source paths get added to the original location?
    check_and_update_source_repo_paths(source_path)

    packages = find_packages(source_path, exclude_subspaces=True)

    # verify that specified package exists in workspace
    if args.pkg:
        packages_by_name = {p.name: path for path, p in packages.iteritems()}
        if args.pkg not in packages_by_name:
            raise RuntimeError('Package %s not found in the workspace' % args.pkg)

    # check if cmake must be run (either for a changed list of package paths or changed cmake arguments)
    force_cmake, _ = builder.cmake_input_changed(packages, build_path, cmake_args=cmake_args)

    # check if toolchain.cmake, config.cmake exist
    toolchain_cmd = "-DCMAKE_TOOLCHAIN_FILE=%s" % os.path.join(base_path, 'toolchain.cmake') if os.path.isfile(os.path.join(base_path, 'toolchain.cmake')) else None
    config_cmd = "-C%s" % os.path.join(base_path, 'config.cmake') if os.path.isfile(os.path.join(base_path, 'config.cmake')) else None

    # Help find catkin cmake and python
    unused_catkin_toplevel, catkin_python_path, unused_catkin_cmake_path = common.find_catkin(base_path)
    pkg_config_paths = common.generate_pkg_config_path(base_path)
    env = os.environ.copy()
    # PYTHONPATH
    # Don't add to the environment variable - this mucks up catkin's catkin_generated/setup_cached.py
    # environment later (how? I can't remember - something to do with the default underlay).
    # Maybe we can do away with this now catkin can look up install spaces?
    #try:
    #    env['PYTHONPATH'] = env['PYTHONPATH'] + os.pathsep + catkin_python_path
    #except KeyError:
    #    env['PYTHONPATH'] = catkin_python_path
    sys.path.append(catkin_python_path)
    # PKG_CONFIG_PATH
    for path in pkg_config_paths:
        try:
            env['PKG_CONFIG_PATH'] = env['PKG_CONFIG_PATH'] + os.pathsep + path
        except KeyError:
            env['PKG_CONFIG_PATH'] = path

    if args.doc_only:
        console.pretty_println('Generates documents only', console.bold_white)
        make_doc(source_path, doc_path, packages)
        return

    # consider calling cmake
    makefile = os.path.join(build_path, 'Makefile')
    if not os.path.exists(makefile) or args.force_cmake or force_cmake:
        cmd = ['cmake', source_path]
        if toolchain_cmd:
            cmd.append(toolchain_cmd)
        if config_cmd:
            cmd.append(config_cmd)
        cmd += cmake_args

        #new_env = common.generate_underlays_environment(base_path)
        try:
            builder.print_command_banner(cmd, build_path, color=not args.no_color)
            if args.no_color:
                builder.run_command(cmd, build_path, env=env)
            else:
                builder.run_command_colorized(cmd, build_path, env=env)
        except subprocess.CalledProcessError:
            return fmt('@{rf}Invoking @{boldon}"cmake"@{boldoff} failed')
    else:
        cmd = ['make', 'cmake_check_build_system']
        #new_env = common.generate_environment(base_path) # underlays + current workspace
        try:
            builder.print_command_banner(cmd, build_path, color=not args.no_color)
            if args.no_color:
                builder.run_command(cmd, build_path, env=env)
            else:
                builder.run_command_colorized(cmd, build_path, env=env)
        except subprocess.CalledProcessError:
            return fmt('@{rf}Invoking @{boldon}"make cmake_check_build_system"@{boldoff} failed')

    insert_yujin_make_signature(base_path, devel_path)

    # invoke make
    if not args.cmake_only:
        if args.target:
            cmd = ['make', args.target]
        elif args.install:
            cmd = ['make', 'install']
        elif args.tests:
            cmd = ['make', 'tests']
        elif args.run_tests:
            cmd = ['make', 'test']
        else:
            cmd = ['make']
        jobs = args.jobs
        if args.jobs == '':
            cmd.append('-j')
        else:
            jobs = args.jobs
            if not jobs:
                if 'ROS_PARALLEL_JOBS' in os.environ:
                    ros_parallel_jobs = os.environ['ROS_PARALLEL_JOBS']
                    cmd += [arg for arg in ros_parallel_jobs.split(' ') if arg]
                else:
                    jobs = multiprocessing.cpu_count()
            if jobs:
                cmd.append('-j%d' % jobs)
                cmd.append('-l%d' % jobs)
        cmd += args.make_args
        try:
            make_path = build_path
            if args.pkg:
                make_path = os.path.join(make_path, packages_by_name[args.pkg])
            builder.print_command_banner(cmd, make_path, color=not args.no_color)
            builder.run_command(cmd, make_path, env=env)
        except subprocess.CalledProcessError:
            return fmt('@{rf}Invoking @{boldon}"make"@{boldoff} failed')

    if args.doc:
        make_doc(source_path, doc_path, packages)
Exemplo n.º 6
0
def make_isolated_main():
    args = _parse_args()

    if args.no_color:
        terminal_color.disable_ANSI_colors()

    (base_path, build_path, devel_path, source_path) = common.get_default_paths(isolated=args.suffixes)
    unused_catkin_toplevel, catkin_python_path, unused_catkin_cmake_path = common.find_catkin(base_path)
    install_path = config_cache.get_install_prefix_from_config_cmake(isolated=args.suffixes)

    sys.path.insert(0, catkin_python_path)

    from catkin.builder import build_workspace_isolated

    # Clear out previous temporaries if requested
    if args.pre_clean:
        console.pretty_print("Pre-cleaning before building.", console.cyan)
        shutil.rmtree(devel_path, ignore_errors=True)
        shutil.rmtree(build_path, ignore_errors=True)
        shutil.rmtree(install_path, ignore_errors=True)

    if not os.path.exists(build_path):
        os.mkdir(build_path)

    # Validate package argument
    packages = find_packages(source_path, exclude_subspaces=True)
    packages_by_name = {p.name: path for path, p in packages.iteritems()}
    if args.packages:
        for package in args.packages:
            if package not in packages_by_name:
                raise RuntimeError('Package %s not found in the workspace' % package)

    make.validate_build_space(base_path)  # raises a RuntimeError if there is a problem
    make.check_and_update_source_repo_paths(source_path)
    build_workspace_isolated(
        workspace=base_path,
        sourcespace=source_path,
        buildspace=build_path,
        develspace=devel_path,
        installspace=install_path,
        merge=args.merge,
        install=args.install,
        force_cmake=args.force_cmake,
        build_packages=args.packages,
        quiet=args.quiet,
        cmake_args=args.cmake_args,
        make_args=args.make_args
    )
    # this is a really fugly way of building a specific target after all else has been built
    # (and rebuilt), usually this is enough as the check of already built packages is quick
    if args.target:
        env = os.environ.copy()
        cmd = ['make', args.target]
        make_paths = []
        if args.packages:
            for package in args.packages:
                # It's an isolated build, so packages are listed under the build path as a flat list (not fully traceable dirs like in catkin_make)
                # make_path = os.path.join(make_path, packages_by_name[package])
                make_paths.append(os.path.join(build_path, package))
        else:
            for (unused_path, package) in topological_order_packages(packages):
	        # 3rd party builds put make targets under an install directory
	        # catkin package builds put make targets under the package name
	        # why? no bloody idea, but just detect what is what here
	        third_party_build_path = os.path.join(build_path, package.name, 'install')
	        catkin_build_path = os.path.join(build_path, package.name)
	        package_build_path = third_party_build_path if os.path.exists(third_party_build_path) else catkin_build_path
                make_paths.append(package_build_path)
        for make_path in make_paths:
            builder.print_command_banner(cmd, make_path, color=not args.no_color)
            if args.no_color:
                builder.run_command(cmd, make_path, env=env)
            else:
                builder.run_command_colorized(cmd, make_path, env=env)