summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver/Session.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC/Driver/Session.hs')
-rw-r--r--compiler/GHC/Driver/Session.hs63
1 files changed, 15 insertions, 48 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index f75a5e0d92..33bc1630e1 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -220,7 +220,6 @@ import GHC.Platform
import GHC.Platform.Ways
import GHC.Platform.Profile
-import GHC.UniqueSubdir (uniqueSubdir)
import GHC.Unit.Types
import GHC.Unit.Parser
import GHC.Unit.Module
@@ -285,6 +284,9 @@ import qualified GHC.Data.EnumSet as EnumSet
import GHC.Foreign (withCString, peekCString)
import qualified GHC.LanguageExtensions as LangExt
+import qualified GHC.EnvironmentFiles as E
+import GHC.AppDir
+
-- Note [Updating flag description in the User's Guide]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
@@ -887,32 +889,7 @@ opt_lc dflags= toolSettings_opt_lc $ toolSettings dflags
opt_i :: DynFlags -> [String]
opt_i dflags= toolSettings_opt_i $ toolSettings dflags
--- | The directory for this version of ghc in the user's app directory
--- The appdir used to be in ~/.ghc but to respect the XDG specification
--- we want to move it under $XDG_DATA_HOME/
--- However, old tooling (like cabal) might still write package environments
--- to the old directory, so we prefer that if a subdirectory of ~/.ghc
--- with the correct target and GHC version suffix exists.
---
--- i.e. if ~/.ghc/$UNIQUE_SUBDIR exists we use that
--- otherwise we use $XDG_DATA_HOME/$UNIQUE_SUBDIR
---
--- UNIQUE_SUBDIR is typically a combination of the target platform and GHC version
-versionedAppDir :: String -> ArchOS -> MaybeT IO FilePath
-versionedAppDir appname platform = do
- -- Make sure we handle the case the HOME isn't set (see #11678)
- -- We need to fallback to the old scheme if the subdirectory exists.
- msum $ map (checkIfExists <=< fmap (</> versionedFilePath platform))
- [ tryMaybeT $ getAppUserDataDirectory appname -- this is ~/.ghc/
- , tryMaybeT $ getXdgDirectory XdgData appname -- this is $XDG_DATA_HOME/
- ]
- where
- checkIfExists dir = tryMaybeT (doesDirectoryExist dir) >>= \case
- True -> pure dir
- False -> MaybeT (pure Nothing)
-versionedFilePath :: ArchOS -> FilePath
-versionedFilePath platform = uniqueSubdir platform
-- | The 'GhcMode' tells us whether we're doing multi-module
-- compilation (controlled via the "GHC" API) or one-shot
@@ -4422,31 +4399,21 @@ addLdInputs p dflags = dflags{ldInputs = ldInputs dflags ++ [p]}
-- -----------------------------------------------------------------------------
-- Load dynflags from environment files.
-setFlagsFromEnvFile :: FilePath -> String -> DynP ()
-setFlagsFromEnvFile envfile content = do
+setFlagsFromEnvFile :: E.PackageEnvironment -> DynP ()
+setFlagsFromEnvFile (E.PackageEnvironment envfile) = do
setGeneralFlag Opt_HideAllPackages
- parseEnvFile envfile content
+ mapM_ run_package_env envfile
-parseEnvFile :: FilePath -> String -> DynP ()
-parseEnvFile envfile = mapM_ parseEntry . lines
where
- parseEntry str = case words str of
- ("package-db": _) -> addPkgDbRef (PkgDbPath (envdir </> db))
- -- relative package dbs are interpreted relative to the env file
- where envdir = takeDirectory envfile
- db = drop 11 str
- ["clear-package-db"] -> clearPkgDb
- ["hide-package", pkg] -> hidePackage pkg
- ["global-package-db"] -> addPkgDbRef GlobalPkgDb
- ["user-package-db"] -> addPkgDbRef UserPkgDb
- ["package-id", pkgid] -> exposePackageId pkgid
- (('-':'-':_):_) -> return () -- comments
- -- and the original syntax introduced in 7.10:
- [pkgid] -> exposePackageId pkgid
- [] -> return ()
- _ -> throwGhcException $ CmdLineError $
- "Can't parse environment file entry: "
- ++ envfile ++ ": " ++ str
+ run_package_env cmd =
+ case cmd of
+ E.ClearPackageDb -> clearPkgDb
+ E.PackageDb db -> addPkgDbRef (PkgDbPath db)
+ E.PackageId pkg -> exposePackageId pkg
+ E.HidePackage pkg -> hidePackage pkg
+ E.GlobalPackageDb -> addPkgDbRef GlobalPkgDb
+ E.UserPackageDb -> addPkgDbRef UserPkgDb
+
-----------------------------------------------------------------------------