Example #1
0
    def test_build_environment(self):
        class Options:
            configflags = []

        plugin = cmake.CMakePlugin('test-part', Options())
        os.makedirs(plugin.builddir)
        plugin.build()

        expected = {}

        expected['CMAKE_PREFIX_PATH'] = '$CMAKE_PREFIX_PATH:{}'.format(
            common.get_stagedir())
        expected['CMAKE_INCLUDE_PATH'] = '$CMAKE_INCLUDE_PATH:' + ':'.join(
            ['{0}/include', '{0}/usr/include', '{0}/include/{1}',
             '{0}/usr/include/{1}']).format(common.get_stagedir(),
                                            common.get_arch_triplet())
        expected['CMAKE_LIBRARY_PATH'] = '$CMAKE_LIBRARY_PATH:' + ':'.join(
            ['{0}/lib', '{0}/usr/lib', '{0}/lib/{1}',
             '{0}/usr/lib/{1}']).format(common.get_stagedir(),
                                        common.get_arch_triplet())

        self.assertEqual(3, self.run_mock.call_count)
        for call_args in self.run_mock.call_args_list:
            environment = call_args[1]['env']
            for variable, value in expected.items():
                self.assertTrue(
                    variable in environment,
                    'Expected variable "{}" to be in environment'.format(
                        variable))

                self.assertEqual(environment[variable], value,
                                 'Expected ${}={}, but it was {}'.format(
                                 variable, value, environment[variable]))
Example #2
0
 def build_env(self, root):
     env = []
     env.append('CFLAGS="' + ' '.join([
         '-I{0}/include',
         '-I{0}/usr/include',
         '-I{0}/include/{1}',
         '-I{0}/usr/include/{1}',
         '$CFLAGS'
     ]).format(root, common.get_arch_triplet()) + '"')
     env.append('CPPFLAGS="' + ' '.join([
         '-I{0}/include',
         '-I{0}/usr/include',
         '-I{0}/include/{1}',
         '-I{0}/usr/include/{1}',
         '$CPPFLAGS'
     ]).format(root, common.get_arch_triplet()) + '"')
     env.append('LDFLAGS="' + ' '.join([
         '-L{0}/lib',
         '-L{0}/usr/lib',
         '-L{0}/lib/{1}',
         '-L{0}/usr/lib/{1}',
         '$LDFLAGS'
     ]).format(root, common.get_arch_triplet()) + '"')
     env.append('PKG_CONFIG_SYSROOT_DIR={0}'.format(root))
     env.append('PKG_CONFIG_PATH=' + ':'.join([
         '{0}/usr/lib/pkgconfig',
         '{0}/usr/lib/{1}/pkgconfig',
         '{0}/usr/share/pkgconfig',
         '{0}/usr/local/lib/pkgconfig',
         '{0}/usr/local/lib/{1}/pkgconfig',
         '{0}/usr/local/share/pkgconfig',
         '$PKG_CONFIG_PATH'
     ]).format(root, common.get_arch_triplet()))
     env.append('PERL5LIB={0}/usr/share/perl5/'.format(root))
     return env
Example #3
0
    def test_arch_triplet_migration_message(self):
        with self.assertRaises(EnvironmentError) as raised:
            common.get_arch_triplet()

        self.assertEqual(
            str(raised.exception),
            "This plugin is outdated, use 'project.arch_triplet'")
Example #4
0
    def _build_environment(self):
        env = os.environ.copy()
        env['CMAKE_PREFIX_PATH'] = '$CMAKE_PREFIX_PATH:{}'.format(
            common.get_stagedir())
        env['CMAKE_INCLUDE_PATH'] = '$CMAKE_INCLUDE_PATH:' + ':'.join([
            '{0}/include', '{0}/usr/include', '{0}/include/{1}',
            '{0}/usr/include/{1}'
        ]).format(common.get_stagedir(), common.get_arch_triplet())
        env['CMAKE_LIBRARY_PATH'] = '$CMAKE_LIBRARY_PATH:' + ':'.join([
            '{0}/lib', '{0}/usr/lib', '{0}/lib/{1}', '{0}/usr/lib/{1}'
        ]).format(common.get_stagedir(), common.get_arch_triplet())

        return env
Example #5
0
    def _build_environment(self):
        env = os.environ.copy()
        env['CMAKE_PREFIX_PATH'] = '$CMAKE_PREFIX_PATH:{}'.format(
            common.get_stagedir())
        env['CMAKE_INCLUDE_PATH'] = '$CMAKE_INCLUDE_PATH:' + ':'.join(
            ['{0}/include', '{0}/usr/include', '{0}/include/{1}',
             '{0}/usr/include/{1}']).format(common.get_stagedir(),
                                            common.get_arch_triplet())
        env['CMAKE_LIBRARY_PATH'] = '$CMAKE_LIBRARY_PATH:' + ':'.join(
            ['{0}/lib', '{0}/usr/lib', '{0}/lib/{1}',
             '{0}/usr/lib/{1}']).format(common.get_stagedir(),
                                        common.get_arch_triplet())

        return env
Example #6
0
def _build_env(root):
    """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 = []

    arch_triplet = common.get_arch_triplet()

    for envvar in ['CPPFLAGS', 'CFLAGS', 'CXXFLAGS']:
        include_path_for_env = _get_include_paths(envvar, root)
        if include_path_for_env:
            env.append(include_path_for_env)
    library_path = _get_library_paths('LDFLAGS', root)
    if library_path:
        env.append(library_path)
    env.append('PKG_CONFIG_PATH=' + ':'.join([
        '{0}/lib/pkgconfig',
        '{0}/lib/{1}/pkgconfig',
        '{0}/usr/lib/pkgconfig',
        '{0}/usr/lib/{1}/pkgconfig',
        '{0}/usr/share/pkgconfig',
        '{0}/usr/local/lib/pkgconfig',
        '{0}/usr/local/lib/{1}/pkgconfig',
        '{0}/usr/local/share/pkgconfig',
        '$PKG_CONFIG_PATH'
    ]).format(root, arch_triplet))

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

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

    # Add the default LD_LIBRARY_PATH
    env.append('LD_LIBRARY_PATH="' + ':'.join([
        '{0}/lib',
        '{0}/usr/lib',
        '{0}/lib/{1}',
        '{0}/usr/lib/{1}',
        '$LD_LIBRARY_PATH'
    ]).format(root, common.get_arch_triplet()) + '"')

    # Add more specific LD_LIBRARY_PATH 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 _runtime_env(root):
    """Set the environment variables required for running binaries."""
    env = []

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

    # Add the default LD_LIBRARY_PATH
    env.append('LD_LIBRARY_PATH="' + ':'.join([
        '{0}/lib',
        '{0}/usr/lib',
        '{0}/lib/{1}',
        '{0}/usr/lib/{1}',
        '$LD_LIBRARY_PATH'
    ]).format(root, common.get_arch_triplet()) + '"')

    # Add more specific LD_LIBRARY_PATH 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
    def test_environment(self):
        class Options:
            source = 'http://github.com/testplug'
            go_packages = []

        plugin = go.GoPlugin('test', Options())
        self.assertEqual(plugin.env('myroot'), [
            'GOPATH=myroot/go',
            'CGO_LDFLAGS=$CGO_LDFLAGS"-Lmyroot/lib -Lmyroot/usr/lib '
            '-Lmyroot/lib/{0} '
            '-Lmyroot/usr/lib/{0} $LDFLAGS"'.format(
                common.get_arch_triplet())])
Example #10
0
    def test_environment(self):
        class Options:
            source = 'http://github.com/testplug'
            go_packages = []

        plugin = go.GoPlugin('test', Options())
        self.assertEqual(plugin.env('myroot'), [
            'GOPATH=myroot/go',
            'CGO_LDFLAGS="$CGO_LDFLAGS -Lmyroot/lib -Lmyroot/usr/lib '
            '-Lmyroot/lib/{0} '
            '-Lmyroot/usr/lib/{0} $LDFLAGS"'.format(common.get_arch_triplet())
        ])
Example #11
0
 def build_env(self, root):
     env = []
     env.append(
         'CFLAGS="'
         + " ".join(
             ["-I{0}/include", "-I{0}/usr/include", "-I{0}/include/{1}", "-I{0}/usr/include/{1}", "$CFLAGS"]
         ).format(root, common.get_arch_triplet())
         + '"'
     )
     env.append(
         'CPPFLAGS="'
         + " ".join(
             ["-I{0}/include", "-I{0}/usr/include", "-I{0}/include/{1}", "-I{0}/usr/include/{1}", "$CPPFLAGS"]
         ).format(root, common.get_arch_triplet())
         + '"'
     )
     env.append(
         'LDFLAGS="'
         + " ".join(["-L{0}/lib", "-L{0}/usr/lib", "-L{0}/lib/{1}", "-L{0}/usr/lib/{1}", "$LDFLAGS"]).format(
             root, common.get_arch_triplet()
         )
         + '"'
     )
     env.append("PKG_CONFIG_SYSROOT_DIR={0}".format(root))
     env.append(
         "PKG_CONFIG_PATH="
         + ":".join(
             [
                 "{0}/usr/lib/pkgconfig",
                 "{0}/usr/lib/{1}/pkgconfig",
                 "{0}/usr/share/pkgconfig",
                 "{0}/usr/local/lib/pkgconfig",
                 "{0}/usr/local/lib/{1}/pkgconfig",
                 "{0}/usr/local/share/pkgconfig",
                 "$PKG_CONFIG_PATH",
             ]
         ).format(root, common.get_arch_triplet())
     )
     env.append("PERL5LIB={0}/usr/share/perl5/".format(root))
     return env
Example #12
0
    def _build_catkin_packages(self):
        # Nothing to do if no packages were specified
        if not self.catkin_packages:
            return

        catkincmd = ['catkin_make_isolated']

        # Install the package
        catkincmd.append('--install')

        # Specify the packages to be built
        catkincmd.append('--pkg')
        catkincmd.extend(self.catkin_packages)

        # Don't clutter the real ROS workspace-- use the Snapcraft build
        # directory
        catkincmd.extend(['--directory', self.builddir])

        # Account for a non-default source space by always specifying it
        catkincmd.extend([
            '--source-space',
            os.path.join(self.builddir, self.options.source_space)
        ])

        # Specify that the package should be installed along with the rest of
        # the ROS distro.
        catkincmd.extend(['--install-space', self.rosdir])

        # All the arguments that follow are meant for CMake
        catkincmd.append('--cmake-args')

        # Make sure we're using the compilers included in this .snap
        catkincmd.extend([
            '-DCMAKE_C_FLAGS="$CFLAGS"',
            '-DCMAKE_CXX_FLAGS="$CPPFLAGS -I{} -I{}"'.format(
                os.path.join(self.installdir, 'usr', 'include', 'c++',
                             self.gcc_version),
                os.path.join(self.installdir, 'usr', 'include',
                             common.get_arch_triplet(), 'c++',
                             self.gcc_version)), '-DCMAKE_LD_FLAGS="$LDFLAGS"',
            '-DCMAKE_C_COMPILER={}'.format(
                os.path.join(self.installdir, 'usr', 'bin',
                             'gcc')), '-DCMAKE_CXX_COMPILER={}'.format(
                                 os.path.join(self.installdir, 'usr', 'bin',
                                              'g++'))
        ])

        # This command must run in bash due to a bug in Catkin that causes it
        # to explode if there are spaces in the cmake args (which there are).
        # This has been fixed in Catkin Tools... perhaps we should be using
        # that instead.
        self._run_in_bash(catkincmd)
Example #13
0
def _create_pkg_config_override(bindir, installdir, stagedir):
    pkg_config_path = os.path.join(bindir, 'pkg-config')
    os.makedirs(os.path.dirname(pkg_config_path), exist_ok=True)

    arch = common.get_arch_triplet()
    pkg_config_content = _PKG_CONFIG_TEMPLATE.format(
        installdir=installdir, stagedir=stagedir, arch=arch)

    with open(pkg_config_path, 'w') as fn:
        fn.write(pkg_config_content)
    os.chmod(pkg_config_path, 0o755)

    return ['PATH={}:$PATH'.format(bindir)]
Example #14
0
    def _build_catkin_packages(self):
        # Nothing to do if no packages were specified
        if not self.catkin_packages:
            return

        catkincmd = ['catkin_make_isolated']

        # Install the package
        catkincmd.append('--install')

        # Specify the packages to be built
        catkincmd.append('--pkg')
        catkincmd.extend(self.catkin_packages)

        # Don't clutter the real ROS workspace-- use the Snapcraft build
        # directory
        catkincmd.extend(['--directory', self.builddir])

        # Account for a non-default source space by always specifying it
        catkincmd.extend(['--source-space', os.path.join(
            self.builddir, self.options.source_space)])

        # Specify that the package should be installed along with the rest of
        # the ROS distro.
        catkincmd.extend(['--install-space', self.rosdir])

        # All the arguments that follow are meant for CMake
        catkincmd.append('--cmake-args')

        # Make sure we're using the compilers included in this .snap
        catkincmd.extend([
            '-DCMAKE_C_FLAGS="$CFLAGS"',
            '-DCMAKE_CXX_FLAGS="$CPPFLAGS -I{} -I{}"'.format(
                os.path.join(self.installdir, 'usr', 'include', 'c++',
                             self.gcc_version),
                os.path.join(self.installdir, 'usr', 'include',
                             common.get_arch_triplet(), 'c++',
                             self.gcc_version)),
            '-DCMAKE_LD_FLAGS="$LDFLAGS"',
            '-DCMAKE_C_COMPILER={}'.format(
                os.path.join(self.installdir, 'usr', 'bin', 'gcc')),
            '-DCMAKE_CXX_COMPILER={}'.format(
                os.path.join(self.installdir, 'usr', 'bin', 'g++'))
        ])

        # This command must run in bash due to a bug in Catkin that causes it
        # to explode if there are spaces in the cmake args (which there are).
        # This has been fixed in Catkin Tools... perhaps we should be using
        # that instead.
        self._run_in_bash(catkincmd)
Example #15
0
 def runtime_env(self, root):
     env = []
     env.append('PATH="' + ':'.join([
         '{0}/bin',
         '{0}/usr/bin',
         '$PATH'
     ]).format(root) + '"')
     env.append('LD_LIBRARY_PATH="' + ':'.join([
         '{0}/lib',
         '{0}/usr/lib',
         '{0}/lib/{1}',
         '{0}/usr/lib/{1}',
         '$LD_LIBRARY_PATH'
     ]).format(root, common.get_arch_triplet()) + '"')
     return env
Example #16
0
def _build_env(root):
    """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 = []

    arch_triplet = common.get_arch_triplet()

    env.append('CFLAGS="' + ' '.join([
        '-I{0}/include',
        '-I{0}/usr/include',
        '-I{0}/include/{1}',
        '-I{0}/usr/include/{1}',
        '$CFLAGS'
    ]).format(root, arch_triplet) + '"')
    env.append('CPPFLAGS="' + ' '.join([
        '-I{0}/include',
        '-I{0}/usr/include',
        '-I{0}/include/{1}',
        '-I{0}/usr/include/{1}',
        '$CPPFLAGS'
    ]).format(root, arch_triplet) + '"')
    env.append('LDFLAGS="' + ' '.join([
        '-L{0}/lib',
        '-L{0}/usr/lib',
        '-L{0}/lib/{1}',
        '-L{0}/usr/lib/{1}',
        '$LDFLAGS'
    ]).format(root, arch_triplet) + '"')
    env.append('PKG_CONFIG_PATH=' + ':'.join([
        '{0}/lib/pkgconfig',
        '{0}/lib/{1}/pkgconfig',
        '{0}/usr/lib/pkgconfig',
        '{0}/usr/lib/{1}/pkgconfig',
        '{0}/usr/share/pkgconfig',
        '{0}/usr/local/lib/pkgconfig',
        '{0}/usr/local/lib/{1}/pkgconfig',
        '{0}/usr/local/share/pkgconfig',
        '$PKG_CONFIG_PATH'
    ]).format(root, arch_triplet))

    return env
Example #17
0
def _build_env(root):
    """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 = []

    arch_triplet = common.get_arch_triplet()

    env.append('CFLAGS="' + ' '.join([
        '-I{0}/include',
        '-I{0}/usr/include',
        '-I{0}/include/{1}',
        '-I{0}/usr/include/{1}',
        '$CFLAGS'
    ]).format(root, arch_triplet) + '"')
    env.append('CPPFLAGS="' + ' '.join([
        '-I{0}/include',
        '-I{0}/usr/include',
        '-I{0}/include/{1}',
        '-I{0}/usr/include/{1}',
        '$CPPFLAGS'
    ]).format(root, arch_triplet) + '"')
    env.append('LDFLAGS="' + ' '.join([
        '-L{0}/lib',
        '-L{0}/usr/lib',
        '-L{0}/lib/{1}',
        '-L{0}/usr/lib/{1}',
        '$LDFLAGS'
    ]).format(root, arch_triplet) + '"')
    env.append('PKG_CONFIG_PATH=' + ':'.join([
        '{0}/lib/pkgconfig',
        '{0}/lib/{1}/pkgconfig',
        '{0}/usr/lib/pkgconfig',
        '{0}/usr/lib/{1}/pkgconfig',
        '{0}/usr/share/pkgconfig',
        '{0}/usr/local/lib/pkgconfig',
        '{0}/usr/local/lib/{1}/pkgconfig',
        '{0}/usr/local/share/pkgconfig',
        '$PKG_CONFIG_PATH'
    ]).format(root, arch_triplet))

    return env
Example #18
0
    def runtime_env(self, root):
        env = []
        env.append('PATH="' + ":".join(["{0}/bin", "{0}/usr/bin", "$PATH"]).format(root) + '"')

        # Add the default LD_LIBRARY_PATH
        env.append(
            'LD_LIBRARY_PATH="'
            + ":".join(["{0}/lib", "{0}/usr/lib", "{0}/lib/{1}", "{0}/usr/lib/{1}", "$LD_LIBRARY_PATH"]).format(
                root, common.get_arch_triplet()
            )
            + '"'
        )

        # Add more specific LD_LIBRARY_PATH 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 #19
0
    def test_snap(self):
        project_dir = 'assemble'
        self.run_snapcraft('snap', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())

        binary1_wrapper_path = os.path.join(
            'snap', 'command-assemble-bin.wrapper')
        with open('binary1.after', 'r') as file_:
            binary1_after = file_.read()
        expected_binary1_wrapper = binary1_after.replace(
            '@MULTIARCH@', get_arch_triplet())
        self.assertThat(
            binary1_wrapper_path, FileContains(expected_binary1_wrapper))

        self.useFixture(
           fixtures.EnvironmentVariable(
                'SNAP', os.path.join(os.getcwd(), 'snap')))
        binary_scenarios = (
            ('command-assemble-service.wrapper', 'service-start\n'),
            ('stop-command-assemble-service.wrapper', 'service-stop\n'),
            ('command-assemble-bin.wrapper', 'binary1\n'),
            ('command-binary2.wrapper', 'binary2\n'),
        )
        for binary, expected_output in binary_scenarios:
            output = subprocess.check_output(
                os.path.join('snap', binary), universal_newlines=True)
            self.assertEqual(expected_output, output)

        with testtools.ExpectedException(subprocess.CalledProcessError):
            subprocess.check_output(
                os.path.join('snap', 'bin', 'not-wrapped'),
                stderr=subprocess.STDOUT)

        self.assertThat(
            os.path.join('snap', 'bin', 'not-wrapped.wrapper'),
            Not(FileExists()))
Example #20
0
    def test_snap(self):
        project_dir = 'assemble'
        self.run_snapcraft('snap', project_dir)
        os.chdir(project_dir)

        snap_file_path = 'assemble_1.0_{}.snap'.format(get_arch())
        self.assertThat(snap_file_path, FileExists())

        binary1_wrapper_path = os.path.join('snap',
                                            'command-assemble-bin.wrapper')
        with open('binary1.after', 'r') as file_:
            binary1_after = file_.read()
        expected_binary1_wrapper = binary1_after.replace(
            '@MULTIARCH@', get_arch_triplet())
        self.assertThat(binary1_wrapper_path,
                        FileContains(expected_binary1_wrapper))

        self.useFixture(
            fixtures.EnvironmentVariable('SNAP',
                                         os.path.join(os.getcwd(), 'snap')))
        binary_scenarios = (
            ('command-assemble-service.wrapper', 'service-start\n'),
            ('stop-command-assemble-service.wrapper', 'service-stop\n'),
            ('command-assemble-bin.wrapper', 'binary1\n'),
            ('command-binary2.wrapper', 'binary2\n'),
        )
        for binary, expected_output in binary_scenarios:
            output = subprocess.check_output(os.path.join('snap', binary),
                                             universal_newlines=True)
            self.assertEqual(expected_output, output)

        with testtools.ExpectedException(subprocess.CalledProcessError):
            subprocess.check_output(os.path.join('snap', 'bin', 'not-wrapped'),
                                    stderr=subprocess.STDOUT)

        self.assertThat(os.path.join('snap', 'bin', 'not-wrapped.wrapper'),
                        Not(FileExists()))
Example #21
0
 def test_get_arch_triplet(self):
     self.assertThat(common.get_arch_triplet(), Contains('linux-gnu'))
Example #22
0
 def test_get_arch_triplet(self):
     self.assertThat(common.get_arch_triplet(), Contains('linux-gnu'))