예제 #1
0
    def test_flags_lib_dir(self):
        libdir = self.Path('/path/to/lib')
        lib = self.Path('/path/to/lib/foo.so')

        # Lib dir
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib_dir(
                Directory(libdir)))), ['/LIBPATH:' + libdir])
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib_dir(
                Directory(libdir))),
                              mode='pkg-config'), ['-L' + libdir])

        # Shared library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(SharedLibrary(lib, 'native')))), [])

        # Static library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(StaticLibrary(lib, 'native')))), [])

        # Mixed
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(Directory(libdir)),
                                 opts.lib(SharedLibrary(lib, 'native')))),
            ['/LIBPATH:' + libdir])
예제 #2
0
    def test_lib_flags_lib(self):
        lib = self.Path('/path/to/lib/foo.lib')

        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(opts.lib(SharedLibrary(lib, 'native')))),
            [lib])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(
                opts.lib(SharedLibrary(lib, 'native'))),
                                  mode='pkg-config'), ['-lfoo'])

        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(
                    opts.lib(WholeArchive(SharedLibrary(lib, 'native'))))),
            ['/WHOLEARCHIVE:' + lib])

        version = ('Microsoft (R) C/C++ Optimizing Compiler Version ' +
                   '18.00.25831 for x86')
        with mock.patch('bfg9000.shell.which', mock_which):
            linker = MsvcBuilder(self.env, known_langs['c++'], ['cl'],
                                 version).linker('executable')
        with self.assertRaises(TypeError):
            linker.lib_flags(
                opts.option_list(
                    opts.lib(WholeArchive(StaticLibrary(lib, 'native')))))

        with self.assertRaises(TypeError):
            self.linker.lib_flags(
                opts.option_list(opts.lib(Framework('cocoa'))))
예제 #3
0
    def test_flags_lib(self):
        lib1 = self.Path('/path/to/lib/libfoo.jar')
        lib2 = self.Path('/path/to/lib/libbar.jar')

        self.assertEqual(self.compiler.flags(opts.option_list(
            opts.lib(file_types.StaticLibrary(lib1, 'jvm'))
        )), ['-cp', lib1])
        self.assertEqual(self.compiler.flags(opts.option_list(
            opts.lib(file_types.StaticLibrary(lib1, 'jvm')),
            opts.lib(file_types.StaticLibrary(lib2, 'jvm'))
        )), ['-cp', lib1 + os.pathsep + lib2])
예제 #4
0
    def test_post_installed_macos(self):
        output = self._get_output_file()
        installed = installify(output).path
        deplib = SharedLibrary(self.Path('libfoo.so'), 'native')

        install_outputs = MockInstallOutputs(self.env)
        with mock.patch('bfg9000.shell.which', return_value=['command']):
            install_name_tool = self.env.tool('install_name_tool')

            # No runtime deps
            fn = self.linker.post_install(opts.option_list(), output, None)
            self.assertEqual(fn(install_outputs), [
                install_name_tool, '-id', installed.cross(self.env), installed
            ] if self.shared else None)

            fn = self.linker.post_install(opts.option_list(
                opts.install_name_change('old.dylib', 'new.dylib')
            ), output, None)
            self.assertEqual(fn(install_outputs), (
                [install_name_tool] +
                (['-id', installed.cross(self.env)] if self.shared else []) +
                ['-change', 'old.dylib', 'new.dylib', installed]
            ))

            # Dependent on local shared lib
            output.runtime_deps = [deplib]
            fn = self.linker.post_install(
                opts.option_list(opts.lib(deplib)), output, None
            )
            self.assertEqual(fn(install_outputs), (
                [install_name_tool] +
                (['-id', installed.cross(self.env)] if self.shared else []) +
                ['-change', deplib.path.string(self.env.base_dirs),
                 installify(deplib, cross=self.env).path, installed]
            ))
예제 #5
0
 def test_framework_suffix(self):
     env = make_env('macos')
     self.assertEqual(
         packages.framework(env, 'name', 'suffix'),
         CommonPackage('name,suffix',
                       env.target_platform.object_format,
                       link_options=opts.option_list(
                           opts.lib(Framework('name', 'suffix')))))
예제 #6
0
    def test_framework_suffix(self):
        env = make_env('macos')
        context = self._make_context(env)

        self.assertEqual(
            context['framework']('name', 'suffix'),
            CommonPackage('name,suffix',
                          env.target_platform.object_format,
                          link_options=opts.option_list(
                              opts.lib(Framework('name', 'suffix')))))
예제 #7
0
    def test_lib_order(self):
        fmt = self.env.target_platform.object_format
        lib = opts.lib(
            file_types.SharedLibrary(Path('libfoo', Root.srcdir), fmt))
        pkg_libdir = opts.lib_dir(
            file_types.Directory(Path('/usr/lib', Root.absolute)))
        pkg = CommonPackage('pkg', fmt, None, opts.option_list(pkg_libdir))

        result = self.context['shared_library']('shared', ['main.cpp'],
                                                libs='libfoo',
                                                packages=pkg)
        self.assertEqual(result.creator.options,
                         opts.option_list(lib, pkg_libdir))
예제 #8
0
    def test_post_installed_linux(self):
        output = self._get_output_file()
        shared = SharedLibrary(self.Path('libfoo.so'), 'native')
        shared_abs = SharedLibrary(self.Path('/path/to/libfoo.so'), 'native')
        static = StaticLibrary(self.Path('libfoo.a'), 'native')

        install_outputs = MockInstallOutputs(self.env)
        with mock.patch('bfg9000.shell.which', return_value=['command']):
            # Local shared lib
            fn = self.linker.post_install(opts.option_list(opts.lib(shared)),
                                          output, None)
            self.assertEqual(fn(install_outputs), [
                self.env.tool('patchelf'), '--set-rpath',
                self.Path('', InstallRoot.libdir),
                installify(output).path
            ])

            # Absolute shared lib
            fn = self.linker.post_install(
                opts.option_list(opts.lib(shared_abs)), output, None)
            self.assertEqual(fn(install_outputs), None)

            # Local static lib
            fn = self.linker.post_install(opts.option_list(opts.lib(static)),
                                          output, None)
            self.assertEqual(fn(install_outputs), None)

            # Explicit rpath dir
            fn = self.linker.post_install(
                opts.option_list(opts.rpath_dir(self.Path('/path'))), output,
                None)
            self.assertEqual(fn(install_outputs), None)

            # Mixed
            fn = self.linker.post_install(
                opts.option_list(opts.lib(shared), opts.lib(shared_abs),
                                 opts.lib(static),
                                 opts.rpath_dir(self.Path('/path')),
                                 opts.rpath_dir(self.Path('/path/to'))),
                output, None)
            self.assertEqual(fn(install_outputs), [
                self.env.tool('patchelf'), '--set-rpath',
                (self.Path('', InstallRoot.libdir) + ':' +
                 self.Path('/path/to') + ':' + self.Path('/path')),
                installify(output).path
            ])
예제 #9
0
    def test_installed_rpaths(self):
        output = Executable(self.Path('program'), 'native')

        # Local shared lib
        rpaths = self.linker._installed_rpaths(
            opts.option_list(
                opts.lib(SharedLibrary(self.Path('libfoo.so'), 'native'))),
            output)
        self.assertEqual(rpaths, [self.Path('', InstallRoot.libdir)])

        # Absolute shared lib
        rpaths = self.linker._installed_rpaths(
            opts.option_list(
                opts.lib(
                    SharedLibrary(self.Path('/path/to/libfoo.so'), 'native'))),
            output)
        self.assertEqual(rpaths, [])

        # Local static lib
        rpaths = self.linker._installed_rpaths(
            opts.option_list(
                opts.lib(StaticLibrary(self.Path('libfoo.a'), 'native'))),
            output)
        self.assertEqual(rpaths, [])

        # Explicit rpath dir
        rpaths = self.linker._installed_rpaths(
            opts.option_list(opts.rpath_dir(self.Path('/path'))), output)
        self.assertEqual(rpaths, [])

        # Mixed
        rpaths = self.linker._installed_rpaths(
            opts.option_list(
                opts.lib(SharedLibrary(self.Path('libfoo.so'), 'native')),
                opts.lib(
                    SharedLibrary(self.Path('/path/to/libfoo.so'), 'native')),
                opts.lib(StaticLibrary(self.Path('libfoo.a'), 'native')),
                opts.rpath_dir(self.Path('/path')),
                opts.rpath_dir(self.Path('/path/to'))), output)
        self.assertEqual(rpaths, [
            self.Path('', InstallRoot.libdir),
            self.Path('/path/to'),
            self.Path('/path')
        ])
예제 #10
0
    def test_lib_flags_lib(self):
        lib = self.Path('/path/to/lib/libfoo.a')

        # Shared library
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(opts.lib(SharedLibrary(lib, 'native')))),
            ['-lfoo'])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(
                opts.lib(SharedLibrary(lib, 'native'))),
                                  mode='pkg-config'), ['-lfoo'])

        # Shared library with creator
        x = SharedLibrary(lib, 'native')
        x.creator = 'test'
        self.assertEqual(self.linker.lib_flags(opts.option_list(opts.lib(x))),
                         [lib])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(opts.lib(x)),
                                  mode='pkg-config'), ['-lfoo'])

        # Static library
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(opts.lib(StaticLibrary(lib, 'native')))),
            [lib])
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(
                opts.lib(StaticLibrary(lib, 'native'))),
                                  mode='pkg-config'), ['-lfoo'])

        # Whole archive
        flags = self.linker.lib_flags(
            opts.option_list(
                opts.lib(WholeArchive(StaticLibrary(lib, 'native')))))
        if self.env.target_platform.genus == 'darwin':
            self.assertEqual(flags, ['-Wl,-force_load', lib])
        else:
            self.assertEqual(
                flags, ['-Wl,--whole-archive', lib, '-Wl,--no-whole-archive'])

        # Generic library
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(opts.lib(Library(lib, 'native')))), ['-lfoo'])

        mingw_lib = self.Path('/path/to/lib/foo.lib')
        self.assertEqual(
            self.linker.lib_flags(
                opts.option_list(opts.lib(Library(mingw_lib, 'native')))),
            [mingw_lib])
        with self.assertRaises(ValueError):
            self.linker.lib_flags(opts.option_list(
                opts.lib(Library(mingw_lib, 'native'))),
                                  mode='pkg-config')

        # Framework
        fw = opts.lib(Framework('cocoa'))
        if self.env.target_platform.genus == 'darwin':
            self.assertEqual(self.linker.lib_flags(opts.option_list(fw)),
                             ['-framework', 'cocoa'])
        else:
            with self.assertRaises(TypeError):
                self.linker.lib_flags(opts.option_list(fw))

        # String
        self.assertEqual(
            self.linker.lib_flags(opts.option_list(opts.lib('foo'))),
            ['-lfoo'])
예제 #11
0
    def test_flags_lib_dir(self):
        libdir = self.Path('/path/to/lib')
        lib = self.Path('/path/to/lib/libfoo.a')
        srclibdir = self.Path('.', Root.srcdir)
        srclib = self.Path('libfoo.a', Root.srcdir)

        if self.shared:
            output = SharedLibrary(self.Path('out'), 'native')
            if self.env.target_platform.genus == 'darwin':
                soname = [
                    '-install_name',
                    self.Path('out').string(self.env.base_dirs)
                ]
            else:
                soname = ['-Wl,-soname,out']
        else:
            output = Executable(self.Path('exe'), 'native')
            soname = []

        if self.env.target_platform.genus == 'linux':
            rpath = ['-Wl,-rpath,' + libdir]
            srcdir_rpath = ['-Wl,-rpath,' + srclibdir]
        else:
            rpath = srcdir_rpath = []

        # Lib dir
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib_dir(
                Directory(libdir)))), ['-L' + libdir])

        # Shared library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath + soname)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(SharedLibrary(srclib, 'native'))),
                output), ['-L' + srclibdir] + srcdir_rpath + soname)

        if self.env.target_platform.genus == 'linux':
            libdir2 = self.Path('foo')
            lib2 = self.Path('foo/libbar.a')

            with self.assertRaises(ValueError):
                self.linker.flags(
                    opts.option_list(opts.lib(SharedLibrary(lib2, 'native'))))
            self.assertEqual(
                self.linker.flags(
                    opts.option_list(opts.lib(SharedLibrary(lib2, 'native'))),
                    output),
                ['-L' + libdir2, '-Wl,-rpath,$ORIGIN/foo'] + soname)

        # Static library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(StaticLibrary(lib, 'native')))), [])
        self.assertEqual(
            self.linker.flags(opts.option_list(
                opts.lib(StaticLibrary(lib, 'native'))),
                              mode='pkg-config'), ['-L' + libdir])

        # Generic library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(Library(lib, 'native')))),
            ['-L' + libdir])

        mingw_lib = self.Path('/path/to/lib/foo.lib')
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(Library(mingw_lib, 'native')))), [])
        with self.assertRaises(ValueError):
            self.linker.flags(opts.option_list(
                opts.lib(Library(mingw_lib, 'native'))),
                              mode='pkg-config')

        # Framework
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib(Framework('cocoa')))),
            [])

        # Mixed
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(Directory(libdir)),
                                 opts.lib(SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(Directory(libdir)),
                                 opts.lib(SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath + soname)
예제 #12
0
    def test_flags_lib_dir(self):
        libdir = Path('/path/to/lib')
        lib = Path('/path/to/lib/libfoo.a')
        output = file_types.Executable(Path('exe'), 'native')

        if self.env.target_platform.name == 'linux':
            rpath = rpath_with_output = ['-Wl,-rpath,' + libdir]
        elif self.env.target_platform.name == 'darwin':
            rpath = []
            rpath_with_output = [jbos('-Wl,-rpath,', '@loader_path')]
        else:
            rpath = rpath_with_output = []

        # Lib dir
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib_dir(file_types.Directory(libdir)))),
            ['-L' + libdir])

        # Shared library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath_with_output)

        if self.env.target_platform.name == 'linux':
            libdir2 = Path('foo')
            lib2 = Path('foo/libbar.a')

            with self.assertRaises(ValueError):
                self.linker.flags(
                    opts.option_list(
                        opts.lib(file_types.SharedLibrary(lib2, 'native'))))
            self.assertEqual(
                self.linker.flags(
                    opts.option_list(
                        opts.lib(file_types.SharedLibrary(lib2, 'native'))),
                    output),
                ['-L' + libdir2,
                 jbos('-Wl,-rpath,', '$ORIGIN/foo')])

        # Static library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.StaticLibrary(lib, 'native')))), [])
        self.assertEqual(
            self.linker.flags(opts.option_list(
                opts.lib(file_types.StaticLibrary(lib, 'native'))),
                              mode='pkg-config'), ['-L' + libdir])

        # Generic library
        self.assertEqual(
            self.linker.flags(
                opts.option_list(opts.lib(file_types.Library(lib, 'native')))),
            ['-L' + libdir])

        mingw_lib = Path('/path/to/lib/foo.lib')
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib(file_types.Library(mingw_lib, 'native')))), [])
        with self.assertRaises(ValueError):
            self.linker.flags(opts.option_list(
                opts.lib(file_types.Library(mingw_lib, 'native'))),
                              mode='pkg-config')

        # Framework
        self.assertEqual(
            self.linker.flags(opts.option_list(opts.lib(Framework('cocoa')))),
            [])

        # Mixed
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native')))),
            ['-L' + libdir] + rpath)
        self.assertEqual(
            self.linker.flags(
                opts.option_list(
                    opts.lib_dir(file_types.Directory(libdir)),
                    opts.lib(file_types.SharedLibrary(lib, 'native'))),
                output), ['-L' + libdir] + rpath_with_output)