def make_doc(source_path, doc_path, packages):

    if not common.which(DOC_PROGRAM):
        console.error('[' + DOC_PROGRAM + '] is not available.')
        console.error('Please make sure [' + DOC_PROGRAM + '] is in your python path')
        return

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

    # List up packages with its absolute path
    packages_by_name = {p.name: source_path + '/' + path for path, p in packages.iteritems()}

    doc_output = {}
    console.pretty_println('Generating documents in ' + doc_path, console.cyan)
    for name, path in packages_by_name.items():
        console.pretty_println('  ' + name)
        output = generate_doc(name, path, doc_path)
        doc_output[name] = output

    generates_index_page(doc_path, packages_by_name.keys())

    console.pretty_println('')
    console.pretty_println('Document generation result. 0 may mean error. But it is fine most of time', console.bold_white)
    for name, err in doc_output.items():
        console.pretty_print(name, console.cyan)
        console.pretty_print(' : ')
        console.pretty_println(str(err))
Exemple #2
0
def create_gradle_package_files(args, author, is_library, sdk_version):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    plugin_name = "com.android.library" if is_library else "com.android.application"
    try:
        package_name = args.name[0].lower()
        package_path = os.path.abspath(os.path.join(os.getcwd(), package_name))
        console.pretty_println("\nCreating gradle files", console.bold)
        for template_name in ['build.gradle']:  # 'CMakeLists.txt']:
            filename = os.path.join(package_path, template_name)
            template = read_template_file(template_name)
            contents = instantiate_template(template, package_name, author,
                                            plugin_name, sdk_version)
            #if is_library:
            #    contents += extra_gradle_library_text()
            try:
                f = open(filename, 'w')
                f.write(contents)
                console.pretty_print('  File: ', console.cyan)
                console.pretty_println(template_name, console.yellow)
            finally:
                f.close()
    except Exception:
        raise
def actually_create_android_project(package_name, sdk_version, java_package_name, is_library):
    path = os.path.join(os.getcwd(), package_name.lower())
    console.pretty_println("\nCreating android project ", console.bold)
    console.pretty_print("  Name      : ", console.cyan)
    console.pretty_println("%s" % package_name, console.yellow)
    console.pretty_print("  Sdk Ver   : ", console.cyan)
    console.pretty_println("%s" % sdk_version, console.yellow)
    console.pretty_print("  Java Name : ", console.cyan)
    console.pretty_println("%s" % java_package_name, console.yellow)
    if is_library:
        console.pretty_print("  Library   : ", console.cyan)
        console.pretty_println("yes\n", console.yellow)
        cmd = ['android', 'create', 'lib-project', '-n', package_name, '-p', path, '-k', java_package_name, '-t', 'android-' + sdk_version, ]
    else:
        activity_name = utils.camel_case(package_name)
        console.pretty_print("  Activity  : ", console.cyan)
        console.pretty_println("%s\n" % activity_name, console.yellow)
        cmd = ['android', 'create', 'project', '-n', package_name, '-p', path, '-k', java_package_name, '-t', 'android-' + sdk_version, '-a', activity_name]
    try:
        subprocess.check_call(cmd)
    except subprocess.CalledProcessError:
        raise subprocess.CalledProcessError("failed to create android project.")
    # This is in the old form, let's shovel the shit around to the new form
    utils.mkdir_p(os.path.join(path, 'src', 'main', 'java'))
    os.remove(os.path.join(path, 'local.properties'))
    os.remove(os.path.join(path, 'project.properties'))
    os.remove(os.path.join(path, 'ant.properties'))
    os.remove(os.path.join(path, 'proguard-project.txt'))
    os.remove(os.path.join(path, 'build.xml'))
    os.rmdir(os.path.join(path, 'bin'))
    os.rmdir(os.path.join(path, 'libs'))
    shutil.move(os.path.join(path, 'AndroidManifest.xml'), os.path.join(path, 'src', 'main'))
    shutil.move(os.path.join(path, 'res'), os.path.join(path, 'src', 'main'))
    if not is_library:
        shutil.move(os.path.join(path, 'src', java_package_name.split('.')[0]), os.path.join(path, 'src', 'main', 'java'))
def add_install_app_to_cmake_targets():
    '''
      Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
    '''
    for rel_path in ['.', '..']:
        cmakelists_txt_path = os.path.join(os.getcwd(), rel_path,
                                           'CMakeLists.txt')
        if os.path.isfile(cmakelists_txt_path):
            break
        else:
            cmakelists_txt_path = None
    if cmakelists_txt_path is None:
        console.pretty_println(
            "\nCouldn't find the root level CMakeLists.txt - not adding to the superproject."
        )
        return
    with open(cmakelists_txt_path, 'r') as cmakelists_txt:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('CMakeLists.txt (gradle task update)',
                               console.yellow)
        old_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository)'
        new_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository installApp)'
        new_contents = cmakelists_txt.read().replace(old_text, new_text)
    with open(cmakelists_txt_path, 'w') as cmakelists_txt:
        cmakelists_txt.write(new_contents)
Exemple #5
0
def make_doc(source_path, doc_path, packages):

    if not common.which(DOC_PROGRAM):
        console.error('[' + DOC_PROGRAM + '] is not available.')
        console.error('Please make sure [' + DOC_PROGRAM +
                      '] is in your python path')
        return

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

    # List up packages with its absolute path
    packages_by_name = {
        p.name: source_path + '/' + path
        for path, p in packages.iteritems()
    }

    doc_output = {}
    console.pretty_println('Generating documents in ' + doc_path, console.cyan)
    for name, path in packages_by_name.items():
        console.pretty_println('  ' + name)
        output = generate_doc(name, path, doc_path)
        doc_output[name] = output

    generates_index_page(doc_path, packages_by_name.keys())

    console.pretty_println('')
    console.pretty_println(
        'Document generation result. 0 may mean error. But it is fine most of time',
        console.bold_white)
    for name, err in doc_output.items():
        console.pretty_print(name, console.cyan)
        console.pretty_print(' : ')
        console.pretty_println(str(err))
def create_catkin_package_files(package_name, package_path, args):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    try:
        build_depends = []
        if 'rosjava_build_tools' not in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency('rosjava_build_tools'))
        for depend_name in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency(depend_name))
        package_template = PackageTemplate._create_package_template(
            package_name=package_name,
            description=args.description,
            licenses=args.license or [],
            maintainer_names=args.maintainer,
            author_names=args.author,
            version=args.pkg_version,
            catkin_deps=[],
            system_deps=[],
            boost_comps=None)
        package_template.exports = []
        package_template.build_depends = build_depends
        distro_version = utils.distro_version()
        package_xml = create_package_xml(package_template=package_template, rosdistro=distro_version)
        try:
            filename = os.path.join(package_path, 'package.xml')
            f = open(filename, 'w')
            f.write(package_xml)
            console.pretty_print('Created repo file: ', console.cyan)
            console.pretty_println('%s' % filename, console.yellow)
        finally:
            f.close()
    except Exception:
        raise
Exemple #7
0
def add_tasks_to_cmake_setup(tasks):
    '''
      Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
    '''
    for rel_path in ['.', '..']:
        cmakelists_txt_path = os.path.join(os.getcwd(), rel_path, 'CMakeLists.txt')
        if os.path.isfile(cmakelists_txt_path):
            break
        else:
            cmakelists_txt_path = None
    if cmakelists_txt_path is None:
        console.pretty_println("\nCouldn't find the root level CMakeLists.txt - not adding to the superproject.")
        return
    with open(cmakelists_txt_path, 'r') as cmakelists_txt:
        old_contents = cmakelists_txt.read()
        result = re.search('^catkin_rosjava_setup\(.*\)', old_contents, re.MULTILINE)
        if result is None:
            console.pretty_println("\nCouldn't find a catkin_rosjava_setup entry in the CMakeLists.txt - not adding tasks.")
            return
        rosjava_setup_string = result.group(0)
        gradle_tasks = set([])
        if rosjava_setup_string.find("publish") == -1:
            gradle_tasks.add("publish")
        if rosjava_setup_string.find("installDist") == -1:
            gradle_tasks.add("installDist")
        gradle_tasks |= set(tasks)
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('CMakeLists.txt (gradle task update)', console.yellow)
        old_text = rosjava_setup_string
        new_text = 'catkin_rosjava_setup(' + ' '.join(gradle_tasks) + ')'
        new_contents = old_contents.replace(old_text, new_text)
    with open(cmakelists_txt_path, 'w') as cmakelists_txt:
        cmakelists_txt.write(new_contents)
def list_rosinstalls(track):
    response = urllib2.urlopen('%s/%s.yaml' % (settings.get_rosinstall_database_uri(), track))
    rosinstalls = yaml.load(response.read())
    sorted_rosinstalls = rosinstalls.keys()
    sorted_rosinstalls.sort()
    for r in sorted_rosinstalls:
        console.pretty_print(" " + r + ": ", console.cyan)
        console.pretty_println("%s" % rosinstalls[r], console.yellow)
def print_details(workspace_dir, uri):
    console.pretty_println("\n***************************** Development Workspace ******************************", console.bold)
    console.pretty_print("Workspace : ", console.cyan)
    console.pretty_println(workspace_dir, console.yellow)
    console.pretty_print("Rosinstall: ", console.cyan)
    console.pretty_println(uri, console.yellow)
    console.pretty_println("**********************************************************************************", console.bold)
    console.pretty_println("\nMerge additional source directories with `wstool` and configure parallel builds with 'yujin_init_build'.\n", console.cyan)
Exemple #10
0
def list_rosinstalls(track):
    response = urllib2.urlopen('%s/%s.yaml' %
                               (settings.get_rosinstall_database_uri(), track))
    rosinstalls = yaml.load(response.read())
    sorted_rosinstalls = rosinstalls.keys()
    sorted_rosinstalls.sort()
    for r in sorted_rosinstalls:
        console.pretty_print(" " + r + ": ", console.cyan)
        console.pretty_println("%s" % rosinstalls[r], console.yellow)
def create_rosjava_project_common(args, template_directory):
    project_name = args.name[0]
    console.pretty_println("\nCreating rosjava project ", console.bold)
    console.pretty_print("  Name      : ", console.cyan)
    console.pretty_println("%s" % project_name, console.yellow)
    utils.mkdir_p(os.path.join(os.getcwd(), project_name.lower()))
    # This is in the old form, let's shovel the shit around to the new form
    create_gradle_package_files(args, template_directory)
    add_to_root_gradle_settings(args.name[0])
def create_rosjava_project_common(args, template_directory):
    project_name = args.name[0]
    console.pretty_println("\nCreating rosjava project ", console.bold)
    console.pretty_print("  Name      : ", console.cyan)
    console.pretty_println("%s" % project_name, console.yellow)
    utils.mkdir_p(os.path.join(os.getcwd(), project_name.lower()))
    # This is in the old form, let's shovel the shit around to the new form
    create_gradle_package_files(args, template_directory)
    add_to_root_gradle_settings(args.name[0])
def create_gradle_wrapper(repo_path):
    gradle_binary = os.path.join(os.path.dirname(__file__), 'gradle', 'gradlew')
    cmd = [gradle_binary, '-p', repo_path, 'wrapper']
    console.pretty_print("Creating gradle wrapper: ", console.cyan)
    console.pretty_println("%s" % ' '.join(cmd), console.yellow)
    try:
        subprocess.check_call(cmd)
    except subprocess.CalledProcessError:
        raise subprocess.CalledProcessError("failed to create the gradle wrapper.")
Exemple #14
0
def actually_create_android_project(package_name, sdk_version,
                                    java_package_name, is_library):
    path = os.path.join(os.getcwd(), package_name.lower())
    console.pretty_println("\nCreating android project ", console.bold)
    console.pretty_print("  Name      : ", console.cyan)
    console.pretty_println("%s" % package_name, console.yellow)
    console.pretty_print("  Sdk Ver   : ", console.cyan)
    console.pretty_println("%s" % sdk_version, console.yellow)
    console.pretty_print("  Java Name : ", console.cyan)
    console.pretty_println("%s" % java_package_name, console.yellow)
    if is_library:
        console.pretty_print("  Library   : ", console.cyan)
        console.pretty_println("yes\n", console.yellow)
        cmd = [
            'android',
            'create',
            'lib-project',
            '-n',
            package_name,
            '-p',
            path,
            '-k',
            java_package_name,
            '-t',
            'android-' + sdk_version,
        ]
    else:
        activity_name = utils.camel_case(package_name)
        console.pretty_print("  Activity  : ", console.cyan)
        console.pretty_println("%s\n" % activity_name, console.yellow)
        cmd = [
            'android', 'create', 'project', '-n', package_name, '-p', path,
            '-k', java_package_name, '-t', 'android-' + sdk_version, '-a',
            activity_name
        ]
    try:
        subprocess.check_call(cmd)
    except subprocess.CalledProcessError:
        raise subprocess.CalledProcessError(
            "failed to create android project.")
    # This is in the old form, let's shovel the shit around to the new form
    utils.mkdir_p(os.path.join(path, 'src', 'main', 'java'))
    os.remove(os.path.join(path, 'local.properties'))
    os.remove(os.path.join(path, 'project.properties'))
    os.remove(os.path.join(path, 'ant.properties'))
    os.remove(os.path.join(path, 'proguard-project.txt'))
    os.remove(os.path.join(path, 'build.xml'))
    os.rmdir(os.path.join(path, 'bin'))
    os.rmdir(os.path.join(path, 'libs'))
    shutil.move(os.path.join(path, 'AndroidManifest.xml'),
                os.path.join(path, 'src', 'main'))
    shutil.move(os.path.join(path, 'res'), os.path.join(path, 'src', 'main'))
    if not is_library:
        shutil.move(os.path.join(path, 'src',
                                 java_package_name.split('.')[0]),
                    os.path.join(path, 'src', 'main', 'java'))
Exemple #15
0
def create_gradle_wrapper(repo_path):
    gradle_binary = os.path.join(os.path.dirname(__file__), 'gradle',
                                 'gradlew')
    cmd = [gradle_binary, '-p', repo_path, 'wrapper']
    console.pretty_print("Creating gradle wrapper: ", console.cyan)
    console.pretty_println("%s" % ' '.join(cmd), console.yellow)
    try:
        subprocess.check_call(cmd)
    except subprocess.CalledProcessError:
        raise subprocess.CalledProcessError(
            "failed to create the gradle wrapper.")
def create_dummy_java_class(project_name):
    path = os.path.join(os.getcwd(), project_name.lower())
    java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', 'rosjava', project_name)
    utils.mkdir_p(java_package_path)
    filename = os.path.join(java_package_path, 'Dude.java')
    java_class = "package com.github.rosjava.%s.Dude;\n" % project_name
    java_class += "\n"
    java_class += "public class Dude {\n"
    java_class += "}\n"
    console.pretty_print('  File      : ', console.cyan)
    console.pretty_println('Dude.class', console.yellow)
    with open(filename, 'w') as dude_class:
        dude_class.write(java_class)
def populate_repo(repo_path, package_type):
    author = utils.author_name()
    repo_name = os.path.basename(repo_path)
    templates = get_templates(package_type)
    for filename, template in templates.iteritems():
        contents = instantiate_template(template, repo_name, author)
        try:
            p = os.path.abspath(os.path.join(repo_path, filename))
            f = open(p, 'w')
            f.write(contents)
            console.pretty_print("Created repo file: ", console.cyan)
            console.pretty_println("%s" % p, console.yellow)
        finally:
            f.close()
Exemple #18
0
def create_dummy_java_class(project_name):
    path = os.path.join(os.getcwd(), project_name.lower())
    package_name = os.path.basename(os.getcwd())
    java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
    utils.mkdir_p(java_package_path)
    filename = os.path.join(java_package_path, 'Dude.java')
    java_class = "package com.github.%s.%s;\n" % (package_name, project_name)
    java_class += "\n"
    java_class += "public class Dude {\n"
    java_class += "}\n"
    console.pretty_print('  File      : ', console.cyan)
    console.pretty_println('Dude.class', console.yellow)
    with open(filename, 'w') as dude_class:
        dude_class.write(java_class)
Exemple #19
0
def populate_repo(repo_path):
    author = utils.author_name()
    repo_name = os.path.basename(repo_path)
    templates = get_templates()
    for filename, template in templates.iteritems():
        contents = instantiate_template(template, repo_name, author)
        try:
            p = os.path.abspath(os.path.join(repo_path, filename))
            f = open(p, 'w')
            f.write(contents)
            console.pretty_print("Created repo file: ", console.cyan)
            console.pretty_println("%s" % p, console.yellow)
        finally:
            f.close()
Exemple #20
0
def add_catkin_generate_tree_command():
    for rel_path in ['.', '..']:
        build_gradle_path = os.path.join(os.getcwd(), rel_path, 'build.gradle')
        if os.path.isfile(build_gradle_path):
            break
        else:
            build_gradle_path = None
    if build_gradle_path is None:
        console.pretty_println("\nCouldn't find the root level build.gradle file - not adding to the superproject.")
        return
    with open(build_gradle_path, 'r') as build_gradle:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('build.gradle (catkin_generate_tree update)', console.yellow)
        new_contents = build_gradle.read().replace("apply plugin: 'catkin'", "apply plugin: 'catkin'\nproject.catkin.tree.generate()\n")
    with open(build_gradle_path, 'w') as build_gradle:
        build_gradle.write(new_contents)
def add_catkin_generate_tree_command():
    for rel_path in ['.', '..']:
        build_gradle_path = os.path.join(os.getcwd(), rel_path, 'build.gradle')
        if os.path.isfile(build_gradle_path):
            break
        else:
            build_gradle_path = None
    if build_gradle_path is None:
        console.pretty_println("\nCouldn't find the root level build.gradle file - not adding to the superproject.")
        return
    with open(build_gradle_path, 'r') as build_gradle:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('build.gradle (catkin_generate_tree update)', console.yellow)
        new_contents = build_gradle.read().replace("apply plugin: 'catkin'", "apply plugin: 'catkin'\nproject.catkin.tree.generate()\n")
    with open(build_gradle_path, 'w') as build_gradle:
        build_gradle.write(new_contents)
Exemple #22
0
def add_to_root_gradle_settings(name):
    '''
      Adds project name to the root level settings.gradle file.
    '''
    for rel_path in ['.', '..']:
        settings_gradle_path = os.path.join(os.getcwd(), rel_path, 'settings.gradle')
        if os.path.isfile(settings_gradle_path):
            break
        else:
            settings_gradle_path = None
    if settings_gradle_path is None:
        console.pretty_println("\nCouldn't find the root level settings.gradle file - not adding to the superproject.")
        return
    with open(settings_gradle_path, 'a') as settings_gradle:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('settings.gradle', console.yellow)
        settings_gradle.write("include '%s'\n" % name)
def add_to_root_gradle_settings(name):
    '''
      Adds project name to the root level settings.gradle file.
    '''
    for rel_path in ['.', '..']:
        settings_gradle_path = os.path.join(os.getcwd(), rel_path, 'settings.gradle')
        if os.path.isfile(settings_gradle_path):
            break
        else:
            settings_gradle_path = None
    if settings_gradle_path is None:
        console.pretty_println("\nCouldn't find the root level settings.gradle file - not adding to the superproject.")
        return
    with open(settings_gradle_path, 'a') as settings_gradle:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('settings.gradle', console.yellow)
        settings_gradle.write("include '%s'\n" % name)
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
    )
Exemple #25
0
def list_platforms():
    console.pretty_println("\n********************************* Platform List **********************************", console.bold)
    platforms = get_toolchains_or_platforms(os.path.join(os.path.dirname(__file__), 'platforms'))
    console.pretty_println("Official:", console.bold)
    for family in platforms:
        for platform in platforms[family]:
            console.pretty_print(" -- %s/" % family, console.cyan)
            console.pretty_println("%s" % platform, console.yellow)
    console.pretty_println("Custom:", console.bold)
    platforms = get_toolchains_or_platforms(os.path.join(settings.yujin_tools_home(), 'platforms'))
    if platforms:
        for family in platforms:
            for platform in platforms[family]:
                console.pretty_print(" -- %s/" % family, console.cyan)
                console.pretty_println("%s" % platform, console.yellow)
    else:
        console.pretty_println(" -- ", console.cyan)
    console.pretty_println("**********************************************************************************\n", console.bold)
Exemple #26
0
def add_to_package_xml(name):
    '''
      Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
    '''
    for rel_path in ['.', '..']:
        package_xml_path = os.path.join(os.getcwd(), rel_path, 'package.xml')
        if os.path.isfile(package_xml_path):
            break
        else:
            package_xml_path = None
    if package_xml_path is None:
        console.pretty_println("\nCouldn't find the root level package.xml file - not adding to the superproject.")
        return
    with open(package_xml_path, 'r') as package_xml:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('package.xml (dependency update)', console.yellow)
        new_contents = package_xml.read().replace("</package>", "<build_depend>%s</build_depend>\n</package>" % name)
    with open(package_xml_path, 'w') as package_xml:
        package_xml.write(new_contents)
def create_talker_listener_classes(project_name, template_directory, author):
    path = os.path.join(os.getcwd(), project_name.lower())
    package_name = os.path.basename(os.getcwd())
    java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
    utils.mkdir_p(java_package_path)
    try:
        for template_name in ['Talker.java', 'Listener.java']:
            filename = os.path.join(java_package_path, template_name)
            template = utils.read_template_file(template_directory, template_name)
            contents = instantiate_code_template(template, package_name, project_name, author)
            try:
                f = open(filename, 'w')
                f.write(contents)
                console.pretty_print('  File      : ', console.cyan)
                console.pretty_println(template_name, console.yellow)
            finally:
                f.close()
    except Exception:
        raise
def add_to_package_xml(name):
    '''
      Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
    '''
    for rel_path in ['.', '..']:
        package_xml_path = os.path.join(os.getcwd(), rel_path, 'package.xml')
        if os.path.isfile(package_xml_path):
            break
        else:
            package_xml_path = None
    if package_xml_path is None:
        console.pretty_println("\nCouldn't find the root level package.xml file - not adding to the superproject.")
        return
    with open(package_xml_path, 'r') as package_xml:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('package.xml (dependency update)', console.yellow)
        new_contents = package_xml.read().replace("</package>", "<build_depend>%s</build_depend>\n</package>" % name)
    with open(package_xml_path, 'w') as package_xml:
        package_xml.write(new_contents)
def main():
    args = parse_arguments()
    if args.get_default_track:
        # console.pretty_print("\nDefault Track: ", console.cyan)
        # console.pretty_println("%s\n" % get_default_track(), console.yellow)
        print get_default_track()
        sys.exit(0)
    if args.set_default_track:
        console.pretty_print("\nNew Default Track: ", console.cyan)
        console.pretty_println("%s\n" % set_default_track(args.set_default_track), console.yellow)
        sys.exit(0)
    if args.get_rosinstall_database_uri:
        print get_rosinstall_database_uri()
        sys.exit(0)
    if args.set_rosinstall_database_uri:
        console.pretty_print("\nNew Rosisntall Database Uri: ", console.cyan)
        console.pretty_println("%s\n" % set_rosinstall_database_uri(args.set_rosinstall_database_uri), console.yellow)
        sys.exit(0)
    print ("%s" % help_string())
Exemple #30
0
def create_talker_listener_classes(project_name, template_directory, author):
    path = os.path.join(os.getcwd(), project_name.lower())
    package_name = os.path.basename(os.getcwd())
    java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name)
    utils.mkdir_p(java_package_path)
    try:
        for template_name in ['Talker.java', 'Listener.java']:
            filename = os.path.join(java_package_path, template_name)
            template = utils.read_template_file(template_directory, template_name)
            contents = instantiate_code_template(template, package_name, project_name, author)
            try:
                f = open(filename, 'w')
                f.write(contents)
                console.pretty_print('  File      : ', console.cyan)
                console.pretty_println(template_name, console.yellow)
            finally:
                f.close()
    except Exception:
        raise
def create_gradle_package_files(args, template_directory):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    try:
        project_name = args.name[0].lower()
        package_path = os.path.abspath(os.path.join(os.getcwd(), project_name))
        for template_name in ['build.gradle']:  # 'CMakeLists.txt']:
            filename = os.path.join(package_path, template_name)
            template = utils.read_template_file(template_directory, template_name)
            contents = instantiate_template(template, project_name, args.author)
            try:
                f = open(filename, 'w')
                f.write(contents)
                console.pretty_print('  File      : ', console.cyan)
                console.pretty_println(template_name, console.yellow)
            finally:
                f.close()
    except Exception:
        raise
Exemple #32
0
def create_gradle_package_files(args, template_directory):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    try:
        project_name = args.name[0].lower()
        package_path = os.path.abspath(os.path.join(os.getcwd(), project_name))
        for template_name in ['build.gradle']:  # 'CMakeLists.txt']:
            filename = os.path.join(package_path, template_name)
            template = utils.read_template_file(template_directory, template_name)
            contents = instantiate_template(template, project_name, args.author)
            try:
                f = open(filename, 'w')
                f.write(contents)
                console.pretty_print('  File      : ', console.cyan)
                console.pretty_println(template_name, console.yellow)
            finally:
                f.close()
    except Exception:
        raise
def init_workspace():
    args = parse_arguments()
    if not args.track:
        args.track = settings.get_default_track()
    if args.list_rosinstalls:
        list_rosinstalls(args.track)
        sys.exit(0)
#    if not which("/opt/ros/" + args.track + "/bin/catkin_init_workspace"):
#        sys.exit("\nCatkin is not installed: 'sudo apt-get install ros-%s-catkin'\n" % args.track)
    if os.path.isabs(args.dir):
        workspace_dir = args.dir
    else:
        workspace_dir = os.path.join(os.getcwd(), args.dir)
    if not os.path.isdir(workspace_dir):
        os.mkdir(workspace_dir)
    if os.path.isdir(os.path.join(workspace_dir, 'src')):
        sys.exit("This workspace is already initialised")
    if args.uri:
        uri = args.uri  # assume its an absolute path or http uri
        if not os.path.isabs(args.uri):
            if os.path.isfile(os.path.join(os.getcwd(), args.uri)):
                uri = os.path.join(os.getcwd(), args.uri)
            else:
                if urlparse.urlparse(args.uri).scheme == "":  # not a http element, let's look up our databas
                    console.pretty_print("Retrieving", console.cyan)
                    console.pretty_print(" %s " % args.uri, console.yellow)
                    console.pretty_print("on track", console.cyan)
                    console.pretty_print(" %s " % args.track, console.yellow)
                    console.pretty_print("from", console.cyan)
                    console.pretty_println(" %s " % settings.get_rosinstall_database_uri(), console.yellow)
                    response = urllib2.urlopen('%s/%s.yaml' % (settings.get_rosinstall_database_uri(), args.track))
                    rosinstalls = yaml.load(response.read())
                    if args.uri in rosinstalls:
                        uri = rosinstalls[args.uri]
                    else:
                        console.logerror("Uri not an absolute path, local file, http or in our rosinstall database.")
                        sys.exit(1)
    else:
        uri = ""
    populate_worskpace(os.path.join(workspace_dir, 'src'), uri)
    print_details(workspace_dir, uri)
def add_install_app_to_cmake_targets():
    '''
      Adds project name to build_depends in package.xml (should be same name as the ros msg package name).
    '''
    for rel_path in ['.', '..']:
        cmakelists_txt_path = os.path.join(os.getcwd(), rel_path, 'CMakeLists.txt')
        if os.path.isfile(cmakelists_txt_path):
            break
        else:
            cmakelists_txt_path = None
    if cmakelists_txt_path is None:
        console.pretty_println("\nCouldn't find the root level CMakeLists.txt - not adding to the superproject.")
        return
    with open(cmakelists_txt_path, 'r') as cmakelists_txt:
        console.pretty_print('  File      : ', console.cyan)
        console.pretty_println('CMakeLists.txt (gradle task update)', console.yellow)
        old_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository)'
        new_text = 'catkin_rosjava_setup(publishMavenJavaPublicationToMavenRepository installApp)'
        new_contents = cmakelists_txt.read().replace(old_text, new_text)
    with open(cmakelists_txt_path, 'w') as cmakelists_txt:
        cmakelists_txt.write(new_contents)
Exemple #35
0
def clean(dir_to_be_cleaned, dir_sources):
    if common.is_same_dir(dir_to_be_cleaned, os.getcwd()):
        if not os.path.isfile(os.path.join(dir_to_be_cleaned, 'config.cmake')):
            console.logerror(
                "Could not clean the current directory [build artifacts do not exist]"
            )
            return
        console.pretty_print(
            "\nCleaning current directory of yujin_init_build artifacts : ",
            console.cyan)
        for f in [
                os.path.join(dir_to_be_cleaned, x) for x in [
                    'config.cmake', 'eclipse', 'gnome-terminal', 'konsole',
                    'toolchain.cmake', '.bashrc', 'android-studio'
                ]
        ]:
            if os.path.isfile(f):
                os.remove(f)
        for f in [
                os.path.join(dir_to_be_cleaned, dir_sources, x)
                for x in ['CMakeLists.txt', '.yujin_init_build']
        ]:
            if os.path.isfile(f):
                os.remove(f)
        for d in [
                os.path.join(dir_to_be_cleaned, x) for x in ['build', 'devel']
        ]:
            if os.path.isdir(d):
                shutil.rmtree(d)
        console.pretty_println('done.\n', console.yellow)
    else:
        if os.path.isdir(os.path.abspath(dir_to_be_cleaned)):
            console.pretty_print("Cleaning build directory : ", console.cyan)
            console.pretty_println(dir_to_be_cleaned, console.yellow)
            shutil.rmtree(os.path.abspath(dir_to_be_cleaned))
        else:
            console.logerror("Could not clean %s [does not exist]" %
                             dir_to_be_cleaned)
Exemple #36
0
def main():
    args = parse_arguments()
    if args.get_default_track:
        #console.pretty_print("\nDefault Track: ", console.cyan)
        #console.pretty_println("%s\n" % get_default_track(), console.yellow)
        print get_default_track()
        sys.exit(0)
    if args.set_default_track:
        console.pretty_print("\nNew Default Track: ", console.cyan)
        console.pretty_println(
            "%s\n" % set_default_track(args.set_default_track), console.yellow)
        sys.exit(0)
    if args.get_rosinstall_database_uri:
        print get_rosinstall_database_uri()
        sys.exit(0)
    if args.set_rosinstall_database_uri:
        console.pretty_print("\nNew Rosisntall Database Uri: ", console.cyan)
        console.pretty_println(
            "%s\n" %
            set_rosinstall_database_uri(args.set_rosinstall_database_uri),
            console.yellow)
        sys.exit(0)
    print("%s" % help_string())
Exemple #37
0
def clean(dir_to_be_cleaned, dir_sources):
    if common.is_same_dir(dir_to_be_cleaned, os.getcwd()):
        if not os.path.isfile(os.path.join(dir_to_be_cleaned, 'config.cmake')):
            console.logerror("Could not clean the current directory [build artifacts do not exist]")
            return
        console.pretty_print("\nCleaning current directory of yujin_init_build artifacts : ", console.cyan)
        for f in [os.path.join(dir_to_be_cleaned, x) for x in ['config.cmake', 'eclipse', 'gnome-terminal', 'konsole', 'toolchain.cmake', '.bashrc', 'android-studio']]:
            if os.path.isfile(f):
                os.remove(f)
        for f in [os.path.join(dir_to_be_cleaned, dir_sources, x) for x in ['CMakeLists.txt', '.yujin_init_build']]:
            if os.path.isfile(f):
                os.remove(f)
        for d in [os.path.join(dir_to_be_cleaned, x) for x in ['build', 'devel']]:
            if os.path.isdir(d):
                shutil.rmtree(d)
        console.pretty_println('done.\n', console.yellow)
    else:
        if os.path.isdir(os.path.abspath(dir_to_be_cleaned)):
            console.pretty_print("Cleaning build directory : ", console.cyan)
            console.pretty_println(dir_to_be_cleaned, console.yellow)
            shutil.rmtree(os.path.abspath(dir_to_be_cleaned))
        else:
            console.logerror("Could not clean %s [does not exist]" % dir_to_be_cleaned)
def create_gradle_package_files(args, author, is_library, sdk_version):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    plugin_name = "android-library" if is_library else "android"
    try:
        package_name = args.name[0].lower()
        package_path = os.path.abspath(os.path.join(os.getcwd(), package_name))
        console.pretty_println("\nCreating gradle files", console.bold)
        for template_name in ['build.gradle']:  # 'CMakeLists.txt']:
            filename = os.path.join(package_path, template_name)
            template = read_template_file(template_name)
            contents = instantiate_template(template, package_name, author, plugin_name, sdk_version)
            #if is_library:
            #    contents += extra_gradle_library_text()
            try:
                f = open(filename, 'w')
                f.write(contents)
                console.pretty_print('  File: ', console.cyan)
                console.pretty_println(template_name, console.yellow)
            finally:
                f.close()
    except Exception:
        raise
Exemple #39
0
def create_catkin_package_files(package_name, package_path, args):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    try:
        build_depends = []
        if 'rosjava_tools' not in args.dependencies:
            build_depends.append(
                catkin_pkg.package.Dependency('rosjava_tools'))
        for depend_name in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency(depend_name))
        package_template = PackageTemplate._create_package_template(
            package_name=package_name,
            description=args.description,
            licenses=args.license or [],
            maintainer_names=args.maintainer,
            author_names=args.author,
            version=args.pkg_version,
            catkin_deps=[],
            system_deps=[],
            boost_comps=None)
        package_template.exports = []
        package_template.build_depends = build_depends
        distro_version = utils.distro_version()
        package_xml = create_package_xml(package_template=package_template,
                                         rosdistro=distro_version)
        try:
            filename = os.path.join(package_path, 'package.xml')
            f = open(filename, 'w')
            f.write(package_xml)
            console.pretty_print('Created repo file: ', console.cyan)
            console.pretty_println('%s' % filename, console.yellow)
        finally:
            f.close()
    except Exception:
        raise
Exemple #40
0
def list_platforms():
    console.pretty_println(
        "\n********************************* Platform List **********************************",
        console.bold)
    platforms = get_toolchains_or_platforms(
        os.path.join(os.path.dirname(__file__), 'platforms'))
    console.pretty_println("Official:", console.bold)
    for family in platforms:
        for platform in platforms[family]:
            console.pretty_print(" -- %s/" % family, console.cyan)
            console.pretty_println("%s" % platform, console.yellow)
    console.pretty_println("Custom:", console.bold)
    platforms = get_toolchains_or_platforms(
        os.path.join(settings.yujin_tools_home(), 'platforms'))
    if platforms:
        for family in platforms:
            for platform in platforms[family]:
                console.pretty_print(" -- %s/" % family, console.cyan)
                console.pretty_println("%s" % platform, console.yellow)
    else:
        console.pretty_println(" -- ", console.cyan)
    console.pretty_println(
        "**********************************************************************************\n",
        console.bold)
def create_symlink(src, dst, quiet=False):
    """
    Creates a symlink at dst to src.
    """
    if not os.path.exists(src):
        raise RuntimeError("'%s' is not a valid path" % src)
    try:
        os.symlink(src, dst)
        if not quiet:
            console.pretty_print('Creating symlink', console.white)
            console.pretty_print(' "%s" ' % dst, console.bold)
            console.pretty_print("->", console.white)
            console.pretty_println(' "%s." ' % src, console.bold)
    except Exception as ex_symlink:
        raise RuntimeError("Could not symlink '%s' to %s [%s]." % (src, dst, str(ex_symlink)))
Exemple #42
0
def create_symlink(src, dst, quiet=False):
    """
    Creates a symlink at dst to src.
    """
    if not os.path.exists(src):
        raise RuntimeError("'%s' is not a valid path" % src)
    try:
        os.symlink(src, dst)
        if not quiet:
            console.pretty_print('Creating symlink', console.white)
            console.pretty_print(' "%s" ' % dst, console.bold)
            console.pretty_print("->", console.white)
            console.pretty_println(' "%s." ' % src, console.bold)
    except Exception as ex_symlink:
        raise RuntimeError("Could not symlink '%s' to %s [%s]." %
                           (src, dst, str(ex_symlink)))
def build_workspace_isolated(
    workspace='.',
    sourcespace=None,
    buildspace=None,
    develspace=None,
    installspace=None,
    merge=False,
    install=False,
    jobs=None,
    force_cmake=False,
    build_packages=None,
    quiet=False,
    cmake_args=[],
    make_args=[],
    catkin_cmake_path=None,
    catkin_python_path=None
):
    '''
    Runs ``cmake``, ``make`` and optionally ``make install`` for all
    catkin packages in sourcespace_dir.  It creates several folders
    in the current working directory. For non-catkin packages it runs
    ``cmake``, ``make`` and ``make install`` for each, installing it to
    the devel space or install space if the ``install`` option is specified.

    :param workspace: path to the current workspace, ``str``
    :param sourcespace: workspace folder containing catkin packages, ``str``
    :param buildspace: path to build space location, ``str``
    :param develspace: path to devel space location, ``str``
    :param installspace: path to install space (CMAKE_INSTALL_PREFIX), ``str``
    :param merge: if True, build each catkin package into the same
        devel space. does not work with non-catkin packages, ``bool``
    :param install: if True, install all packages to the install space,
        ``bool``
    :param jobs: number of parallel build jobs to run (make -jN -lN), ``int``
    :param force_cmake: (optional), if True calls cmake explicitly for each
        package, ``bool``
    :param colorize: if True, colorize cmake output and other messages,
        ``bool``
    :param build_packages: specific packages to build (all parent packages
        in the topological order must have been built before), ``str``
    :param quiet: if True, hides some build output, ``bool``
    :param cmake_args: additional arguments for cmake, ``[str]``
    :param make_args: additional arguments for make, ``[str]``
    '''
    # Should actually have alot of argument checks here, rather than
    # before feeding the function (makes for safe functions)

    console.pretty_print("Base Path: ", console.cyan)
    console.pretty_println("%s" % workspace, console.yellow)
    console.pretty_print("Build Path: ", console.cyan)
    console.pretty_println("%s" % buildspace, console.yellow)
    console.pretty_print("Source Path: ", console.cyan)
    console.pretty_println("%s" % sourcespace, console.yellow)
    console.pretty_print("Devel Path: ", console.cyan)
    console.pretty_println("%s" % develspace, console.yellow)
    console.pretty_print("Install Path: ", console.cyan)
    console.pretty_println("%s" % installspace, console.yellow)
    console.pretty_print("Catkin CMake Path: ", console.cyan)
    console.pretty_println("%s" % catkin_cmake_path, console.yellow)
    console.pretty_print("Catkin Python Path: ", console.cyan)
    console.pretty_println("%s" % catkin_python_path, console.yellow)
    # Find packages
    packages = find_packages(sourcespace, exclude_subspaces=True)
    if not packages:
        raise RuntimeError("No packages found in source space: %s" % sourcespace)

    # verify that specified package exists in workspace
    if build_packages:
        packages_by_name = {p.name: path for path, p in packages.iteritems()}
        unknown_packages = [p for p in build_packages if p not in packages_by_name]
        if unknown_packages:
            raise RuntimeError('Packages not found in the workspace: %s' % ', '.join(unknown_packages))

    # Report topological ordering
    ordered_packages = topological_order_packages(packages)
    unknown_build_types = []
    msg = []
    msg.append('@{pf}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' + ('~' * len(str(len(ordered_packages)))))
    msg.append('@{pf}~~@|  traversing %d packages in topological order:' % len(ordered_packages))
    for path, package in ordered_packages:
        export_tags = [e.tagname for e in package.exports]
        if 'build_type' in export_tags:
            build_type_tag = [e.content for e in package.exports if e.tagname == 'build_type'][0]
        else:
            build_type_tag = 'catkin'
        if build_type_tag == 'catkin':
            msg.append('@{pf}~~@|  - @!@{bf}' + package.name + '@|')
        elif build_type_tag == 'cmake':
            msg.append(
                '@{pf}~~@|  - @!@{bf}' + package.name + '@|' +
                ' (@!@{cf}plain cmake@|)'
            )
        else:
            msg.append(
                '@{pf}~~@|  - @!@{bf}' + package.name + '@|' +
                ' (@{rf}unknown@|)'
            )
            unknown_build_types.append(package)
    msg.append('@{pf}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' + ('~' * len(str(len(ordered_packages)))))
    for index in range(len(msg)):
        msg[index] = fmt(msg[index])
    print('\n'.join(msg))

    # Error if there are packages with unknown build_types
    if unknown_build_types:
        raise RuntimeError('Can not build workspace with packages of unknown build_type.')

    # Check to see if the workspace has changed
    if not force_cmake:
        force_cmake, install_toggled = builder.cmake_input_changed(
            packages,
            buildspace,
            install=install,
            cmake_args=cmake_args,
            filename='catkin_make_isolated'
        )
        if force_cmake:
            print('The packages or cmake arguments have changed, forcing cmake invocation')
        elif install_toggled:
            print('The install argument has been toggled, forcing cmake invocation on plain cmake package')

    # Build packages
    original_develspace = copy.deepcopy(develspace)
    for index, path_package in enumerate(ordered_packages):
        path, package = path_package
        if not merge:
            develspace = os.path.join(original_develspace, package.name)
        if not build_packages or package.name in build_packages:
            try:
                export_tags = [e.tagname for e in package.exports]
                is_cmake_package = 'cmake' in [e.content for e in package.exports if e.tagname == 'build_type']
                builder.build_package(
                    path, package,
                    workspace, buildspace, develspace, installspace,
                    install, jobs, force_cmake or (install_toggled and is_cmake_package),
                    quiet, cmake_args, make_args,
                    number=index + 1, of=len(ordered_packages),
                    catkin_cmake_path=catkin_cmake_path,
                    catkin_python_path=catkin_python_path
                )
            except Exception as e:
                import traceback
                traceback.print_exc()
                builder.cprint(
                    '@{rf}@!<==@| ' +
                    'Failed to process package \'@!@{bf}' +
                    package.name + '@|\': \n  ' +
                    ('KeyboardInterrupt' if isinstance(e, KeyboardInterrupt)
                        else str(e))
                )
                if isinstance(e, subprocess.CalledProcessError):
                    cmd = ' '.join(e.cmd) if isinstance(e.cmd, list) else e.cmd
                    print(fmt("\n@{rf}Reproduce this error by running:"))
                    print(fmt("@{gf}@!==> @|") + cmd + "\n")
                sys.exit('Command failed, exiting.')
        else:
            builder.cprint("Skipping package: '@!@{bf}" + package.name + "@|'")

    # Provide a top level devel space environment setup script
    if not merge and not build_packages:
        # generate env.sh and setup.sh which relay to last devel space
        generated_env = os.path.join(original_develspace, 'env.sh')
        with open(generated_env, 'w') as f:
            f.write("""\
#!/usr/bin/env sh
# generated from catkin.builder module

{0} "$@"
""".format(os.path.join(develspace, 'env.sh')))
        os.chmod(generated_env, stat.S_IXUSR | stat.S_IWUSR | stat.S_IRUSR)
        with open(os.path.join(original_develspace, 'setup.sh'), 'w') as f:
            f.write("""\
#!/usr/bin/env sh
# generated from catkin.builder module

. "{0}/setup.sh"
""".format(develspace))
        # generate setup.bash and setup.zsh for convenience
        variables = {'SETUP_DIR': original_develspace}
        with open(os.path.join(original_develspace, 'setup.bash'), 'w') as f:
            f.write(configure_file(os.path.join(catkin_cmake_path, 'templates', 'setup.bash.in'), variables))
        with open(os.path.join(original_develspace, 'setup.zsh'), 'w') as f:
            f.write(configure_file(os.path.join(catkin_cmake_path, 'templates', 'setup.zsh.in'), variables))
Exemple #44
0
def print_build_details(build_dir, source_dir, install_prefix, build_type, underlays, name, toolchain, platform):
    console.pretty_println("\n************************** Parallel Buildspace Details ***************************", console.bold)
    console.pretty_print(" -- Build directory : ", console.cyan)
    console.pretty_println(build_dir, console.yellow)
    console.pretty_print(" -- Source directory: ", console.cyan)
    console.pretty_println(source_dir, console.yellow)
    console.pretty_print(" -- Install prefix  : ", console.cyan)
    console.pretty_println(install_prefix, console.yellow)
    console.pretty_print(" -- Build Type      : ", console.cyan)
    console.pretty_println(build_type, console.yellow)
    console.pretty_print(" -- Underlays       : ", console.cyan)
    console.pretty_println(underlays, console.yellow)
    console.pretty_print(" -- Eclipse Name    : ", console.cyan)
    console.pretty_println(name, console.yellow)
    if not toolchain == "":
        console.pretty_print(" -- Toolchain       : ", console.cyan)
        console.pretty_println(toolchain, console.yellow)
    if not platform == "":
        console.pretty_print(" -- Platform        : ", console.cyan)
        console.pretty_println(platform, console.yellow)
    console.pretty_println("**********************************************************************************\n", console.bold)
def print_details(workspace_dir, uri_list, lookup_name_list, lookup_track, lookup_database):
    console.pretty_println("\n***************************** Development Workspace ******************************", console.bold)
    console.pretty_print("Workspace   : ", console.cyan)
    console.pretty_println(workspace_dir, console.yellow)
    if lookup_name_list:
        console.pretty_print("  Names     : ", console.cyan)
        for lookup_name in lookup_name_list:
            console.pretty_print("%s " % lookup_name, console.yellow)
        console.pretty_println('', console.yellow)
        console.pretty_print("    Track   : ", console.cyan)
        console.pretty_println(lookup_track, console.yellow)
        console.pretty_print("    Database: ", console.cyan)
        console.pretty_println(lookup_database, console.yellow)
    console.pretty_print("  Sources   : ", console.cyan)
    if uri_list:
        console.pretty_println("%s " % uri_list[0], console.yellow)
        for uri in uri_list[1:]:
            console.pretty_print("            : ", console.cyan)
            console.pretty_println("%s " % uri, console.yellow)
    else:
        console.pretty_println("empty workspace", console.yellow)
    console.pretty_println("**********************************************************************************", console.bold)
    console.pretty_println("\nMerge additional source directories with `wstool` and configure parallel builds with 'yujin_init_build'.\n", console.cyan)
Exemple #46
0
def print_build_details(build_dir, source_dir, install_prefix, doc_prefix, build_type, underlays, name, toolchain, platform):
    console.pretty_println("\n************************** Parallel Buildspace Details ***************************", console.bold)
    console.pretty_print(" -- Build directory : ", console.cyan)
    console.pretty_println(build_dir, console.yellow)
    console.pretty_print(" -- Source directory: ", console.cyan)
    console.pretty_println(source_dir, console.yellow)
    console.pretty_print(" -- Install prefix  : ", console.cyan)
    console.pretty_println(install_prefix, console.yellow)
    console.pretty_print(" -- Document prefix : ", console.cyan)
    console.pretty_println(doc_prefix, console.yellow)
    console.pretty_print(" -- Build Type      : ", console.cyan)
    console.pretty_println(build_type, console.yellow)
    underlays_list = underlays.split(';')
    console.pretty_print(" -- Underlays       : ", console.cyan)
    if len(underlays_list) == 0:
        console.pretty_println("-", console.yellow)
    else:
        underlay = underlays_list.pop(0)
        console.pretty_println(underlay, console.yellow)
        for underlay in underlays_list:
            console.pretty_print("                    : ", console.cyan)
            console.pretty_println(underlay, console.yellow)
    console.pretty_print(" -- Eclipse Name    : ", console.cyan)
    console.pretty_println(name, console.yellow)
    if not toolchain == "":
        console.pretty_print(" -- Toolchain       : ", console.cyan)
        console.pretty_println(toolchain, console.yellow)
    if not platform == "":
        console.pretty_print(" -- Platform        : ", console.cyan)
        console.pretty_println(platform, console.yellow)
    console.pretty_println("**********************************************************************************\n", console.bold)
Exemple #47
0
def print_details(workspace_dir, uri_list, lookup_name_list, lookup_track,
                  lookup_database):
    console.pretty_println(
        "\n***************************** Development Workspace ******************************",
        console.bold)
    console.pretty_print("Workspace   : ", console.cyan)
    console.pretty_println(workspace_dir, console.yellow)
    if lookup_name_list:
        console.pretty_print("  Names     : ", console.cyan)
        for lookup_name in lookup_name_list:
            console.pretty_print("%s " % lookup_name, console.yellow)
        console.pretty_println('', console.yellow)
        console.pretty_print("    Track   : ", console.cyan)
        console.pretty_println(lookup_track, console.yellow)
        console.pretty_print("    Database: ", console.cyan)
        console.pretty_println(lookup_database, console.yellow)
    console.pretty_print("  Sources   : ", console.cyan)
    if uri_list:
        console.pretty_println("%s " % uri_list[0], console.yellow)
        for uri in uri_list[1:]:
            console.pretty_print("            : ", console.cyan)
            console.pretty_println("%s " % uri, console.yellow)
    else:
        console.pretty_println("empty workspace", console.yellow)
    console.pretty_println(
        "**********************************************************************************",
        console.bold)
    console.pretty_println(
        "\nMerge additional source directories with `wstool` and configure parallel builds with 'yujin_init_build'.\n",
        console.cyan)
Exemple #48
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)
Exemple #49
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)
Exemple #50
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')
Exemple #51
0
def print_build_details(build_dir, source_dir, install_prefix, doc_prefix,
                        build_type, underlays, name, toolchain, platform):
    console.pretty_println(
        "\n************************** Parallel Buildspace Details ***************************",
        console.bold)
    console.pretty_print(" -- Build directory : ", console.cyan)
    console.pretty_println(build_dir, console.yellow)
    console.pretty_print(" -- Source directory: ", console.cyan)
    console.pretty_println(source_dir, console.yellow)
    console.pretty_print(" -- Install prefix  : ", console.cyan)
    console.pretty_println(install_prefix, console.yellow)
    console.pretty_print(" -- Document prefix : ", console.cyan)
    console.pretty_println(doc_prefix, console.yellow)
    console.pretty_print(" -- Build Type      : ", console.cyan)
    console.pretty_println(build_type, console.yellow)
    underlays_list = underlays.split(';')
    console.pretty_print(" -- Underlays       : ", console.cyan)
    if len(underlays_list) == 0:
        console.pretty_println("-", console.yellow)
    else:
        underlay = underlays_list.pop(0)
        console.pretty_println(underlay, console.yellow)
        for underlay in underlays_list:
            console.pretty_print("                    : ", console.cyan)
            console.pretty_println(underlay, console.yellow)
    console.pretty_print(" -- Eclipse Name    : ", console.cyan)
    console.pretty_println(name, console.yellow)
    if not toolchain == "":
        console.pretty_print(" -- Toolchain       : ", console.cyan)
        console.pretty_println(toolchain, console.yellow)
    if not platform == "":
        console.pretty_print(" -- Platform        : ", console.cyan)
        console.pretty_println(platform, console.yellow)
    console.pretty_println(
        "**********************************************************************************\n",
        console.bold)