From cd7b5a686a5bbc3ded21ca019f759a32a1a3c9c5 Mon Sep 17 00:00:00 2001 From: Auke Booij <auke@tulcod.com> Date: Sun, 30 Oct 2016 19:30:12 +0000 Subject: [PATCH] Add sandbox lib dir to environment during cabal exec --- cabal-install/Distribution/Client/Exec.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cabal-install/Distribution/Client/Exec.hs b/cabal-install/Distribution/Client/Exec.hs index 4020056da4..d0cf66a7cf 100644 --- a/cabal-install/Distribution/Client/Exec.hs +++ b/cabal-install/Distribution/Client/Exec.hs @@ -29,10 +29,11 @@ import Distribution.Simple.Program.Run (programInvocation, runProgramInvocation) import Distribution.Simple.Program.Types ( simpleProgram, ConfiguredProgram(..) ) import Distribution.Simple.Utils (die, warn) -import Distribution.System (Platform) +import Distribution.System (Platform(..), OS(..)) import Distribution.Verbosity (Verbosity) import System.Directory ( doesDirectoryExist ) +import System.Environment (lookupEnv) import System.FilePath (searchPathSeparator, (</>)) @@ -81,6 +82,7 @@ sandboxEnvironment verbosity sandboxDir comp platform programDb = GHCJS -> env GHCJS.getGlobalPackageDB ghcjsProgram "GHCJS_PACKAGE_PATH" _ -> die "exec only works with GHC and GHCJS" where + (Platform _ os) = platform env getGlobalPackageDB hcProgram packagePathEnvVar = do let Just program = lookupProgram hcProgram programDb gDb <- getGlobalPackageDB verbosity program @@ -92,10 +94,18 @@ sandboxEnvironment verbosity sandboxDir comp platform programDb = exists <- doesDirectoryExist sandboxPackagePath unless exists $ warn verbosity $ "Package database is not a directory: " ++ sandboxPackagePath + let ldPath = case os of + OSX -> "DYLD_LIBRARY_PATH" + _ -> "LD_LIBRARY_PATH" + currentLibraryPath <- lookupEnv ldPath + let newLibraryPath = case currentLibraryPath of + Nothing -> sandboxDir </> "lib" + Just paths -> sandboxDir </> "lib" ++ searchPathSeparator:paths -- Build the environment return [ (packagePathEnvVar, Just compilerPackagePaths) , ("CABAL_SANDBOX_PACKAGE_PATH", Just compilerPackagePaths) , ("CABAL_SANDBOX_CONFIG", Just sandboxConfigFilePath) + , (ldPath, Just newLibraryPath) ] prependToSearchPath path newValue = -- GitLab