diff options
author | Zubin Duggal <zubin.duggal@gmail.com> | 2021-11-17 19:24:41 +0530 |
---|---|---|
committer | Zubin Duggal <zubin.duggal@gmail.com> | 2022-01-31 16:51:55 +0530 |
commit | ee5c4f9d05fab41f53364dc18d30932034e6ada6 (patch) | |
tree | 78cbe08a9d4654eb3e5ebe2dd17b3c1cced1df51 /compiler | |
parent | 3531c4784c0a06063dcfc0f084943d5149e64035 (diff) | |
download | haskell-ee5c4f9d05fab41f53364dc18d30932034e6ada6.tar.gz |
Improve migration strategy for the XDG compliance change to the GHC application
directory.
We want to always use the old path (~/.ghc/..) if it exists.
But we never want to create the old path.
This ensures that the migration can eventually be completed once older GHC
versions are no longer in circulation.
Fixes #20684, #20669, #20660
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 2e7574837f..b17b0c8d3d 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE LambdaCase #-} ------------------------------------------------------------------------------- -- @@ -887,13 +888,28 @@ 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 --- (typically something like @~/.ghc/x86_64-linux-7.6.3@) +-- 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) - appdir <- tryMaybeT $ getXdgDirectory XdgData appname - return $ appdir </> versionedFilePath platform + -- 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 |