Commit fd3e3889 authored by Alexis Williams's avatar Alexis Williams
Browse files

Add --env-cwd

parent 563d5017
...@@ -124,19 +124,21 @@ import Distribution.Utils.NubList ...@@ -124,19 +124,21 @@ import Distribution.Utils.NubList
( fromNubList ) ( fromNubList )
import System.Directory import System.Directory
( getHomeDirectory, doesFileExist, createDirectoryIfMissing ( getHomeDirectory, doesFileExist, createDirectoryIfMissing
, getTemporaryDirectory, makeAbsolute ) , getTemporaryDirectory, makeAbsolute, getCurrentDirectory )
import System.FilePath import System.FilePath
( (</>), takeDirectory ) ( (</>), takeDirectory )
data NewInstallFlags = NewInstallFlags data NewInstallFlags = NewInstallFlags
{ ninstInstallLibs :: Flag Bool { ninstInstallLibs :: Flag Bool
, ninstEnvironmentPath :: Flag FilePath , ninstEnvironmentPath :: Flag FilePath
, ninstEnvironmentCwd :: Flag Bool
} }
defaultNewInstallFlags :: NewInstallFlags defaultNewInstallFlags :: NewInstallFlags
defaultNewInstallFlags = NewInstallFlags defaultNewInstallFlags = NewInstallFlags
{ ninstInstallLibs = toFlag False { ninstInstallLibs = toFlag False
, ninstEnvironmentPath = mempty , ninstEnvironmentPath = mempty
, ninstEnvironmentCwd = toFlag False
} }
newInstallOptions :: ShowOrParseArgs -> [OptionField NewInstallFlags] newInstallOptions :: ShowOrParseArgs -> [OptionField NewInstallFlags]
...@@ -149,6 +151,10 @@ newInstallOptions _ = ...@@ -149,6 +151,10 @@ newInstallOptions _ =
"Set the environment file that may be modified." "Set the environment file that may be modified."
ninstEnvironmentPath (\pf flags -> flags { ninstEnvironmentPath = pf }) ninstEnvironmentPath (\pf flags -> flags { ninstEnvironmentPath = pf })
(reqArg "PATH" (succeedReadE Flag) flagToList) (reqArg "PATH" (succeedReadE Flag) flagToList)
, option [] ["env-cwd"]
"Modify the current directory's environment instead of the global one."
ninstEnvironmentCwd (\pf flags -> flags { ninstEnvironmentCwd = pf })
trueArg
] ]
installCommand :: CommandUI ( ConfigFlags, ConfigExFlags, InstallFlags installCommand :: CommandUI ( ConfigFlags, ConfigExFlags, InstallFlags
...@@ -405,10 +411,18 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, newInstal ...@@ -405,10 +411,18 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, newInstal
compilerId@(CompilerId compilerFlavor compilerVersion) }, platform, progDb') <- compilerId@(CompilerId compilerFlavor compilerVersion) }, platform, progDb') <-
configCompilerEx hcFlavor hcPath hcPkg progDb verbosity configCompilerEx hcFlavor hcPath hcPkg progDb verbosity
cwd <- getCurrentDirectory
let let
envFile = flip fromFlagOrDefault (ninstEnvironmentPath newInstallFlags) $ defaultEnv =
home </> ".ghc" </> ghcPlatformAndVersionString platform compilerVersion home </> ".ghc" </> ghcPlatformAndVersionString platform compilerVersion
</> "environments" </> "default" </> "environments" </> "default"
cwdEnv =
cwd </> ".ghc.environment." ++ ghcPlatformAndVersionString platform ghcversion
envFile = if fromFlagOrDefault False (ninstEnvironmentCwd newInstallFlags)
then cwdEnv
else fromFlagOrDefault defaultEnv (ninstEnvironmentPath newInstallFlags)
GhcImplInfo{ supportsPkgEnvFiles } = getImplInfo compiler GhcImplInfo{ supportsPkgEnvFiles } = getImplInfo compiler
-- Why? We know what the first part will be, we only care about the packages. -- Why? We know what the first part will be, we only care about the packages.
filterEnvEntries = filter $ \case filterEnvEntries = filter $ \case
......
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