Commit cc4dbe06 authored by Edward Z. Yang's avatar Edward Z. Yang

Port exec/T4049 to cabal-testsuite

Fixes bug where cabal exec with foreign libraries didn't
actually work on Windows (because it was selecting
the wrong library directory).
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 6c2d0a65
......@@ -29,7 +29,7 @@ import Distribution.Simple.Program.Run (programInvocation, runProgramInvocation)
import Distribution.Simple.Program.Types ( simpleProgram, ConfiguredProgram(..) )
import Distribution.Simple.Utils (die', warn)
import Distribution.System (Platform(..), OS(..))
import Distribution.System (Platform(..), OS(..), buildOS)
import Distribution.Verbosity (Verbosity)
import System.Directory ( doesDirectoryExist )
......@@ -99,6 +99,20 @@ sandboxEnvironment verbosity sandboxDir comp platform programDb iEnv =
exists <- doesDirectoryExist sandboxPackagePath
unless exists $ warn verbosity $ "Package database is not a directory: "
++ sandboxPackagePath
-- MASSIVE HACK. We need this to be synchronized with installLibDir
-- in defaultInstallDirs' in Distribution.Simple.InstallDirs,
-- which has a special case for Windows (WHY? Who knows; it's been
-- around as long as Windows exists.) The sane thing to do here
-- would be to read out the actual install dirs that were associated
-- with the package in question, but that's not a well-formed question
-- here because there is not actually install directory for the
-- "entire" sandbox. Since we want to kill this code in favor of
-- new-build, I decided it wasn't worth fixing this "properly."
-- Also, this doesn't handle LHC correctly but I don't care -- ezyang
let extraLibPath =
case buildOS of
Windows -> sandboxDir
_ -> sandboxDir </> "lib"
-- 2016-11-26 Apologies for the spaghetti code here.
-- Essentially we just want to add the sandbox's lib/ dir to
-- whatever the library search path environment variable is:
......@@ -115,7 +129,6 @@ sandboxEnvironment verbosity sandboxDir comp platform programDb iEnv =
-- want to avoid wiping the user's own settings, so we first
-- read the env var's current value, and then prefix ours if
-- the user had any set.
let extraLibPath = sandboxDir </> "lib"
iEnv' <-
if any ((==ldPath) . fst) iEnv
then return $ updateLdPath extraLibPath iEnv
......
......@@ -26,15 +26,6 @@ Extra-Source-Files:
-- Do NOT edit this section manually; instead, run the script.
-- BEGIN gen-extra-source-files
tests/IntegrationTests/common.sh
tests/IntegrationTests/exec/Foo.hs
tests/IntegrationTests/exec/My.hs
tests/IntegrationTests/exec/T4049.sh
tests/IntegrationTests/exec/T4049/UseLib.c
tests/IntegrationTests/exec/T4049/csrc/MyForeignLibWrapper.c
tests/IntegrationTests/exec/T4049/my-foreign-lib.cabal
tests/IntegrationTests/exec/T4049/src/MyForeignLib/Hello.hs
tests/IntegrationTests/exec/T4049/src/MyForeignLib/SomeBindings.hsc
tests/IntegrationTests/exec/my.cabal
tests/IntegrationTests2/build/keep-going/cabal.project
tests/IntegrationTests2/build/keep-going/p/P.hs
tests/IntegrationTests2/build/keep-going/p/p.cabal
......
. ./common.sh
require_ghc_ge 708
cd T4049
cabal sandbox init > /dev/null
cabal install --enable-shared > /dev/null
sh -c "$CCOMP UseLib.c -o UseLib -l myforeignlib -L \"$PWD/.cabal-sandbox/lib\" > /dev/null"
cabal exec "$PWD/UseLib"
# cabal sandbox init
Writing a default package environment file to <ROOT>/sandbox.dist/cabal.sandbox.config
Creating a new sandbox at <ROOT>/sandbox.dist/sandbox
# cabal install
Resolving dependencies...
Configuring my-foreign-lib-0.1.0.0...
Preprocessing foreign library 'myforeignlib' for my-foreign-lib-0.1.0.0..
Building foreign library 'myforeignlib' for my-foreign-lib-0.1.0.0..
Installing foreign library myforeignlib in <PATH>
Installed my-foreign-lib-0.1.0.0
# cabal exec
Hi from a foreign library! Foo has value 5678
import Test.Cabal.Prelude
main = cabalTest $ do
skipUnless =<< ghcVersionIs (>= mkVersion [7,8])
withSandbox $ do
cabal "install" ["--enable-shared"]
env <- getTestEnv
is_windows <- isWindows
let sandbox_dir = testSandboxDir env
work_dir = testWorkDir env
lib_dir =
-- This is dumb but it's been this way for a long time.
if is_windows
then sandbox_dir
else sandbox_dir </> "lib"
gcc [ "UseLib.c"
, "-o", work_dir </> "UseLib"
, "-l" ++ "myforeignlib"
, "-L" ++ lib_dir ]
recordMode RecordAll $
cabal "exec" ["-v0", work_dir </> "UseLib"]
......@@ -789,6 +789,22 @@ git' cmd args = do
recordHeader ["git", cmd]
runProgramM gitProgram (cmd : args)
gcc :: [String] -> TestM ()
gcc args = void $ gcc' args
gcc' :: [String] -> TestM Result
gcc' args = do
recordHeader ["gcc"]
runProgramM gccProgram args
ghc :: [String] -> TestM ()
ghc args = void $ ghc' args
ghc' :: [String] -> TestM Result
ghc' args = do
recordHeader ["ghc"]
runProgramM ghcProgram args
-- | If a test needs to modify or write out source files, it's
-- necessary to make a hermetic copy of the source files to operate
-- on. This function arranges for this to be done.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment