diff options
author | Gauvain 'GovanifY' Roussel-Tarbouriech <gauvain@govanify.com> | 2020-12-05 23:02:44 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-02-18 13:46:19 -0500 |
commit | 763d28551de32377a1dca8bdde02979e3686f400 (patch) | |
tree | b96de6da511d3fc2f7b29260d8250afb787df758 | |
parent | 2adfb404111c220ef4df0206d9cda20c2fe5db46 (diff) | |
download | haskell-763d28551de32377a1dca8bdde02979e3686f400.tar.gz |
directory: ensure xdg compliance (Fix #6077)
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 2 | ||||
-rw-r--r-- | docs/users_guide/9.2.1-notes.rst | 4 | ||||
-rw-r--r-- | docs/users_guide/ghci.rst | 4 | ||||
-rw-r--r-- | docs/users_guide/packages.rst | 12 | ||||
-rw-r--r-- | ghc/GHCi/UI.hs | 18 | ||||
-rw-r--r-- | utils/ghc-pkg/Main.hs | 8 |
6 files changed, 33 insertions, 15 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 90f49f995f..5e76da3490 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -867,7 +867,7 @@ opt_i dflags= toolSettings_opt_i $ toolSettings dflags 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 $ getAppUserDataDirectory appname + appdir <- tryMaybeT $ getXdgDirectory XdgData appname return $ appdir </> versionedFilePath platform versionedFilePath :: ArchOS -> FilePath diff --git a/docs/users_guide/9.2.1-notes.rst b/docs/users_guide/9.2.1-notes.rst index a29a744f8b..e06aa5b11b 100644 --- a/docs/users_guide/9.2.1-notes.rst +++ b/docs/users_guide/9.2.1-notes.rst @@ -101,6 +101,10 @@ GHCi :envvar:`EDITOR`, following UNIX convention. (:ghc-ticket:`19030`) +- GHC now follows by default the XDG Base Directory Specification. If + ``$HOME/.ghc`` is found it will fallback to the old paths to give you + time to migrate. This fallback will be removed in three releases. + Runtime system ~~~~~~~~~~~~~~ diff --git a/docs/users_guide/ghci.rst b/docs/users_guide/ghci.rst index 6ff9c1f20a..f32692f472 100644 --- a/docs/users_guide/ghci.rst +++ b/docs/users_guide/ghci.rst @@ -2063,7 +2063,7 @@ mostly obvious. :reverse: -fno-local-ghci-history :category: - By default, GHCi keeps global history in ``~/.ghc/ghci_history`` or + By default, GHCi keeps global history in ``$XDG_DATA_HOME/ghc/ghci_history`` or ``%APPDATA%/<app>/ghci_history``, but you can use current directory, e.g.: .. code-block:: none @@ -3248,7 +3248,7 @@ they exist: Unix or :file:`C:/Documents and Settings/user/Application Data/ghc` on Windows. -2. :file:`$HOME/.ghci` +2. :file:`$XDG_CONFIG_HOME/.ghci` 3. :file:`./.ghci` diff --git a/docs/users_guide/packages.rst b/docs/users_guide/packages.rst index 75774c8055..f24275311b 100644 --- a/docs/users_guide/packages.rst +++ b/docs/users_guide/packages.rst @@ -393,7 +393,7 @@ GHC knows about two package databases in particular: e.g. ``/usr/lib/ghc-6.12.1/package.conf.d``. - The *user package database* private to each user. On Unix systems this will - be ``$HOME/.ghc/arch-os-version/package.conf.d``, and on Windows it will + be ``$XDG_DATA_HOME/ghc/arch-os-version/package.conf.d``, and on Windows it will be something like ``C:\Documents And Settings\user\ghc\package.conf.d``. The ``ghc-pkg`` tool knows where this file should be located, and will @@ -515,7 +515,7 @@ The ``GHC_PACKAGE_PATH`` environment variable .. code-block:: none - $ export GHC_PACKAGE_PATH=$HOME/.my-ghc-packages.conf: + $ export GHC_PACKAGE_PATH=$XDG_DATA_HOME/.my-ghc-packages.conf: To check whether your `GHC_PACKAGE_PATH` setting is doing the right thing, ``ghc-pkg list`` will list all the databases in use, in the @@ -578,7 +578,7 @@ must be relative to the location of the package environment file. :category: Use the package environment in ⟨file⟩, or in - ``$HOME/.ghc/arch-os-version/environments/⟨name⟩`` + ``$XDG_DATA_HOME/ghc/arch-os-version/environments/⟨name⟩`` If set to ``-`` no package environment is read. .. envvar:: GHC_ENVIRONMENT @@ -591,13 +591,13 @@ locations: - File ⟨file⟩ if you pass the option :ghc-flag:`-package-env ⟨file⟩|⟨name⟩`. -- File ``$HOME/.ghc/arch-os-version/environments/name`` if you pass the +- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/name`` if you pass the option ``-package-env ⟨name⟩``. - File ⟨file⟩ if the environment variable :envvar:`GHC_ENVIRONMENT` is set to ⟨file⟩. -- File ``$HOME/.ghc/arch-os-version/environments/name`` if the +- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/name`` if the environment variable :envvar:`GHC_ENVIRONMENT` is set to ⟨name⟩. Additionally, unless ``-hide-all-packages`` is specified ``ghc`` will also @@ -606,7 +606,7 @@ look for the package environment in the following locations: - File ``.ghc.environment.arch-os-version`` if it exists in the current directory or any parent directory (but not the user's home directory). -- File ``$HOME/.ghc/arch-os-version/environments/default`` if it +- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/default`` if it exists. Package environments can be modified by further command line arguments; diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 97b5f57447..18a6e6eeae 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -587,7 +587,21 @@ ghciLogAction lastErrLocations old_log_action withGhcAppData :: (FilePath -> IO a) -> IO a -> IO a withGhcAppData right left = do - either_dir <- tryIO (getAppUserDataDirectory "ghc") + either_dir <- tryIO (getXdgDirectory XdgData "ghc") + case either_dir of + Right dir -> + do createDirectoryIfMissing False dir `catchIO` \_ -> return () + right dir + _ -> left + +withGhcConfig :: (FilePath -> IO a) -> IO a -> IO a +withGhcConfig right left = do + old_path <- getAppUserDataDirectory "ghc" + use_old_path <- doesPathExist old_path + let path = (if use_old_path + then getAppUserDataDirectory "ghc" + else getXdgDirectory XdgConfig "ghc") + either_dir <- tryIO (path) case either_dir of Right dir -> do createDirectoryIfMissing False dir `catchIO` \_ -> return () @@ -600,7 +614,7 @@ runGHCi paths maybe_exprs = do let ignore_dot_ghci = gopt Opt_IgnoreDotGhci dflags - app_user_dir = liftIO $ withGhcAppData + app_user_dir = liftIO $ withGhcConfig (\dir -> return (Just (dir </> "ghci.conf"))) (return Nothing) diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index a0fc8772ac..fc33f3ce37 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -58,8 +58,8 @@ import Distribution.Simple.Utils (toUTF8BS, writeUTF8File, readUTF8File) import qualified Data.Version as Version import System.FilePath as FilePath import qualified System.FilePath.Posix as FilePath.Posix -import System.Directory ( getAppUserDataDirectory, createDirectoryIfMissing, - getModificationTime ) +import System.Directory ( getXdgDirectory, createDirectoryIfMissing, + getModificationTime, XdgDirectory ( XdgData ) ) import Text.Printf import Prelude @@ -634,8 +634,8 @@ getPkgDatabases verbosity mode use_user use_cache expand_vars my_flags = do let no_user_db = FlagNoUserDb `elem` my_flags -- get the location of the user package database, and create it if necessary - -- getAppUserDataDirectory can fail (e.g. if $HOME isn't set) - e_appdir <- tryIO $ getAppUserDataDirectory "ghc" + -- getXdgDirectory can fail (e.g. if $HOME isn't set) + e_appdir <- tryIO $ getXdgDirectory XdgData "ghc" mb_user_conf <- case [ f | FlagUserConfig f <- my_flags ] of |