1 {-# LANGUAGE RecordWildCards #-}
4 import Control
.Exception
5 import Control
.Monad
.IO.Class
6 import System
.Environment
9 #ifndef mingw32_HOST_OS
10 import System
.Posix
(readSymbolicLink
)
11 #endif
/* mingw32_HOST_OS
*/
13 import Distribution
.Simple
.LocalBuildInfo
14 import Distribution
.Simple
.Program
.Db
15 import Distribution
.Simple
.Program
.Builtin
16 import Distribution
.Simple
.Program
.Types
17 import Distribution
.System
18 import Distribution
.Verbosity
19 import Distribution
.Version
21 import Test
.Cabal
.Prelude
23 -- Test that foreign libraries work
24 -- Recording is turned off because versionedlib will or will not
25 -- be installed depending on if we're on Linux or not.
26 main
= setupAndCabalTest
. recordMode DoNotRecord
$ do
27 -- Foreign libraries don't work with GHC 7.6 and earlier
28 skipUnlessGhcVersion
">= 7.8"
30 ghc80
<- isGhcVersion
"== 8.0.2"
31 expectBrokenIf
(osx
&& ghc80
) 7989 $
34 setup
"copy" [] -- regression test #4156
35 dist_dir
<- fmap testDistDir getTestEnv
36 lbi
<- getLocalBuildInfoM
37 let installDirs
= absoluteInstallDirs
(localPkgDescr lbi
) lbi NoCopyDest
39 -- Link a C program against the library
40 _
<- runProgramM gccProgram
44 , "-l", "myforeignlib"
45 , "-L", flibdir installDirs
]
49 let ldPath
= case hostPlatform lbi
of
50 Platform _ OSX
-> "DYLD_LIBRARY_PATH"
51 Platform _ Windows
-> "PATH"
52 Platform _ _other
-> "LD_LIBRARY_PATH"
53 oldLdPath
<- liftIO
$ getEnv' ldPath
54 withEnv
[ (ldPath
, Just
$ flibdir installDirs
++ [searchPathSeparator
] ++ oldLdPath
) ] $ do
55 cwd
<- fmap testCurrentDir getTestEnv
56 result
<- runM
(cwd
</> "uselib") [] Nothing
57 assertOutputContains
"5678" result
58 assertOutputContains
"189" result
60 -- If we're on Linux, we should have built a library with a
61 -- version. We will now check that it was installed correctly.
62 #ifndef mingw32_HOST_OS
63 case hostPlatform lbi
of
64 Platform _ Linux
-> do
65 let libraryName
= "libversionedlib.so.5.4.3"
66 libdir
= flibdir installDirs
67 objdumpProgram
= simpleProgram
"objdump"
68 (objdump
, _
) <- liftIO
$ requireProgram normal objdumpProgram
(withPrograms lbi
)
69 path1
<- liftIO
$ readSymbolicLink
$ libdir
</> "libversionedlib.so"
70 path2
<- liftIO
$ readSymbolicLink
$ libdir
</> "libversionedlib.so.5"
71 assertEqual
"Symbolic link 'libversionedlib.so' incorrect"
73 assertEqual
"Symbolic link 'libversionedlib.so.5' incorrect"
75 objInfo
<- runM
(programPath objdump
) [
77 , libdir
</> libraryName
79 assertBool
"SONAME of 'libversionedlib.so.5.4.3' incorrect" $
80 elem "libversionedlib.so.5" $ words $ resultOutput objInfo
82 #endif
/* mingw32_HOST_OS
*/
84 getEnv' :: String -> IO String
85 getEnv' = handle handler
. getEnv
87 handler e
= if isDoesNotExistError e