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

        # expand package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            template_path = get_package_level_template_path(name)
            variables = {'CMAKE_INSTALL_PREFIX': context.install_space}
            if name[:-3].endswith('.sh'):
                variables['ENVIRONMENT_HOOKS'] = \
                    'ament_append_value AMENT_ENVIRONMENT_HOOKS "%s"\n' % \
                    ':'.join([
                        os.path.join('$AMENT_CURRENT_PREFIX', path_environment_hook),
                        os.path.join('$AMENT_CURRENT_PREFIX', pythonpath_environment_hook),
                    ])
            elif name[:-3].endswith('.bat'):
                t = 'call:ament_append_value AMENT_ENVIRONMENT_HOOKS[%s] "%s"\n'
                variables['ENVIRONMENT_HOOKS'] = t % (
                    context.package_manifest.name, ';'.join([
                        os.path.join('%AMENT_CURRENT_PREFIX%',
                                     path_environment_hook),
                        os.path.join('%AMENT_CURRENT_PREFIX%',
                                     pythonpath_environment_hook),
                    ]))
                variables['PROJECT_NAME'] = context.package_manifest.name
            content = configure_file(template_path, variables)
            destination_path = os.path.join(context.build_space, 'share',
                                            context.package_manifest.name,
                                            name[:-3])
            with open(destination_path, 'w') as h:
                h.write(content)
    def _build_action(self, context):
        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_environment_hook = os.path.join(
            'share', context.package_manifest.name, 'environment', 'path' + ext)
        # expand environment hook for PYTHONPATH
        ext = '.sh.in' if not IS_WINDOWS else '.bat.in'
        template_path = get_environment_hook_template_path('pythonpath' + ext)
        content = configure_file(template_path, {
            'PYTHON_INSTALL_DIR': self._get_python_lib(context),
        })
        pythonpath_environment_hook = os.path.join(
            'share', context.package_manifest.name, 'environment',
            os.path.basename(template_path)[:-3])
        destination_path = os.path.join(
            context.build_space, pythonpath_environment_hook)
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_path, 'w') as h:
            h.write(content)

        # expand package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            template_path = get_package_level_template_path(name)
            variables = {'CMAKE_INSTALL_PREFIX': context.install_space}
            if name[:-3].endswith('.sh'):
                variables['ENVIRONMENT_HOOKS'] = \
                    'ament_append_value AMENT_ENVIRONMENT_HOOKS "%s"\n' % \
                    ':'.join([
                        os.path.join('$AMENT_CURRENT_PREFIX', path_environment_hook),
                        os.path.join('$AMENT_CURRENT_PREFIX', pythonpath_environment_hook),
                    ])
            elif name[:-3].endswith('.bat'):
                t = 'call:ament_append_value AMENT_ENVIRONMENT_HOOKS[%s] "%s"\n'
                variables['ENVIRONMENT_HOOKS'] = t % (
                    context.package_manifest.name,
                    ';'.join([
                        os.path.join('%AMENT_CURRENT_PREFIX%', path_environment_hook),
                        os.path.join('%AMENT_CURRENT_PREFIX%', pythonpath_environment_hook),
                    ])
                )
                variables['PROJECT_NAME'] = context.package_manifest.name
            content = configure_file(template_path, variables)
            destination_path = os.path.join(
                context.build_space,
                'share', context.package_manifest.name,
                name[:-3])
            with open(destination_path, 'w') as h:
                h.write(content)
Example #3
0
    def _build_action(self, context):
        environment_hooks_path = os.path.join('share',
                                              context.package_manifest.name,
                                              'environment')

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

        environment_hooks = [
            path_environment_hook,
            pythonpath_environment_hook,
        ]

        # expand package-level setup files
        expand_package_level_setup_files(context, environment_hooks,
                                         environment_hooks_path)
Example #4
0
    def _build_action(self, context):
        environment_hooks_path = os.path.join(
            'share', context.package_manifest.name, 'environment')

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

        environment_hooks = [
            path_environment_hook,
            pythonpath_environment_hook,
        ]

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

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

        yield BuildAction(cmd, cwd=context.source_space)

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

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

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

        environment_hooks = [
            path_environment_hook,
            javapath_environment_hook,
        ]

        # expand package-level setup files
        expand_package_level_setup_files(context, environment_hooks,
                                         environment_hooks_path)
Example #6
0
def expand_package_level_setup_files(context, environment_hooks, environment_hooks_path):
    destinations = []

    for name in get_package_level_template_names():
        assert name.endswith('.in')

        local_environment_hooks = []
        if os.path.splitext(name[:-3])[1] in ['.sh', '.bat']:
            local_environment_hooks.extend(environment_hooks)

        # check if any data files are environment hooks (Python only)
        for data_file in context.get('setup.py', {}).get('data_files', {}).values():
            if not data_file.startswith(environment_hooks_path):
                continue
            # ignore data files with different extensions
            if os.path.splitext(data_file)[1] != os.path.splitext(name[:-3])[1]:
                continue
            local_environment_hooks.append(data_file)

        template_path = get_package_level_template_path(name)
        variables = {'CMAKE_INSTALL_PREFIX': context.install_space}
        if name[:-3].endswith('.bat'):
            variables['PROJECT_NAME'] = context.package_manifest.name
        if local_environment_hooks:
            if name[:-3].endswith('.bat'):
                t = 'call:ament_append_value AMENT_ENVIRONMENT_HOOKS[%s] "%s"\n'
                variables['ENVIRONMENT_HOOKS'] = t % (
                    context.package_manifest.name,
                    ';'.join([
                        os.path.join('%AMENT_CURRENT_PREFIX%', environment_hook)
                        for environment_hook in local_environment_hooks
                    ])
                )
            else:
                variables['ENVIRONMENT_HOOKS'] = \
                    'ament_append_value AMENT_ENVIRONMENT_HOOKS "%s"\n' % \
                    ':'.join([
                        os.path.join('$AMENT_CURRENT_PREFIX', environment_hook)
                        for environment_hook in local_environment_hooks
                    ])
        content = configure_file(template_path, variables)
        destination_path = os.path.join(
            context.build_space,
            'share', context.package_manifest.name,
            name[:-3])
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        destinations.append(destination_path)
        with open(destination_path, 'w') as h:
            h.write(content)

    return destinations
Example #7
0
def expand_prefix_level_setup_files(context):
    # expand prefix-level setup files
    for name in get_prefix_level_template_names():
        if name.endswith('.in'):
            template_path = get_prefix_level_template_path(name)
            content = configure_file(
                template_path, {
                    'CMAKE_INSTALL_PREFIX': context.install_space,
                })
            destination_path = os.path.join(context.build_space, name[:-3])
            with open(destination_path, 'w') as h:
                h.write(content)
Example #8
0
def expand_prefix_level_setup_files(context):
    # expand prefix-level setup files
    for name in get_prefix_level_template_names():
        if name.endswith('.in'):
            template_path = get_prefix_level_template_path(name)
            content = configure_file(template_path, {
                'CMAKE_INSTALL_PREFIX': context.install_space,
            })
            destination_path = os.path.join(
                context.build_space, name[:-3])
            with open(destination_path, 'w') as h:
                h.write(content)
Example #9
0
def iterate_packages(opts, packages, per_package_callback):
    install_space_base = opts.install_space
    package_dict = dict([(path, package) for path, package, _ in packages])
    workspace_package_names = [pkg.name for pkg in package_dict.values()]
    jobs = OrderedDict()
    for (path, package, depends) in packages:
        if package.name in opts.skip_packages:
            print('# Skipping: %s' % package.name)
        else:
            pkg_path = os.path.join(opts.basepath, path)
            package_opts = copy.copy(opts)
            package_opts.path = os.path.abspath(
                os.path.join(os.getcwd(), pkg_path))
            if package_opts.isolated:
                package_opts.install_space = os.path.join(
                    install_space_base, package.name)

            # get recursive package dependencies in topological order
            ordered_depends = topological_order_packages(package_dict,
                                                         whitelisted=depends)
            ordered_depends = [
                pkg.name for _, pkg, _ in ordered_depends
                if pkg.name != package.name
            ]
            # get package share folder for each package
            package_opts.build_dependencies = []
            for depend in ordered_depends:
                install_space = install_space_base
                if package_opts.isolated:
                    install_space = os.path.join(install_space, depend)
                package_share = os.path.join(install_space, 'share', depend)
                package_opts.build_dependencies.append(package_share)

            # get the package share folder for each exec depend of the package
            package_opts.exec_dependency_paths_in_workspace = []
            for dep_object in package.exec_depends:
                dep_name = dep_object.name
                if dep_name not in workspace_package_names:
                    # do not add to this list if the dependency is not in the workspace
                    continue
                install_space = install_space_base
                if package_opts.isolated:
                    install_space = os.path.join(install_space, dep_name)
                package_share = os.path.join(install_space, 'share', dep_name)
                package_opts.exec_dependency_paths_in_workspace.append(
                    package_share)

            jobs[package.name] = {
                'callback': per_package_callback,
                'opts': package_opts,
                'depends': ordered_depends,
            }
        if package.name == opts.end_with:
            break

    if not opts.parallel:
        rc = processSequentially(jobs)
    else:
        rc = processInParallel(jobs)

    if not rc and opts.end_with:
        print("Stopped after package '{0}'".format(opts.end_with))

    # expand prefix-level setup files for the root of the install-space
    if opts.isolated:
        for name in get_isolated_prefix_level_template_names():
            template_path = get_isolated_prefix_level_template_path(name)
            if name.endswith('.in'):
                content = configure_file(
                    template_path, {
                        'CMAKE_INSTALL_PREFIX': install_space_base,
                        'PYTHON_EXECUTABLE': sys.executable,
                    })
                destination_path = os.path.join(install_space_base, name[:-3])
                with open(destination_path, 'w') as h:
                    h.write(content)
            else:
                dst = os.path.join(install_space_base, name)
                if os.path.exists(dst):
                    if not opts.symlink_install or \
                            not os.path.islink(dst) or \
                            not os.path.samefile(template_path, dst):
                        os.remove(dst)
                if not os.path.exists(dst):
                    if not opts.symlink_install:
                        shutil.copy(template_path, dst)
                    else:
                        os.symlink(template_path, dst)

    return rc
Example #10
0
def iterate_packages(opts, packages, per_package_callback):
    install_space_base = opts.install_space
    package_dict = {path: package for path, package, _ in packages}
    workspace_package_names = [pkg.name for pkg in package_dict.values()]
    jobs = OrderedDict()
    for (path, package, depends) in packages:
        if package.name in opts.skip_packages:
            print('# Skipping: %s' % package.name)
        else:
            pkg_path = os.path.join(opts.basepath, path)
            package_opts = copy.copy(opts)
            package_opts.path = os.path.abspath(os.path.join(os.getcwd(), pkg_path))
            if package_opts.isolated:
                package_opts.install_space = os.path.join(install_space_base, package.name)

            # get recursive package dependencies in topological order
            ordered_depends = topological_order_packages(
                package_dict, whitelisted=depends)
            ordered_depends = [
                pkg.name
                for _, pkg, _ in ordered_depends
                if pkg.name != package.name]
            # get package share folder for each package
            package_opts.build_dependencies = []
            for depend in ordered_depends:
                install_space = install_space_base
                if package_opts.isolated:
                    install_space = os.path.join(install_space, depend)
                package_share = os.path.join(install_space, 'share', depend)
                package_opts.build_dependencies.append(package_share)

            # get the package share folder for each exec depend of the package
            # also consider group dependencies
            package_opts.exec_dependency_paths_in_workspace = []
            dep_names = [d.name for d in package.exec_depends]
            for g in package.group_depends:
                dep_names += g.members
            for dep_name in dep_names:
                if dep_name not in workspace_package_names:
                    # do not add to this list if the dependency is not in the workspace
                    continue
                install_space = install_space_base
                if package_opts.isolated:
                    install_space = os.path.join(install_space, dep_name)
                package_share = os.path.join(install_space, 'share', dep_name)
                package_opts.exec_dependency_paths_in_workspace.append(package_share)

            jobs[package.name] = {
                'callback': per_package_callback,
                'opts': package_opts,
                'depends': ordered_depends,
            }
        if package.name == opts.end_with:
            break

    if not opts.parallel:
        rc = process_sequentially(jobs)
    else:
        rc = process_in_parallel(jobs)

    if not rc and opts.end_with:
        print("Stopped after package '{0}'".format(opts.end_with))

    # expand prefix-level setup files for the root of the install-space
    if opts.isolated:
        for name in get_isolated_prefix_level_template_names():
            template_path = get_isolated_prefix_level_template_path(name)
            if name.endswith('.in'):
                content = configure_file(template_path, {
                    'CMAKE_INSTALL_PREFIX': install_space_base,
                    'PYTHON_EXECUTABLE': opts.python_interpreter,
                })
                destination_path = os.path.join(
                    install_space_base, name[:-3])
                with open(destination_path, 'w') as h:
                    h.write(content)
            else:
                dst = os.path.join(install_space_base, name)
                if os.path.exists(dst):
                    if not opts.symlink_install or \
                            not os.path.islink(dst) or \
                            not os.path.samefile(template_path, dst):
                        os.remove(dst)
                if not os.path.exists(dst):
                    if not opts.symlink_install:
                        shutil.copy(template_path, dst)
                    else:
                        os.symlink(template_path, dst)

    return rc
Example #11
0
def iterate_packages(opts, packages, per_package_callback):
    start_with_found = not opts.start_with
    install_space_base = opts.install_space
    package_dict = dict([(path, package) for path, package, _ in packages])
    for (path, package, depends) in packages:
        if package.name == opts.start_with:
            start_with_found = True
        if not start_with_found:
            print('# Skipping: %s' % package.name)
            continue
        pkg_path = os.path.join(opts.basepath, path)
        opts.path = pkg_path
        if opts.isolated:
            opts.install_space = os.path.join(install_space_base, package.name)

        # get recursive package dependencies in topological order
        ordered_depends = topological_order_packages(package_dict,
                                                     whitelisted=depends)
        ordered_depends = [
            pkg.name for _, pkg, _ in ordered_depends
            if pkg.name != package.name
        ]
        # get package share folder for each package
        opts.build_dependencies = []
        for depend in ordered_depends:
            install_space = install_space_base
            if opts.isolated:
                install_space = os.path.join(install_space, depend)
            package_share = os.path.join(install_space, 'share', depend)
            opts.build_dependencies.append(package_share)

        rc = per_package_callback(opts)
        if rc:
            return rc
        if package.name == opts.end_with:
            print("Stopped after package '{0}'".format(package.name))
            break

    # expand prefix-level setup files for the root of the install-space
    if opts.isolated:
        for name in get_isolated_prefix_level_template_names():
            template_path = get_isolated_prefix_level_template_path(name)
            if name.endswith('.in'):
                content = configure_file(
                    template_path, {
                        'CMAKE_INSTALL_PREFIX': install_space_base,
                        'PYTHON_EXECUTABLE': sys.executable,
                    })
                destination_path = os.path.join(install_space_base, name[:-3])
                with open(destination_path, 'w') as h:
                    h.write(content)
            else:
                dst = os.path.join(install_space_base, name)
                if os.path.exists(dst):
                    if not opts.symlink_install or \
                            not os.path.islink(dst) or \
                            not os.path.samefile(template_path, dst):
                        os.remove(dst)
                if not os.path.exists(dst):
                    if not opts.symlink_install:
                        shutil.copy(template_path, dst)
                    else:
                        os.symlink(template_path, dst)
Example #12
0
def iterate_packages(opts, packages, per_package_callback):
    start_with_found = not opts.start_with
    install_space_base = opts.install_space
    package_dict = dict([(path, package) for path, package, _ in packages])
    for (path, package, depends) in packages:
        if package.name == opts.start_with:
            start_with_found = True
        if not start_with_found:
            print('# Skipping: %s' % package.name)
            continue
        pkg_path = os.path.join(opts.basepath, path)
        opts.path = pkg_path
        if opts.isolated:
            opts.install_space = os.path.join(install_space_base, package.name)

        # get recursive package dependencies in topological order
        ordered_depends = topological_order_packages(
            package_dict, whitelisted=depends)
        ordered_depends = [
            pkg.name
            for _, pkg, _ in ordered_depends
            if pkg.name != package.name]
        # get package share folder for each package
        opts.build_dependencies = []
        for depend in ordered_depends:
            install_space = install_space_base
            if opts.isolated:
                install_space = os.path.join(install_space, depend)
            package_share = os.path.join(install_space, 'share', depend)
            opts.build_dependencies.append(package_share)

        rc = per_package_callback(opts)
        if rc:
            return rc
        if package.name == opts.end_with:
            print("Stopped after package '{0}'".format(package.name))
            break

    # expand prefix-level setup files for the root of the install-space
    if opts.isolated:
        for name in get_isolated_prefix_level_template_names():
            template_path = get_isolated_prefix_level_template_path(name)
            if name.endswith('.in'):
                content = configure_file(template_path, {
                    'CMAKE_INSTALL_PREFIX': install_space_base,
                    'PYTHON_EXECUTABLE': sys.executable,
                })
                destination_path = os.path.join(
                    install_space_base, name[:-3])
                with open(destination_path, 'w') as h:
                    h.write(content)
            else:
                dst = os.path.join(install_space_base, name)
                if os.path.exists(dst):
                    if not opts.symlink_install or \
                            not os.path.islink(dst) or \
                            not os.path.samefile(template_path, dst):
                        os.remove(dst)
                if not os.path.exists(dst):
                    if not opts.symlink_install:
                        shutil.copy(template_path, dst)
                    else:
                        os.symlink(template_path, dst)