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
20 import System
.Directory
22 import Test
.Cabal
.Prelude
24 -- Test that foreign libraries work
25 -- Recording is turned off because versionedlib will or will not
26 -- be installed depending on if we're on Linux or not.
27 main
= setupAndCabalTest
. recordMode DoNotRecord
$ do
28 -- Foreign libraries don't work with GHC 7.6 and earlier
29 skipUnlessGhcVersion
">= 7.8"
31 ghc94
<- isGhcVersion
">= 9.4.1"
32 expectBrokenIf
(win
&& ghc94
) 8451 $
35 setup
"copy" [] -- regression test #4156
36 dist_dir
<- fmap testDistDir getTestEnv
37 lbi
<- getLocalBuildInfoM
38 let installDirs
= absoluteInstallDirs
(localPkgDescr lbi
) lbi NoCopyDest
40 -- Link a C program against the library
41 _
<- runProgramM gccProgram
45 , "-l", "myforeignlib"
46 , "-L", flibdir installDirs
]
50 let ldPath
= case hostPlatform lbi
of
51 Platform _ OSX
-> "DYLD_LIBRARY_PATH"
52 Platform _ Windows
-> "PATH"
53 Platform _ _other
-> "LD_LIBRARY_PATH"
54 oldLdPath
<- liftIO
$ getEnv' ldPath
55 withEnv
[ (ldPath
, Just
$ flibdir installDirs
++ [searchPathSeparator
] ++ oldLdPath
) ] $ do
56 cwd
<- fmap testCurrentDir getTestEnv
57 result
<- runM
(cwd
</> "uselib") [] Nothing
58 assertOutputContains
"5678" result
59 assertOutputContains
"189" result
61 -- If we're on Linux, we should have built a library with a
62 -- version. We will now check that it was installed correctly.
63 #ifndef mingw32_HOST_OS
64 case hostPlatform lbi
of
65 Platform _ Linux
-> do
66 let libraryName
= "libversionedlib.so.5.4.3"
67 libdir
= flibdir installDirs
68 objdumpProgram
= simpleProgram
"objdump"
69 (objdump
, _
) <- liftIO
$ requireProgram normal objdumpProgram
(withPrograms lbi
)
70 path1
<- liftIO
$ readSymbolicLink
$ libdir
</> "libversionedlib.so"
71 path2
<- liftIO
$ readSymbolicLink
$ libdir
</> "libversionedlib.so.5"
72 assertEqual
"Symbolic link 'libversionedlib.so' incorrect"
74 assertEqual
"Symbolic link 'libversionedlib.so.5' incorrect"
76 objInfo
<- runM
(programPath objdump
) [
78 , libdir
</> libraryName
80 assertBool
"SONAME of 'libversionedlib.so.5.4.3' incorrect" $
81 elem "libversionedlib.so.5" $ words $ resultOutput objInfo
83 #endif
/* mingw32_HOST_OS
*/
85 getEnv' :: String -> IO String
86 getEnv' = handle handler
. getEnv
88 handler e
= if isDoesNotExistError e