1111from bfg9000 .tools .cc import CcBuilder
1212from bfg9000 .packages import Framework
1313from bfg9000 .path import abspath , InstallRoot , Path , Root
14+ from bfg9000 .versioning import Version
1415
1516
1617class TestCcLinker (CrossPlatformTestCase ):
@@ -100,6 +101,8 @@ def test_flags_lib_dir(self):
100101 lib = self .Path ('/path/to/lib/libfoo.a' )
101102 srclibdir = self .Path ('.' , Root .srcdir )
102103 srclib = self .Path ('libfoo.a' , Root .srcdir )
104+ srcverlib = self .Path ('libfoo.so.1.2.3' , Root .srcdir )
105+ srcsoname = self .Path ('libfoo.so.1' , Root .srcdir )
103106
104107 if self .shared :
105108 output = SharedLibrary (self .Path ('out' ), 'native' )
@@ -134,6 +137,12 @@ def test_flags_lib_dir(self):
134137 opts .lib (SharedLibrary (srclib , 'native' ))
135138 ), output = output ), ['-L' + srclibdir ] + srcdir_rpath + soname )
136139
140+ # Versioned library
141+ self .assertEqual (self .linker .flags (opts .option_list (
142+ opts .lib (VersionedSharedLibrary (srcverlib , 'native' , 'c' ,
143+ srcsoname , srclib ))
144+ ), output = output ), ['-L' + srclibdir ] + srcdir_rpath + soname )
145+
137146 if self .env .target_platform .genus == 'linux' :
138147 libdir2 = self .Path ('foo' )
139148 lib2 = self .Path ('foo/libbar.a' )
@@ -149,6 +158,22 @@ def test_flags_lib_dir(self):
149158 ['-L' + libdir2 , '-Wl,-rpath,$ORIGIN/foo' ] + soname
150159 )
151160
161+ # Make sure we handle rpath-link for broken BFD-based ld. See
162+ # `bfg9000/tools/cc/linker.py`
163+ class BrokenBfdLinker :
164+ brand = 'bfd'
165+ version = Version ('2.27' )
166+ with mock .patch ('bfg9000.tools.cc.CcBuilder.linker' ,
167+ return_value = BrokenBfdLinker ()):
168+ s = SharedLibrary (srclib , 'native' )
169+ s .runtime_deps = [SharedLibrary (lib2 , 'native' )]
170+ self .assertEqual (
171+ self .linker .flags (opts .option_list (opts .lib (s )),
172+ output = output ),
173+ (['-L' + srclibdir ] + srcdir_rpath +
174+ ['-Wl,-rpath-link,' + libdir2 ] + soname )
175+ )
176+
152177 # Static library
153178 self .assertEqual (self .linker .flags (opts .option_list (
154179 opts .lib (StaticLibrary (lib , 'native' ))
0 commit comments