Merge pull request #10647 from MercuryTechnologies/improve-tar-errors
[cabal.git] / cabal-testsuite / PackageTests / LinkerOptions / T7339 / setup.test.hs
blob233d3b20736ab7191a7926f4dc06835feedeec59
1 -- Test for #19350, #7339 originally by @bgamari
2 -- =============================================
3 --
4 -- The plan
5 -- ---------
6 -- We build a C shared library (`libhello`, contained in ./clib) and then build
7 -- a Haskell library (`T19350-lib`, in ./lib) which depends upon it via `foreign
8 -- import`. We make sure that the libhello shared object can only be found via
9 -- the extra-lib-dirs from the package database registration (which we do by
10 -- moving libhello.so from its original place).
12 -- Finally, we enter GHCi, load the Haskell library, and try to use it to call
13 -- into libhello.
15 import System.Directory
16 import Distribution.System
17 import Test.Cabal.Prelude
20 main = setupTest $ do
21 skipIfNoSharedLibraries
22 skipUnlessGhcVersion ">= 8.4"
24 withPackageDb $ do
25 cwd <- takeDirectory . testCurrentDir <$> getTestEnv
26 plat <- testPlatform <$> getTestEnv
27 let libExt = case plat of
28 Platform _ OSX -> "dylib"
29 Platform _ Windows -> "dll"
30 Platform _ _other -> "so"
33 -- Link a C program against the library
34 _ <- runProgramM ghcProgram
35 [ "-fPIC", "-c", "clib/lib.c"
36 , "-o", "clib/lib.o" ]
37 Nothing
38 _ <- runProgramM ghcProgram
39 [ "-shared", "-no-hs-main", "clib/lib.o"
40 , "-o", "clib/libhello" <.> libExt ]
41 Nothing
43 withDirectory "lib" $ do
44 setup "configure" ["-v0"
45 , "--extra-lib-dirs=" ++ (cwd </> "clib")
46 , "--extra-lib-dirs=" ++ (cwd </> "clib-install")
47 , "--disable-library-vanilla"
48 , "--enable-shared"]
49 setup "build" []
50 setup "register" ["--inplace"]
52 -- Move libhello from its original place to ensure it isn't found via RPATH
53 liftIO $ do
54 createDirectoryIfMissing False (cwd </> "clib-install")
55 copyFile (cwd </> "clib/libhello" <.> libExt) ( cwd </> "clib-install/libhello" <.> libExt)
56 removeFile (cwd </> "clib/libhello" <.> libExt)
58 pkgDb <- testPackageDbDir <$> getTestEnv
59 ghciScript <- liftIO $ readFile (cwd </> "T19350.script")
60 _ <- runProgramM ghcProgram
61 [ "--interactive"
62 , "-package", "T7339"
63 , "-package-db", pkgDb
64 ] (Just ghciScript)
66 return ()