Browse files

store PATH and GHC_PACKAGE_PATH vars outside of activate script (they…

…'ll be needed by emacs mode)
  • Loading branch information...
1 parent 6a448b2 commit 5e09780c65931121fdbdb6b89b7fea2d6b8cba48 @Paczesiowa committed Jul 29, 2011
Showing with 48 additions and 13 deletions.
  1. +5 −6 skeletons/activate
  2. +30 −7 src/Actions.hs
  3. +13 −0 src/Process.hs
View
11 skeletons/activate
@@ -40,12 +40,11 @@ deactivate() {
fi
}
-if [ -e "<GHC_BIN_DIR>" ]; then
- export PATH="<VIRTHUALENV_BIN_DIR>:<CABAL_BIN_DIR>:<GHC_BIN_DIR>:${PATH}"
-else
- export PATH="<VIRTHUALENV_BIN_DIR>:<CABAL_BIN_DIR>:${PATH}"
-fi
-export GHC_PACKAGE_PATH="<GHC_PACKAGE_PATH>"
+PATH_PREPENDIX="$(cat <VIRTHUALENV_DIR>/path_var_prependix)"
+export PATH="${PATH_PREPENDIX}:${PATH}"
+unset -v PATH_PREPENDIX
+
+export GHC_PACKAGE_PATH="$(cat <VIRTHUALENV_DIR>/ghc_package_path_var)"
export PS1="(${VIRTHUALENV_NAME})${PS1}"
if [ -n "$BASH" -o -n "$ZSH_VERSION" ]; then
View
37 src/Actions.hs
@@ -13,6 +13,7 @@ import System.FilePath ((</>))
import Distribution.Version (Version (..))
import Distribution.Package (PackageName(..))
import Safe (lastMay)
+import Data.List (intercalate)
import MyMonad
import Types
@@ -50,23 +51,44 @@ installCabalWrapper = do
liftIO $ writeFile cabalWrapper cabalWrapperContents
liftIO $ makeExecutable cabalWrapper
+installActivateScriptSupportFiles :: MyMonad ()
+installActivateScriptSupportFiles = do
+ debug "installing supporting files"
+ dirStructure <- vheDirStructure
+ ghc <- asks ghcSource
+ indentMessages $ do
+ let pathVarPrependixLocation = virthualEnvDir dirStructure </> "path_var_prependix"
+ pathVarElems =
+ case ghc of
+ System -> [virthualEnvBinDir dirStructure, cabalBinDir dirStructure]
+ Tarball _ -> [ virthualEnvBinDir dirStructure
+ , cabalBinDir dirStructure
+ , ghcBinDir dirStructure
+ ]
+ pathVarPrependix = intercalate ":" pathVarElems
+ debug $ "installing path_var_prependix file to " ++ pathVarPrependixLocation
+ indentMessages $ trace $ "path_var_prependix contents: " ++ pathVarPrependix
+ liftIO $ writeFile pathVarPrependixLocation pathVarPrependix
+ ghcPkgDbPath <- indentMessages ghcPkgDbPathLocation
+ let ghcPackagePathVarLocation = virthualEnvDir dirStructure </> "ghc_package_path_var"
+ ghcPackagePathVar = ghcPkgDbPath
+ debug $ "installing ghc_package_path_var file to " ++ ghcPackagePathVarLocation
+ indentMessages $ trace $ "path_var_prependix contents: " ++ ghcPackagePathVar
+ liftIO $ writeFile ghcPackagePathVarLocation ghcPackagePathVar
+
-- install activate script (in bin/ directory) inside virtual environment dir structure
installActivateScript :: MyMonad ()
installActivateScript = do
info "Installing activate script"
virthualEnvName <- asks vheName
dirStructure <- vheDirStructure
- ghc <- asks ghcSource
- ghcPkgPath <- case ghc of
- System -> return $ ghcPackagePath dirStructure
- Tarball _ -> do
- externalGhcPkgDbPath <- indentMessages externalGhcPkgDb
- return $ ghcPackagePath dirStructure ++ ":" ++ externalGhcPkgDbPath
+ ghcPkgDbPath <- indentMessages ghcPkgDbPathLocation
let activateScript = virthualEnvBinDir dirStructure </> "activate"
indentMessages $ debug $ "using location: " ++ activateScript
let activateScriptContents = substs [ ("<VIRTHUALENV_NAME>", virthualEnvName)
+ , ("<VIRTHUALENV_DIR>", virthualEnvDir dirStructure)
, ("<VIRTHUALENV>", virthualEnv dirStructure)
- , ("<GHC_PACKAGE_PATH>", ghcPkgPath)
+ , ("<GHC_PACKAGE_PATH>", ghcPkgDbPath)
, ("<VIRTHUALENV_BIN_DIR>", virthualEnvBinDir dirStructure)
, ("<CABAL_BIN_DIR>", cabalBinDir dirStructure)
, ("<GHC_BIN_DIR>", ghcBinDir dirStructure)
@@ -75,6 +97,7 @@ installActivateScript = do
trace "activate script contents:"
indentMessages $ mapM_ trace $ lines activateScriptContents
liftIO $ writeFile activateScript activateScriptContents
+ indentMessages installActivateScriptSupportFiles
-- install cabal's config file (in cabal/ directory) inside virtual environment dir structure
installCabalConfig :: MyMonad ()
View
13 src/Process.hs
@@ -2,6 +2,7 @@ module Process ( externalGhcPkgDb
, outsideGhcPkg
, insideGhcPkg
, runProcess
+ , ghcPkgDbPathLocation
) where
import Types
@@ -93,3 +94,15 @@ insideGhcPkg args input = do
debug "Running ghc-pkg, installed from GHC's tarball, inside virtual environment"
return $ ghcDir dirStructure </> "bin" </> "ghc-pkg"
indentMessages $ runProcess (Just env) ghcPkg args input
+
+-- returns value of GHC_PACKAGE_PATH that should be used inside virtual environment
+ghcPkgDbPathLocation :: MyMonad String
+ghcPkgDbPathLocation = do
+ debug "Determining value of GHC_PACKAGE_PATH to be used inside virtual environment"
+ dirStructure <- vheDirStructure
+ ghc <- asks ghcSource
+ case ghc of
+ System -> return $ ghcPackagePath dirStructure
+ Tarball _ -> do
+ externalGhcPkgDbPath <- indentMessages externalGhcPkgDb
+ return $ ghcPackagePath dirStructure ++ ":" ++ externalGhcPkgDbPath

0 comments on commit 5e09780

Please sign in to comment.