Example #1
0
def build_env(root: str, snap_name: str, arch_triplet: str) -> List[str]:
    """Set the environment variables required for building.

    This is required for the current parts installdir due to stage-packages
    and also to setup the stagedir.
    """
    env = []

    paths = common.get_include_paths(root, arch_triplet)
    if paths:
        for envvar in ["CPPFLAGS", "CFLAGS", "CXXFLAGS"]:
            env.append(
                formatting_utils.format_path_variable(
                    envvar, paths, prepend="-I", separator=" "
                )
            )

    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(
            formatting_utils.format_path_variable(
                "LDFLAGS", paths, prepend="-L", separator=" "
            )
        )

    paths = common.get_pkg_config_paths(root, arch_triplet)
    if paths:
        env.append(
            formatting_utils.format_path_variable(
                "PKG_CONFIG_PATH", paths, prepend="", separator=":"
            )
        )

    return env
Example #2
0
def build_env(root: str, snap_name: str, arch_triplet: str) -> List[str]:
    """Set the environment variables required for building.

    This is required for the current parts installdir due to stage-packages
    and also to setup the stagedir.
    """
    env = []

    paths = common.get_include_paths(root, arch_triplet)
    if paths:
        for envvar in ['CPPFLAGS', 'CFLAGS', 'CXXFLAGS']:
            env.append(
                formatting_utils.format_path_variable(envvar,
                                                      paths,
                                                      prepend='-I',
                                                      separator=' '))

    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(
            formatting_utils.format_path_variable('LDFLAGS',
                                                  paths,
                                                  prepend='-L',
                                                  separator=' '))

    paths = common.get_pkg_config_paths(root, arch_triplet)
    if paths:
        env.append(
            formatting_utils.format_path_variable('PKG_CONFIG_PATH',
                                                  paths,
                                                  prepend='',
                                                  separator=':'))

    return env
Example #3
0
    def _run(self, arguments) -> str:
        with tempfile.NamedTemporaryFile(mode="w+") as f:
            lines = [
                'export PYTHONPATH="{}"'.format(
                    os.path.join(
                        self._rospack_install_path,
                        "usr",
                        "lib",
                        "python2.7",
                        "dist-packages",
                    ))
            ]

            ros_path = os.path.join(self._rospack_install_path, "opt", "ros",
                                    self._ros_distro)
            bin_paths = (
                os.path.join(ros_path, "bin"),
                os.path.join(self._rospack_install_path, "usr", "bin"),
            )
            lines.append("export {}".format(
                formatting_utils.format_path_variable("PATH",
                                                      bin_paths,
                                                      prepend="",
                                                      separator=":")))

            lib_paths = common.get_library_paths(self._rospack_install_path,
                                                 self._project.arch_triplet)
            if lib_paths:
                lines.append("export {}".format(
                    formatting_utils.format_path_variable("LD_LIBRARY_PATH",
                                                          lib_paths,
                                                          prepend="",
                                                          separator=":")))

            # Source our own workspace so we have all of rospack's dependencies
            lines.append("_CATKIN_SETUP_DIR={} source {}".format(
                ros_path, os.path.join(ros_path, "setup.sh")))

            # By default, rospack saves its cache in $HOME/.ros, which we shouldn't
            # access here, so we'll redirect it with this environment variable.
            lines.append('export ROS_HOME="{}"'.format(
                self._rospack_cache_path))

            lines.append('export ROS_PACKAGE_PATH="{}"'.format(
                self._ros_package_path))

            lines.append('exec "$@"')
            f.write("\n".join(lines))
            f.flush()
            return (subprocess.check_output(
                ["/bin/bash", f.name, "rospack"] + arguments,
                stderr=subprocess.STDOUT,
            ).decode("utf8").strip())
Example #4
0
def _build_env(root, snap_name, confinement, arch_triplet,
               core_dynamic_linker=None):
    """Set the environment variables required for building.

    This is required for the current parts installdir due to stage-packages
    and also to setup the stagedir.
    """
    env = []

    paths = common.get_include_paths(root, arch_triplet)
    if paths:
        for envvar in ['CPPFLAGS', 'CFLAGS', 'CXXFLAGS']:
            env.append(formatting_utils.format_path_variable(
                envvar, paths, prepend='-I', separator=' '))

    if confinement == 'classic':
        if not core_dynamic_linker:
            raise EnvironmentError(
                'classic confinement requires the core snap to be installed. '
                'Install it by running `snap install core`.')

        core_path = common.get_core_path()
        core_rpaths = common.get_library_paths(core_path, arch_triplet,
                                               existing_only=False)
        snap_path = os.path.join('/snap', snap_name, 'current')
        snap_rpaths = common.get_library_paths(snap_path, arch_triplet,
                                               existing_only=False)

        # snap_rpaths before core_rpaths to prefer libraries from the snap.
        rpaths = formatting_utils.combine_paths(
            snap_rpaths + core_rpaths, prepend='', separator=':')
        env.append('LDFLAGS="$LDFLAGS '
                   # Building tools to continue the build becomes problematic
                   # with nodefaultlib.
                   # '-Wl,-z,nodefaultlib '
                   '-Wl,--dynamic-linker={0} '
                   '-Wl,-rpath,{1}"'.format(core_dynamic_linker, rpaths))

    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'LDFLAGS', paths, prepend='-L', separator=' '))

    paths = common.get_pkg_config_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'PKG_CONFIG_PATH', paths, prepend='', separator=':'))

    return env
Example #5
0
def _build_env(root, snap_name, confinement, arch_triplet,
               core_dynamic_linker=None):
    """Set the environment variables required for building.

    This is required for the current parts installdir due to stage-packages
    and also to setup the stagedir.
    """
    env = []

    paths = common.get_include_paths(root, arch_triplet)
    if paths:
        for envvar in ['CPPFLAGS', 'CFLAGS', 'CXXFLAGS']:
            env.append(formatting_utils.format_path_variable(
                envvar, paths, prepend='-I', separator=' '))

    if confinement == 'classic':
        if not core_dynamic_linker:
            raise EnvironmentError(
                'classic confinement requires the core snap to be installed. '
                'Install it by running `snap install core`.')

        core_path = common.get_core_path()
        core_rpaths = common.get_library_paths(core_path, arch_triplet,
                                               existing_only=False)
        snap_path = os.path.join('/snap', snap_name, 'current')
        snap_rpaths = common.get_library_paths(snap_path, arch_triplet,
                                               existing_only=False)

        # snap_rpaths before core_rpaths to prefer libraries from the snap.
        rpaths = formatting_utils.combine_paths(
            snap_rpaths + core_rpaths, prepend='', separator=':')
        env.append('LDFLAGS="$LDFLAGS '
                   # Building tools to continue the build becomes problematic
                   # with nodefaultlib.
                   # '-Wl,-z,nodefaultlib '
                   '-Wl,--dynamic-linker={0} '
                   '-Wl,-rpath,{1}"'.format(core_dynamic_linker, rpaths))

    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'LDFLAGS', paths, prepend='-L', separator=' '))

    paths = common.get_pkg_config_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'PKG_CONFIG_PATH', paths, prepend='', separator=':'))

    return env
Example #6
0
def _runtime_env(root, arch_triplet):
    """Set the environment variables required for running binaries."""
    env = []

    env.append('PATH="' + ':'.join([
        '{0}/usr/sbin',
        '{0}/usr/bin',
        '{0}/sbin',
        '{0}/bin',
        '$PATH'
    ]).format(root) + '"')

    # Add the default LD_LIBRARY_PATH
    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'LD_LIBRARY_PATH', paths, prepend='', separator=':'))

    # Add more specific LD_LIBRARY_PATH from staged packages if necessary
    ld_library_paths = libraries.determine_ld_library_path(root)
    if ld_library_paths:
        env.append('LD_LIBRARY_PATH="' + ':'.join(ld_library_paths) +
                   ':$LD_LIBRARY_PATH"')

    return env
Example #7
0
def _runtime_env(root, arch_triplet):
    """Set the environment variables required for running binaries."""
    env = []

    env.append('PATH="' + ':'.join([
        '{0}/usr/sbin',
        '{0}/usr/bin',
        '{0}/sbin',
        '{0}/bin',
        '$PATH'
    ]).format(root) + '"')

    # Add the default LD_LIBRARY_PATH
    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'LD_LIBRARY_PATH', paths, prepend='', separator=':'))

    # Add more specific LD_LIBRARY_PATH from staged packages if necessary
    ld_library_paths = libraries.determine_ld_library_path(root)
    if ld_library_paths:
        env.append('LD_LIBRARY_PATH="' + ':'.join(ld_library_paths) +
                   ':$LD_LIBRARY_PATH"')

    return env
Example #8
0
    def _run(self, arguments):
        with tempfile.NamedTemporaryFile(mode='w+') as f:
            lines = ['export PYTHONPATH={}'.format(os.path.join(
                self._catkin_install_path, 'usr', 'lib', 'python2.7',
                'dist-packages'))]

            ros_path = os.path.join(
                self._catkin_install_path, 'opt', 'ros', self._ros_distro)
            bin_paths = (
                os.path.join(ros_path, 'bin'),
                os.path.join(self._catkin_install_path, 'usr', 'bin'))
            lines.append('export {}'.format(
                formatting_utils.format_path_variable(
                    'PATH', bin_paths, prepend='', separator=':')))

            # Source our own workspace so we have all of Catkin's dependencies,
            # then source the workspace we're actually supposed to be crawling.
            lines.append('_CATKIN_SETUP_DIR={} source {}'.format(
                ros_path, os.path.join(ros_path, 'setup.sh')))
            lines.append('_CATKIN_SETUP_DIR={} source {} --extend'.format(
                self._workspace,
                os.path.join(self._workspace, 'setup.sh')))

            lines.append('exec "$@"')
            f.write('\n'.join(lines))
            f.flush()
            return subprocess.check_output(
                ['/bin/bash', f.name, 'catkin_find'] + arguments,
                stderr=subprocess.STDOUT).decode('utf8').strip()
Example #9
0
def runtime_env(root: str, arch_triplet: str) -> List[str]:
    """Set the environment variables required for running binaries."""
    env = []

    env.append(
        'PATH="'
        + ":".join(
            ["{0}/usr/sbin", "{0}/usr/bin", "{0}/sbin", "{0}/bin", "$PATH"]
        ).format(root)
        + '"'
    )

    # Add the default LD_LIBRARY_PATH
    paths = common.get_library_paths(root, arch_triplet)
    # Add more specific LD_LIBRARY_PATH from staged packages if necessary
    paths += elf.determine_ld_library_path(root)

    if paths:
        env.append(
            formatting_utils.format_path_variable(
                "LD_LIBRARY_PATH", paths, prepend="", separator=":"
            )
        )

    return env
Example #10
0
def runtime_env(root: str, arch_triplet: str) -> List[str]:
    """Set the environment variables required for running binaries."""
    env = []

    env.append(
        'PATH="'
        + ":".join(
            ["{0}/usr/sbin", "{0}/usr/bin", "{0}/sbin", "{0}/bin", "$PATH"]
        ).format(root)
        + '"'
    )

    # Add the default LD_LIBRARY_PATH
    paths = common.get_library_paths(root, arch_triplet)
    # Add more specific LD_LIBRARY_PATH from staged packages if necessary
    paths += elf.determine_ld_library_path(root)

    if paths:
        env.append(
            formatting_utils.format_path_variable(
                "LD_LIBRARY_PATH", paths, prepend="", separator=":"
            )
        )

    return env
Example #11
0
    def _run(self, arguments):
        with tempfile.NamedTemporaryFile(mode='w+') as f:
            lines = [
                'export PYTHONPATH={}'.format(
                    os.path.join(self._catkin_install_path, 'usr', 'lib',
                                 'python2.7', 'dist-packages'))
            ]

            ros_path = os.path.join(self._catkin_install_path, 'opt', 'ros',
                                    self._ros_distro)
            bin_paths = (os.path.join(ros_path, 'bin'),
                         os.path.join(self._catkin_install_path, 'usr', 'bin'))
            lines.append('export {}'.format(
                formatting_utils.format_path_variable('PATH',
                                                      bin_paths,
                                                      prepend='',
                                                      separator=':')))

            lines.append('export _CATKIN_SETUP_DIR={}'.format(self._workspace))
            lines.append('source {}'.format(
                os.path.join(self._workspace, 'setup.sh')))
            lines.append('exec "$@"')
            f.write('\n'.join(lines))
            f.flush()
            return subprocess.check_output(
                ['/bin/bash', f.name, 'catkin_find'] + arguments,
                stderr=subprocess.STDOUT).decode('utf8').strip()
Example #12
0
    def _run(self, arguments):
        with tempfile.NamedTemporaryFile(mode="w+") as f:
            lines = [
                "export PYTHONPATH={}".format(
                    os.path.join(
                        self._catkin_install_path,
                        "usr",
                        "lib",
                        "python2.7",
                        "dist-packages",
                    )
                )
            ]

            ros_path = os.path.join(
                self._catkin_install_path, "opt", "ros", self._ros_distro
            )
            bin_paths = (
                os.path.join(ros_path, "bin"),
                os.path.join(self._catkin_install_path, "usr", "bin"),
            )
            lines.append(
                "export {}".format(
                    formatting_utils.format_path_variable(
                        "PATH", bin_paths, prepend="", separator=":"
                    )
                )
            )

            # Source our own workspace so we have all of Catkin's dependencies,
            # then source the workspace we're actually supposed to be crawling.
            lines.append(
                "_CATKIN_SETUP_DIR={} source {} --local".format(
                    ros_path, os.path.join(ros_path, "setup.sh")
                )
            )

            for workspace in self._workspaces:
                lines.append(
                    "_CATKIN_SETUP_DIR={} source {} --local --extend".format(
                        workspace, os.path.join(workspace, "setup.sh")
                    )
                )

            lines.append('exec "$@"')
            f.write("\n".join(lines))
            f.flush()
            return (
                subprocess.check_output(
                    ["/bin/bash", f.name, "catkin_find"] + arguments,
                    stderr=subprocess.STDOUT,
                )
                .decode("utf8")
                .strip()
            )
Example #13
0
def env_for_classic(arch_triplet: str) -> List[str]:
    """Set the required environment variables for a classic confined build."""
    env = []

    core_path = common.get_core_path()
    paths = common.get_library_paths(core_path, arch_triplet,
                                     existing_only=False)
    env.append(formatting_utils.format_path_variable(
        'LD_LIBRARY_PATH', paths, prepend='', separator=':'))

    return env
Example #14
0
    def _run(self, arguments):
        with tempfile.NamedTemporaryFile(mode="w+") as f:
            lines = [
                "export PYTHONPATH={}".format(
                    os.path.join(
                        self._catkin_install_path,
                        "usr",
                        "lib",
                        "python2.7",
                        "dist-packages",
                    )
                )
            ]

            ros_path = os.path.join(
                self._catkin_install_path, "opt", "ros", self._ros_distro
            )
            bin_paths = (
                os.path.join(ros_path, "bin"),
                os.path.join(self._catkin_install_path, "usr", "bin"),
            )
            lines.append(
                "export {}".format(
                    formatting_utils.format_path_variable(
                        "PATH", bin_paths, prepend="", separator=":"
                    )
                )
            )

            # Source our own workspace so we have all of Catkin's dependencies,
            # then source the workspace we're actually supposed to be crawling.
            lines.append(
                "_CATKIN_SETUP_DIR={} source {}".format(
                    ros_path, os.path.join(ros_path, "setup.sh")
                )
            )
            lines.append(
                "_CATKIN_SETUP_DIR={} source {} --extend".format(
                    self._workspace, os.path.join(self._workspace, "setup.sh")
                )
            )

            lines.append('exec "$@"')
            f.write("\n".join(lines))
            f.flush()
            return (
                subprocess.check_output(
                    ["/bin/bash", f.name, "catkin_find"] + arguments,
                    stderr=subprocess.STDOUT,
                )
                .decode("utf8")
                .strip()
            )
Example #15
0
def env_for_classic(base: str, arch_triplet: str) -> List[str]:
    """Set the required environment variables for a classic confined build."""
    env = []

    core_path = common.get_core_path(base)
    paths = common.get_library_paths(core_path, arch_triplet, existing_only=False)
    env.append(
        formatting_utils.format_path_variable(
            "LD_LIBRARY_PATH", paths, prepend="", separator=":"
        )
    )

    return env
Example #16
0
def _build_env(root, arch_triplet):
    """Set the environment variables required for building.

    This is required for the current parts installdir due to stage-packages
    and also to setup the stagedir.
    """
    env = []

    paths = common.get_include_paths(root, arch_triplet)
    if paths:
        for envvar in ['CPPFLAGS', 'CFLAGS', 'CXXFLAGS']:
            env.append(formatting_utils.format_path_variable(
                envvar, paths, prepend='-I', separator=' '))
    paths = common.get_library_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'LDFLAGS', paths, prepend='-L', separator=' '))
    paths = common.get_pkg_config_paths(root, arch_triplet)
    if paths:
        env.append(formatting_utils.format_path_variable(
            'PKG_CONFIG_PATH', paths, prepend='', separator=':'))

    return env
Example #17
0
def test_two_paths_other_paremeters():
    paths = ["/usr/bin", "/usr/sbin"]
    output = formatting_utils.format_path_variable("PATH", paths, "", ",")

    assert output == 'PATH="${PATH:+$PATH,}/usr/bin,/usr/sbin"'
Example #18
0
 def test_two_paths(self):
     paths = ["/bin", "/sbin"]
     output = formatting_utils.format_path_variable("PATH", paths, "/usr",
                                                    ":")
     self.assertThat(output, Equals('PATH="$PATH:/usr/bin:/usr/sbin"'))
Example #19
0
def test_no_paths():
    with pytest.raises(ValueError):
        formatting_utils.format_path_variable("PATH", list(), "/usr", ":")
 def test_two_paths_other_paremeters(self):
     paths = ['/usr/bin', '/usr/sbin']
     output = formatting_utils.format_path_variable('PATH', paths, '', ',')
     self.assertThat(output, Equals('PATH="$PATH,/usr/bin,/usr/sbin"'))
 def test_two_paths(self):
     paths = ['/bin', '/sbin']
     output = formatting_utils.format_path_variable('PATH', paths, '/usr',
                                                    ':')
     self.assertThat(output, Equals('PATH="$PATH:/usr/bin:/usr/sbin"'))
Example #22
0
 def test_two_paths_other_paremeters(self):
     paths = ["/usr/bin", "/usr/sbin"]
     output = formatting_utils.format_path_variable("PATH", paths, "", ",")
     self.assertThat(output, Equals('PATH="$PATH,/usr/bin,/usr/sbin"'))
Example #23
0
def test_two_paths():
    paths = ["/bin", "/sbin"]
    output = formatting_utils.format_path_variable("PATH", paths, "/usr", ":")

    assert output == 'PATH="${PATH:+$PATH:}/usr/bin:/usr/sbin"'