From 9c1624e457370abe8f9b3adc031872e35f6a1f74 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 9 May 2021 10:22:51 +0200 Subject: [PATCH 01/44] Move towards using XDG directories. --- Cabal-tests/tests/HackageTests.hs | 19 +++++----------- .../src/Distribution/Client/Config.hs | 22 ++++++++----------- doc/installing-packages.rst | 6 ++--- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index e214c626106..54f2e99624d 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -20,12 +20,13 @@ import Data.Foldable (traverse_) import Data.List (isPrefixOf, isSuffixOf) import Data.Maybe (mapMaybe) import Data.Monoid (Sum (..)) +import Distribution.Client.Config (getConfigFilePath) import Distribution.PackageDescription.Check (PackageCheck (..), checkPackage) import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription) import Distribution.PackageDescription.Quirks (patchQuirks) import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS) import Numeric (showFFloat) -import System.Directory (getAppUserDataDirectory) +import System.Directory (getXdgDirectory, XdgDirectory(XdgData)) import System.Environment (lookupEnv) import System.Exit (exitFailure) import System.FilePath (()) @@ -63,23 +64,15 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact) parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool) -> (FilePath -> B.ByteString -> IO a) -> IO a parseIndex predicate action = do - cabalDir <- getAppUserDataDirectory "cabal" - configPath <- getCabalConfigPath cabalDir + configPath <- getConfigFilePath cfg <- B.readFile configPath cfgFields <- either (fail . show) pure $ Parsec.readFields cfg + repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of + [] -> defaultCacheDir -- Default + (rrc : _) -> return rrc -- User-specified let repos = reposFromConfig cfgFields - repoCache = case lookupInConfig "remote-repo-cache" cfgFields of - [] -> cabalDir "packages" -- Default - (rrc : _) -> rrc -- User-specified tarName repo = repoCache repo "01-index.tar" mconcat <$> traverse (parseIndex' predicate action . tarName) repos - where - getCabalConfigPath cabalDir = do - mx <- lookupEnv "CABAL_CONFIG" - case mx of - Just x -> return x - Nothing -> return (cabalDir "config") - parseIndex' :: (Monoid a, NFData a) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index e7277535587..8403f8930d1 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -130,7 +130,7 @@ import Text.PrettyPrint import Text.PrettyPrint.HughesPJ ( text, Doc ) import System.Directory - ( createDirectoryIfMissing, getAppUserDataDirectory, renameFile ) + ( createDirectoryIfMissing, getAppUserDataDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), renameFile ) import Network.URI ( URI(..), URIAuth(..), parseURI ) import System.FilePath @@ -595,25 +595,21 @@ getCabalDir = do Just dir -> return dir defaultConfigFile :: IO FilePath -defaultConfigFile = do - dir <- getCabalDir - return $ dir "config" +defaultConfigFile = + getXdgDirectory XdgConfig $ "cabal" "config" defaultCacheDir :: IO FilePath -defaultCacheDir = do - dir <- getCabalDir - return $ dir "packages" +defaultCacheDir = + getXdgDirectory XdgCache $ "cabal" "packages" defaultLogsDir :: IO FilePath -defaultLogsDir = do - dir <- getCabalDir - return $ dir "logs" +defaultLogsDir = + getXdgDirectory XdgCache $ "cabal" "logs" -- | Default position of the world file defaultWorldFile :: IO FilePath -defaultWorldFile = do - dir <- getCabalDir - return $ dir "world" +defaultWorldFile = + getXdgDirectory XdgCache $ "cabal" "world" defaultExtraPath :: IO [FilePath] defaultExtraPath = do diff --git a/doc/installing-packages.rst b/doc/installing-packages.rst index 9b09d56e514..c1eb1d2583a 100644 --- a/doc/installing-packages.rst +++ b/doc/installing-packages.rst @@ -51,8 +51,8 @@ Various environment variables affect ``cabal-install``. ``CABAL_DIR`` Default content directory for ``cabal-install`` files. - Default value is ``getAppUserDataDirectory "cabal"``, which is - ``$HOME/.cabal`` on unix systems and ``%APPDATA%\cabal`` in Windows. + Default value is ``getXdgDirectory XdgCache "cabal"``, which is + ``$XDG_CACHE_HOME/cabal`` on unix systems and ``%APPDATA%\cabal`` in Windows. .. note:: @@ -244,4 +244,4 @@ dependencies in a single step. To do this, run: To browse the list of available packages, visit the `Hackage`_ web site. -.. _Hackage: https://hackage.haskell.org/ \ No newline at end of file +.. _Hackage: https://hackage.haskell.org/ From aadd47cb76ab20154dfa37d6930d2081ef453064 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 25 Jun 2021 23:03:54 +0200 Subject: [PATCH 02/44] Install binaries in $HOME/.local/bin. --- cabal-install/src/Distribution/Client/Config.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index d3a1a393e6f..e01f3f4be3c 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -616,13 +616,13 @@ defaultWorldFile = defaultExtraPath :: IO [FilePath] defaultExtraPath = do - dir <- getCabalDir - return [dir "bin"] + dir <- getHomeDirectory + return (dir ".local" "bin") defaultInstallPath :: IO FilePath defaultInstallPath = do - dir <- getCabalDir - return (dir "bin") + dir <- getHomeDirectory + return (dir ".local" "bin") defaultCompiler :: CompilerFlavor defaultCompiler = fromMaybe GHC defaultCompilerFlavor From 813c4ee3b142cf63dcff6abac25ed4e2875e4063 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sat, 26 Jun 2021 01:00:42 +0200 Subject: [PATCH 03/44] Fix tests. --- Cabal-tests/Cabal-tests.cabal | 1 + Cabal-tests/tests/HackageTests.hs | 4 ++-- cabal-install/src/Distribution/Client/Config.hs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cabal-tests/Cabal-tests.cabal b/Cabal-tests/Cabal-tests.cabal index 093a552e4ba..4d3dfe3aa4f 100644 --- a/Cabal-tests/Cabal-tests.cabal +++ b/Cabal-tests/Cabal-tests.cabal @@ -160,6 +160,7 @@ test-suite hackage-tests , bytestring , Cabal , Cabal-tree-diff + , cabal-install , containers , deepseq , directory diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index 54f2e99624d..850831f6fc1 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -20,7 +20,7 @@ import Data.Foldable (traverse_) import Data.List (isPrefixOf, isSuffixOf) import Data.Maybe (mapMaybe) import Data.Monoid (Sum (..)) -import Distribution.Client.Config (getConfigFilePath) +import Distribution.Client.Config (getConfigFilePath, defaultCacheDir) import Distribution.PackageDescription.Check (PackageCheck (..), checkPackage) import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription) import Distribution.PackageDescription.Quirks (patchQuirks) @@ -64,7 +64,7 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact) parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool) -> (FilePath -> B.ByteString -> IO a) -> IO a parseIndex predicate action = do - configPath <- getConfigFilePath + configPath <- getConfigFilePath mempty cfg <- B.readFile configPath cfgFields <- either (fail . show) pure $ Parsec.readFields cfg repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index e01f3f4be3c..b3d037d4873 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -130,7 +130,7 @@ import Text.PrettyPrint import Text.PrettyPrint.HughesPJ ( text, Doc ) import System.Directory - ( createDirectoryIfMissing, getAppUserDataDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), renameFile ) + ( createDirectoryIfMissing, getAppUserDataDirectory, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), renameFile ) import Network.URI ( URI(..), URIAuth(..), parseURI ) import System.FilePath @@ -617,7 +617,7 @@ defaultWorldFile = defaultExtraPath :: IO [FilePath] defaultExtraPath = do dir <- getHomeDirectory - return (dir ".local" "bin") + return [dir ".local" "bin"] defaultInstallPath :: IO FilePath defaultInstallPath = do From 39ad39625af21e1c9b4919527d9b9ad159072a81 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sat, 4 Sep 2021 10:19:10 +0200 Subject: [PATCH 04/44] Ensure config file is where it should be. --- .github/workflows/linux.yml | 66 +++++++++++++++++++++++++++++++++ templates/ci-linux.template.yml | 6 +++ 2 files changed, 72 insertions(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 544011da33a..38cc62546e1 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -39,6 +39,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -81,6 +87,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -126,6 +138,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -172,6 +190,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -218,6 +242,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -264,6 +294,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -310,6 +346,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -352,6 +394,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -394,6 +442,12 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -440,6 +494,12 @@ jobs: run: apt-get install -y ghc-7.6.3-dyn - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout @@ -488,6 +548,12 @@ jobs: run: apt-get install -y ghc-7.0.4-dyn ghc-7.2.2-dyn ghc-7.4.2-dyn - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout diff --git a/templates/ci-linux.template.yml b/templates/ci-linux.template.yml index 3f90db7fbe3..0e264c8338e 100644 --- a/templates/ci-linux.template.yml +++ b/templates/ci-linux.template.yml @@ -54,6 +54,12 @@ jobs: {% endif %} - name: Update Hackage index run: cabal v2-update + - name: Move config file + run: | + if [ -f $HOME/.cabal/config ]; then + mkdir -p $HOME/.config/cabal + cp $HOME/.cabal/config $HOME/.config/cabal/config + fi # https://github.com/actions/checkout/issues/170 # - uses: actions/checkout@v2 - name: Checkout From 299ab6c1fffd7d8eb559745086d1905ab3bba203 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 21:27:43 +0200 Subject: [PATCH 05/44] Require newer directory for XdgState. --- cabal-install/cabal-install.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 3e6ac1bacb9..d63c309acb2 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -207,7 +207,7 @@ library bytestring >= 0.10.6.0 && < 0.12, containers >= 0.5.6.2 && < 0.7, cryptohash-sha256 >= 0.11 && < 0.12, - directory >= 1.2.2.0 && < 1.4, + directory >= 1.3.7.0 && < 1.4, echo >= 0.1.3 && < 0.2, edit-distance >= 0.2.2 && < 0.3, exceptions >= 0.10.4 && < 0.11, From 787ddcaf670d0beadc81970d17ca1d557e4e2ce3 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 21:31:08 +0200 Subject: [PATCH 06/44] Put world file in XDG_STATE_HOME. --- cabal-install/src/Distribution/Client/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index b13c4d9b2d5..61bc98d8cd2 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -612,7 +612,7 @@ defaultLogsDir = -- | Default position of the world file defaultWorldFile :: IO FilePath defaultWorldFile = - getXdgDirectory XdgCache $ "cabal" "world" + getXdgDirectory XdgState $ "cabal" "world" defaultExtraPath :: IO [FilePath] defaultExtraPath = do From 664266333f368fb8f1bd974b276ebc72a536f022 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 21:39:28 +0200 Subject: [PATCH 07/44] Oops, forgot to import. --- cabal-install/src/Distribution/Client/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 61bc98d8cd2..4be2d645c9e 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -130,7 +130,7 @@ import Text.PrettyPrint import Text.PrettyPrint.HughesPJ ( text, Doc ) import System.Directory - ( createDirectoryIfMissing, getAppUserDataDirectory, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), renameFile ) + ( createDirectoryIfMissing, getAppUserDataDirectory, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile ) import Network.URI ( URI(..), URIAuth(..), parseURI ) import System.FilePath From d5a10e93e86067b32ca9ea19579f5f5a1632fbee Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 22:06:40 +0200 Subject: [PATCH 08/44] Remove uses of getCabalDir. --- .../src/Distribution/Client/CmdInstall.hs | 9 +++---- .../src/Distribution/Client/Config.hs | 14 ++++++---- .../src/Distribution/Client/DistDirLayout.hs | 27 +++++++++---------- .../src/Distribution/Client/Install.hs | 6 ++--- .../Client/ProjectOrchestration.hs | 15 +++++------ .../src/Distribution/Client/ScriptUtils.hs | 6 ++--- .../src/Distribution/Client/SetupWrapper.hs | 6 ++--- .../src/Distribution/Client/Upload.hs | 4 +-- cabal-install/tests/IntegrationTests2.hs | 4 +-- 9 files changed, 44 insertions(+), 47 deletions(-) diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index fd47f5545c2..f8f16497fe8 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -64,7 +64,7 @@ import Distribution.Simple.BuildPaths import Distribution.Simple.Program.Find ( ProgramSearchPathEntry(..) ) import Distribution.Client.Config - ( defaultInstallPath, getCabalDir, loadConfig, SavedConfig(..) ) + ( defaultInstallPath, loadConfig, SavedConfig(..) ) import qualified Distribution.Simple.PackageIndex as PI import Distribution.Solver.Types.PackageIndex ( lookupPackageName, searchByName ) @@ -254,7 +254,6 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe withoutProject globalConfig = do tss <- traverse (parseWithoutProjectTargetSelector verbosity) targetStrings' - cabalDir <- getCabalDir let projectConfig = globalConfig <> cliConfig @@ -268,8 +267,9 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe mlogsDir = flagToMaybe projectConfigLogsDir mstoreDir = flagToMaybe projectConfigStoreDir - cabalDirLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir + cabalDirLayout <- mkCabalDirLayout mstoreDir mlogsDir + let buildSettings = resolveBuildTimeSettings verbosity cabalDirLayout projectConfig @@ -912,11 +912,10 @@ getPackageDbStack -> Flag FilePath -> IO PackageDBStack getPackageDbStack compilerId storeDirFlag logsDirFlag = do - cabalDir <- getCabalDir mstoreDir <- traverse makeAbsolute $ flagToMaybe storeDirFlag let mlogsDir = flagToMaybe logsDirFlag - cabalLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir + cabalLayout <- mkCabalDirLayout mstoreDir mlogsDir pure $ storePackageDBStack (cabalStoreDirLayout cabalLayout) compilerId -- | This defines what a 'TargetSelector' means for the @bench@ command. diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 4be2d645c9e..c2983055bad 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -22,12 +22,13 @@ module Distribution.Client.Config ( showConfigWithComments, parseConfig, - getCabalDir, defaultConfigFile, defaultCacheDir, + defaultStoreDir, defaultCompiler, defaultInstallPath, defaultLogsDir, + defaultReportsDir, defaultUserInstall, baseSavedConfig, @@ -605,14 +606,17 @@ defaultCacheDir :: IO FilePath defaultCacheDir = getXdgDirectory XdgCache $ "cabal" "packages" +defaultStoreDir :: IO FilePath +defaultStoreDir = + getXdgDirectory XdgState $ "cabal" "store" + defaultLogsDir :: IO FilePath defaultLogsDir = getXdgDirectory XdgCache $ "cabal" "logs" --- | Default position of the world file -defaultWorldFile :: IO FilePath -defaultWorldFile = - getXdgDirectory XdgState $ "cabal" "world" +defaultReportsDir :: IO FilePath +defaultReportsDir = + getXdgDirectory XdgCache $ "cabal" "reports" defaultExtraPath :: IO [FilePath] defaultExtraPath = do diff --git a/cabal-install/src/Distribution/Client/DistDirLayout.hs b/cabal-install/src/Distribution/Client/DistDirLayout.hs index d8923370797..2b88ddc4302 100644 --- a/cabal-install/src/Distribution/Client/DistDirLayout.hs +++ b/cabal-install/src/Distribution/Client/DistDirLayout.hs @@ -27,6 +27,8 @@ import Prelude () import System.FilePath +import Distribution.Client.Config + ( defaultStoreDir, defaultLogsDir) import Distribution.Package ( PackageId, PackageIdentifier, ComponentId, UnitId ) import Distribution.Compiler @@ -292,19 +294,16 @@ defaultStoreDirLayout storeRoot = storeIncomingDirectory compid prettyShow unitid <.> "lock" -defaultCabalDirLayout :: FilePath -> CabalDirLayout -defaultCabalDirLayout cabalDir = - mkCabalDirLayout cabalDir Nothing Nothing +defaultCabalDirLayout :: IO CabalDirLayout +defaultCabalDirLayout = + mkCabalDirLayout Nothing Nothing -mkCabalDirLayout :: FilePath -- ^ Cabal directory - -> Maybe FilePath -- ^ Store directory. Must be absolute +mkCabalDirLayout :: Maybe FilePath -- ^ Store directory. Must be absolute -> Maybe FilePath -- ^ Log directory - -> CabalDirLayout -mkCabalDirLayout cabalDir mstoreDir mlogDir = - CabalDirLayout {..} - where - cabalStoreDirLayout :: StoreDirLayout - cabalStoreDirLayout = - defaultStoreDirLayout (fromMaybe (cabalDir "store") mstoreDir) - cabalLogsDirectory :: FilePath - cabalLogsDirectory = fromMaybe (cabalDir "logs") mlogDir + -> IO CabalDirLayout +mkCabalDirLayout mstoreDir mlogDir = do + cabalStoreDirLayout <- + defaultStoreDirLayout <$> maybe defaultStoreDir pure mstoreDir + cabalLogsDirectory <- + maybe defaultLogsDir pure mlogDir + pure $ CabalDirLayout {..} diff --git a/cabal-install/src/Distribution/Client/Install.hs b/cabal-install/src/Distribution/Client/Install.hs index d099ec4dfff..fb35cc9649b 100644 --- a/cabal-install/src/Distribution/Client/Install.hs +++ b/cabal-install/src/Distribution/Client/Install.hs @@ -71,7 +71,7 @@ import Distribution.Client.Setup , ConfigExFlags(..), InstallFlags(..) , filterTestFlags ) import Distribution.Client.Config - ( getCabalDir, defaultUserInstall ) + ( defaultReportsDir, defaultUserInstall ) import Distribution.Client.Tar (extractTarGzFile) import Distribution.Client.Types as Source import Distribution.Client.BuildReports.Types @@ -831,10 +831,10 @@ postInstallActions verbosity storeDetailedBuildReports :: Verbosity -> FilePath -> [(BuildReports.BuildReport, Maybe Repo)] -> IO () storeDetailedBuildReports verbosity logsDir reports = sequence_ - [ do dotCabal <- getCabalDir + [ do allReportsDir <- defaultReportsDir let logFileName = prettyShow (BuildReports.package report) <.> "log" logFile = logsDir logFileName - reportsDir = dotCabal "reports" unRepoName (remoteRepoName remoteRepo) + reportsDir = allReportsDir unRepoName (remoteRepoName remoteRepo) reportFile = reportsDir logFileName handleMissingLogFile $ do diff --git a/cabal-install/src/Distribution/Client/ProjectOrchestration.hs b/cabal-install/src/Distribution/Client/ProjectOrchestration.hs index d7933b6c2a9..83eb723e7ae 100644 --- a/cabal-install/src/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/src/Distribution/Client/ProjectOrchestration.hs @@ -138,7 +138,7 @@ import qualified Distribution.Client.BuildReports.Anonymous as BuildReports import qualified Distribution.Client.BuildReports.Storage as BuildReports ( storeLocal ) -import Distribution.Client.Config (getCabalDir) +import Distribution.Client.Config () import Distribution.Client.HttpUtils import Distribution.Client.Setup hiding (packageName) import Distribution.Compiler @@ -222,8 +222,6 @@ establishProjectBaseContextWithRoot -> CurrentCommand -> IO ProjectBaseContext establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentCommand = do - cabalDir <- getCabalDir - let distDirLayout = defaultDistDirLayout projectRoot mdistDirectory httpTransport <- configureTransport verbosity @@ -247,9 +245,9 @@ establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentComma mlogsDir = Setup.flagToMaybe projectConfigLogsDir mstoreDir <- sequenceA $ makeAbsolute <$> Setup.flagToMaybe projectConfigStoreDir - let cabalDirLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir + cabalDirLayout <- mkCabalDirLayout mstoreDir mlogsDir - buildSettings = resolveBuildTimeSettings + let buildSettings = resolveBuildTimeSettings verbosity cabalDirLayout projectConfig @@ -1319,8 +1317,6 @@ establishDummyProjectBaseContext -> CurrentCommand -> IO ProjectBaseContext establishDummyProjectBaseContext verbosity projectConfig distDirLayout localPackages currentCommand = do - cabalDir <- getCabalDir - let ProjectConfigBuildOnly { projectConfigLogsDir } = projectConfigBuildOnly projectConfig @@ -1331,9 +1327,10 @@ establishDummyProjectBaseContext verbosity projectConfig distDirLayout localPack mlogsDir = flagToMaybe projectConfigLogsDir mstoreDir = flagToMaybe projectConfigStoreDir - cabalDirLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir - buildSettings :: BuildTimeSettings + cabalDirLayout <- mkCabalDirLayout mstoreDir mlogsDir + + let buildSettings :: BuildTimeSettings buildSettings = resolveBuildTimeSettings verbosity cabalDirLayout projectConfig diff --git a/cabal-install/src/Distribution/Client/ScriptUtils.hs b/cabal-install/src/Distribution/Client/ScriptUtils.hs index 6555b92ef7c..f981593045d 100644 --- a/cabal-install/src/Distribution/Client/ScriptUtils.hs +++ b/cabal-install/src/Distribution/Client/ScriptUtils.hs @@ -22,7 +22,7 @@ import Distribution.CabalSpecVersion ( CabalSpecVersion (..), cabalSpecLatest) import Distribution.Client.ProjectOrchestration import Distribution.Client.Config - ( getCabalDir ) + ( defaultCacheDir ) import Distribution.Client.DistDirLayout ( DistDirLayout(..) ) import Distribution.Client.HashValue @@ -125,8 +125,8 @@ import qualified Text.Parsec as P -- @CABAL_DIR\/script-builds\/@ getScriptCacheDirectoryRoot :: IO FilePath getScriptCacheDirectoryRoot = do - cabalDir <- getCabalDir - return $ cabalDir "script-builds" + cacheDir <- defaultCacheDir + return $ cacheDir "script-builds" -- | Get the hash of a script's absolute path) -- diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs index 1ac82efcbd7..20f20691b2e 100644 --- a/cabal-install/src/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs @@ -77,7 +77,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex) import qualified Distribution.InstalledPackageInfo as IPI import Distribution.Client.Types import Distribution.Client.Config - ( getCabalDir ) + ( defaultCacheDir ) import Distribution.Client.IndexUtils ( getInstalledPackages ) import Distribution.Client.JobControl @@ -740,8 +740,8 @@ getExternalSetupMethod verbosity options pkg bt = do cachedSetupDirAndProg :: SetupScriptOptions -> Version -> IO (FilePath, FilePath) cachedSetupDirAndProg options' cabalLibVersion = do - cabalDir <- getCabalDir - let setupCacheDir = cabalDir "setup-exe-cache" + cacheDir <- defaultCacheDir + let setupCacheDir = cacheDir "setup-exe-cache" cachedSetupProgFile = setupCacheDir ("setup-" ++ buildTypeString ++ "-" ++ cabalVersionString ++ "-" diff --git a/cabal-install/src/Distribution/Client/Upload.hs b/cabal-install/src/Distribution/Client/Upload.hs index 1c23aa21696..d5f46439954 100644 --- a/cabal-install/src/Distribution/Client/Upload.hs +++ b/cabal-install/src/Distribution/Client/Upload.hs @@ -183,9 +183,9 @@ report verbosity repoCtxt mUsername mPassword = do let auth :: (String, String) auth = (username, password) - dotCabal <- getCabalDir + reportsDir <- defaultReportsDir let srcDir :: FilePath - srcDir = dotCabal "reports" unRepoName (remoteRepoName remoteRepo) + srcDir = reportsDir unRepoName (remoteRepoName remoteRepo) -- We don't want to bomb out just because we haven't built any packages -- from this repo yet. srcExists <- doesDirectoryExist srcDir diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index da1652aadd6..1e552605446 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -15,7 +15,6 @@ import Prelude () import Distribution.Client.DistDirLayout import Distribution.Client.ProjectConfig -import Distribution.Client.Config (getCabalDir) import Distribution.Client.HttpUtils import Distribution.Client.TargetSelector hiding (DirActions(..)) import qualified Distribution.Client.TargetSelector as TS (DirActions(..)) @@ -1678,8 +1677,7 @@ type ProjDetails = (DistDirLayout, configureProject :: FilePath -> ProjectConfig -> IO ProjDetails configureProject testdir cliConfig = do - cabalDir <- getCabalDir - let cabalDirLayout = defaultCabalDirLayout cabalDir + cabalDirLayout <- defaultCabalDirLayout projectRootDir <- canonicalizePath (basedir testdir) isexplict <- doesFileExist (projectRootDir "cabal.project") From 70b12148abfe8a39b47cf80441b14c6eb78f5581 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 22:40:21 +0200 Subject: [PATCH 09/44] These all need directory-1.3.7.0 now. --- bootstrap/linux-8.10.7.json | 2 +- bootstrap/linux-8.6.5.json | 2 +- bootstrap/linux-8.8.4.json | 2 +- bootstrap/linux-9.0.2.json | 2 +- bootstrap/linux-9.2.3.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bootstrap/linux-8.10.7.json b/bootstrap/linux-8.10.7.json index 34ff8c40d19..654209e11f2 100644 --- a/bootstrap/linux-8.10.7.json +++ b/bootstrap/linux-8.10.7.json @@ -354,7 +354,7 @@ }, { "package": "directory", - "version": "1.3.6.0" + "version": "1.3.7.0" }, { "package": "transformers", diff --git a/bootstrap/linux-8.6.5.json b/bootstrap/linux-8.6.5.json index ac629a89ccc..fc77a867114 100644 --- a/bootstrap/linux-8.6.5.json +++ b/bootstrap/linux-8.6.5.json @@ -365,7 +365,7 @@ }, { "package": "directory", - "version": "1.3.3.0" + "version": "1.3.7.0" }, { "package": "transformers", diff --git a/bootstrap/linux-8.8.4.json b/bootstrap/linux-8.8.4.json index 2a46e755c6f..29dd42e475f 100644 --- a/bootstrap/linux-8.8.4.json +++ b/bootstrap/linux-8.8.4.json @@ -365,7 +365,7 @@ }, { "package": "directory", - "version": "1.3.6.0" + "version": "1.3.7.0" }, { "package": "transformers", diff --git a/bootstrap/linux-9.0.2.json b/bootstrap/linux-9.0.2.json index b9527b73c2c..fa157e190f3 100644 --- a/bootstrap/linux-9.0.2.json +++ b/bootstrap/linux-9.0.2.json @@ -354,7 +354,7 @@ }, { "package": "directory", - "version": "1.3.6.2" + "version": "1.3.7.0" }, { "package": "transformers", diff --git a/bootstrap/linux-9.2.3.json b/bootstrap/linux-9.2.3.json index 08db7275892..36e07c272b5 100644 --- a/bootstrap/linux-9.2.3.json +++ b/bootstrap/linux-9.2.3.json @@ -357,7 +357,7 @@ }, { "package": "directory", - "version": "1.3.6.2" + "version": "1.3.7.0" }, { "package": "transformers", From 28febc3655f4ff5607b5f2be2422c1f11b2d2a0f Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 22:48:14 +0200 Subject: [PATCH 10/44] Oh right, not a builtin anymore. If this works I will also change the other .json files. --- bootstrap/linux-8.10.7.json | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bootstrap/linux-8.10.7.json b/bootstrap/linux-8.10.7.json index 654209e11f2..0292632de80 100644 --- a/bootstrap/linux-8.10.7.json +++ b/bootstrap/linux-8.10.7.json @@ -301,7 +301,16 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - } + }, + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, ], "builtin": [ { @@ -352,10 +361,6 @@ "package": "unix", "version": "2.7.2.2" }, - { - "package": "directory", - "version": "1.3.7.0" - }, { "package": "transformers", "version": "0.5.6.2" From f11619a6ce0ef0692b151403916b7b78644fafa4 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 22:52:14 +0200 Subject: [PATCH 11/44] Try it by hand. --- bootstrap/linux-8.8.4.json | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bootstrap/linux-8.8.4.json b/bootstrap/linux-8.8.4.json index 29dd42e475f..74175ef75a4 100644 --- a/bootstrap/linux-8.8.4.json +++ b/bootstrap/linux-8.8.4.json @@ -312,7 +312,16 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - } + }, + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, ], "builtin": [ { @@ -363,10 +372,6 @@ "package": "unix", "version": "2.7.2.2" }, - { - "package": "directory", - "version": "1.3.7.0" - }, { "package": "transformers", "version": "0.5.6.2" From 899718ef6396c42acce5cfd661e35ef1a101e47c Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 22:54:46 +0200 Subject: [PATCH 12/44] Haskell is better than JSON. --- bootstrap/linux-8.10.7.json | 2 +- bootstrap/linux-8.8.4.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/linux-8.10.7.json b/bootstrap/linux-8.10.7.json index 0292632de80..dda7cb72917 100644 --- a/bootstrap/linux-8.10.7.json +++ b/bootstrap/linux-8.10.7.json @@ -310,7 +310,7 @@ "package": "directory", "source": "hackage", "version": "1.3.7.1" - }, + } ], "builtin": [ { diff --git a/bootstrap/linux-8.8.4.json b/bootstrap/linux-8.8.4.json index 74175ef75a4..e7754a6baa6 100644 --- a/bootstrap/linux-8.8.4.json +++ b/bootstrap/linux-8.8.4.json @@ -321,7 +321,7 @@ "package": "directory", "source": "hackage", "version": "1.3.7.1" - }, + } ], "builtin": [ { From 4cb1d8612f22237eb0ee07e233c69251de1a138f Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Thu, 18 Aug 2022 23:01:06 +0200 Subject: [PATCH 13/44] Bump directory in all jsons. --- bootstrap/linux-8.6.5.json | 13 +++++++++---- bootstrap/linux-9.0.2.json | 13 +++++++++---- bootstrap/linux-9.2.3.json | 13 +++++++++---- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bootstrap/linux-8.6.5.json b/bootstrap/linux-8.6.5.json index fc77a867114..c3457b48271 100644 --- a/bootstrap/linux-8.6.5.json +++ b/bootstrap/linux-8.6.5.json @@ -312,6 +312,15 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" + }, + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" } ], "builtin": [ @@ -363,10 +372,6 @@ "package": "unix", "version": "2.7.2.2" }, - { - "package": "directory", - "version": "1.3.7.0" - }, { "package": "transformers", "version": "0.5.6.2" diff --git a/bootstrap/linux-9.0.2.json b/bootstrap/linux-9.0.2.json index fa157e190f3..78718dbbe47 100644 --- a/bootstrap/linux-9.0.2.json +++ b/bootstrap/linux-9.0.2.json @@ -301,6 +301,15 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" + }, + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" } ], "builtin": [ @@ -352,10 +361,6 @@ "package": "unix", "version": "2.7.2.2" }, - { - "package": "directory", - "version": "1.3.7.0" - }, { "package": "transformers", "version": "0.5.6.2" diff --git a/bootstrap/linux-9.2.3.json b/bootstrap/linux-9.2.3.json index 36e07c272b5..ac22e41c1bc 100644 --- a/bootstrap/linux-9.2.3.json +++ b/bootstrap/linux-9.2.3.json @@ -292,6 +292,15 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" + }, + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" } ], "builtin": [ @@ -355,10 +364,6 @@ "package": "unix", "version": "2.7.2.2" }, - { - "package": "directory", - "version": "1.3.7.0" - }, { "package": "transformers", "version": "0.5.6.2" From a3d46760b18d44567b40e12172774c8a1b05c082 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 08:20:55 +0200 Subject: [PATCH 14/44] Put directory first. --- bootstrap/linux-8.10.7.json | 18 +++++++++--------- bootstrap/linux-8.6.5.json | 18 +++++++++--------- bootstrap/linux-8.8.4.json | 18 +++++++++--------- bootstrap/linux-9.0.2.json | 18 +++++++++--------- bootstrap/linux-9.2.3.json | 18 +++++++++--------- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/bootstrap/linux-8.10.7.json b/bootstrap/linux-8.10.7.json index dda7cb72917..b852f5e1854 100644 --- a/bootstrap/linux-8.10.7.json +++ b/bootstrap/linux-8.10.7.json @@ -1,5 +1,14 @@ { "dependencies": [ + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, { "cabal_sha256": null, "revision": null, @@ -301,15 +310,6 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - }, - { - "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, - "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", - "flags": [], - "package": "directory", - "source": "hackage", - "version": "1.3.7.1" } ], "builtin": [ diff --git a/bootstrap/linux-8.6.5.json b/bootstrap/linux-8.6.5.json index c3457b48271..f95aa856c8f 100644 --- a/bootstrap/linux-8.6.5.json +++ b/bootstrap/linux-8.6.5.json @@ -1,5 +1,14 @@ { "dependencies": [ + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, { "cabal_sha256": null, "revision": null, @@ -312,15 +321,6 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - }, - { - "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, - "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", - "flags": [], - "package": "directory", - "source": "hackage", - "version": "1.3.7.1" } ], "builtin": [ diff --git a/bootstrap/linux-8.8.4.json b/bootstrap/linux-8.8.4.json index e7754a6baa6..b87d5f63295 100644 --- a/bootstrap/linux-8.8.4.json +++ b/bootstrap/linux-8.8.4.json @@ -1,5 +1,14 @@ { "dependencies": [ + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, { "cabal_sha256": null, "revision": null, @@ -312,15 +321,6 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - }, - { - "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, - "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", - "flags": [], - "package": "directory", - "source": "hackage", - "version": "1.3.7.1" } ], "builtin": [ diff --git a/bootstrap/linux-9.0.2.json b/bootstrap/linux-9.0.2.json index 78718dbbe47..68652c2d5ef 100644 --- a/bootstrap/linux-9.0.2.json +++ b/bootstrap/linux-9.0.2.json @@ -1,5 +1,14 @@ { "dependencies": [ + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, { "cabal_sha256": null, "revision": null, @@ -301,15 +310,6 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - }, - { - "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, - "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", - "flags": [], - "package": "directory", - "source": "hackage", - "version": "1.3.7.1" } ], "builtin": [ diff --git a/bootstrap/linux-9.2.3.json b/bootstrap/linux-9.2.3.json index ac22e41c1bc..cea47336119 100644 --- a/bootstrap/linux-9.2.3.json +++ b/bootstrap/linux-9.2.3.json @@ -1,5 +1,14 @@ { "dependencies": [ + { + "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", + "revision": null, + "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", + "flags": [], + "package": "directory", + "source": "hackage", + "version": "1.3.7.1" + }, { "cabal_sha256": null, "revision": null, @@ -292,15 +301,6 @@ "package": "cabal-install", "source": "local", "version": "3.9.0.0" - }, - { - "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, - "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", - "flags": [], - "package": "directory", - "source": "hackage", - "version": "1.3.7.1" } ], "builtin": [ From 8c6cc676be1fcb510a67607bed187c1ce7d94713 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 09:33:21 +0200 Subject: [PATCH 15/44] Let us assume that getConfigFilePath gets this right. --- Cabal-tests/tests/HackageTests.hs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index 84278465571..12a339c40c8 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -26,8 +26,6 @@ import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescriptio import Distribution.PackageDescription.Quirks (patchQuirks) import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS) import Numeric (showFFloat) -import System.Directory (getXdgDirectory, XdgDirectory(XdgData)) -import System.Environment (lookupEnv) import System.Exit (exitFailure) import System.FilePath (()) @@ -64,8 +62,7 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact) parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool) -> (FilePath -> B.ByteString -> IO a) -> IO a parseIndex predicate action = do - cabalDir <- getCabalDir - configPath <- getCabalConfigPath cabalDir + configPath <- getConfigFilePath mempty cfg <- B.readFile configPath cfgFields <- either (fail . show) pure $ Parsec.readFields cfg repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of @@ -74,17 +71,6 @@ parseIndex predicate action = do let repos = reposFromConfig cfgFields tarName repo = repoCache repo "01-index.tar" mconcat <$> traverse (parseIndex' predicate action . tarName) repos - where - getCabalDir = do - mx <- lookupEnv "CABAL_DIR" - case mx of - Just x -> return x - Nothing -> getAppUserDataDirectory "cabal" - getCabalConfigPath cabalDir = do - mx <- lookupEnv "CABAL_CONFIG" - case mx of - Just x -> return x - Nothing -> return (cabalDir "config") parseIndex' From eda8190c6775128eeea596bfc3e314eb6abd9f8e Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 09:46:01 +0200 Subject: [PATCH 16/44] Implement backwards compatibility. --- .../src/Distribution/Client/Config.hs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index c2983055bad..5a60cd5375e 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -131,7 +131,7 @@ import Text.PrettyPrint import Text.PrettyPrint.HughesPJ ( text, Doc ) import System.Directory - ( createDirectoryIfMissing, getAppUserDataDirectory, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile ) + ( createDirectoryIfMissing, getAppUserDataDirectory, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile, doesDirectoryExist ) import Network.URI ( URI(..), URIAuth(..), parseURI ) import System.FilePath @@ -598,25 +598,43 @@ getCabalDir = do Nothing -> defaultCabalDir Just dir -> return dir +-- The default behaviour of cabal-install is to use the XDG directory +-- standard. However, if CABAL_DIR is set, we instead use that +-- directory as a single store for everything cabal-related, like the +-- old ~/.cabal behaviour. Also, for backwards compatibility, if +-- ~/.cabal exists we treat that as equivalent to CABAL_DIR being set. +-- This function abstracts that decision-making. +getDefaultDir :: XdgDirectory -> FilePath -> IO FilePath +getDefaultDir xdg subdir = do + mDir <- lookupEnv "CABAL_DIR" + case mDir of + Just dir -> return $ dir subdir + Nothing -> do + defaultDir <- defaultCabalDir + dotCabalExists <- doesDirectoryExist defaultDir + if dotCabalExists + then return $ defaultDir subdir + else getXdgDirectory xdg $ "cabal" subdir + defaultConfigFile :: IO FilePath defaultConfigFile = - getXdgDirectory XdgConfig $ "cabal" "config" + getDefaultDir XdgConfig "config" defaultCacheDir :: IO FilePath defaultCacheDir = - getXdgDirectory XdgCache $ "cabal" "packages" + getDefaultDir XdgCache "packages" defaultStoreDir :: IO FilePath defaultStoreDir = - getXdgDirectory XdgState $ "cabal" "store" + getDefaultDir XdgState "store" defaultLogsDir :: IO FilePath defaultLogsDir = - getXdgDirectory XdgCache $ "cabal" "logs" + getDefaultDir XdgCache "logs" defaultReportsDir :: IO FilePath defaultReportsDir = - getXdgDirectory XdgCache $ "cabal" "reports" + getDefaultDir XdgCache "reports" defaultExtraPath :: IO [FilePath] defaultExtraPath = do From 2d97c744748401ee10fa2290bdb0382e14f5fd95 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 10:19:19 +0200 Subject: [PATCH 17/44] This is now elsewhere. --- cabal-testsuite/src/Test/Cabal/Prelude.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs index 355a2a9de1e..dcfb75c382f 100644 --- a/cabal-testsuite/src/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs @@ -839,7 +839,7 @@ getScriptCacheDirectory script = do cabalDir <- testCabalDir `fmap` getTestEnv hashinput <- liftIO $ canonicalizePath script let hash = C.unpack . Base16.encode . SHA256.hash . C.pack $ hashinput - return $ cabalDir "script-builds" hash + return $ cabalDir "packages" "script-builds" hash ------------------------------------------------------------------------ -- * Skipping tests From cb3016fda975efa7851ada107415ced5a78ab227 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 11:03:00 +0200 Subject: [PATCH 18/44] We need to create parents as well because ~/.local might not exist. --- cabal-install/src/Distribution/Client/CmdInstall.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index f8f16497fe8..84fc86f65ba 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -605,7 +605,7 @@ installExes verbosity baseCtx buildCtx platform compiler installdir <- fromFlagOrDefault (warn verbosity installdirUnknown >> pure installPath) $ pure <$> cinstInstalldir clientInstallFlags - createDirectoryIfMissingVerbose verbosity False installdir + createDirectoryIfMissingVerbose verbosity True installdir warnIfNoExes verbosity buildCtx installMethod <- flagElim defaultMethod return $ From b4e97fe63974128ea54eceb74a3a2d6fa3117a86 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 11:58:43 +0200 Subject: [PATCH 19/44] Put scripts-build in distinct cache directory. --- .../src/Distribution/Client/CmdClean.hs | 6 +++--- .../src/Distribution/Client/Config.hs | 5 +++++ .../src/Distribution/Client/ScriptUtils.hs | 18 +++++------------- cabal-testsuite/src/Test/Cabal/Prelude.hs | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cabal-install/src/Distribution/Client/CmdClean.hs b/cabal-install/src/Distribution/Client/CmdClean.hs index a0eee3e33fa..d0d1a573e4c 100644 --- a/cabal-install/src/Distribution/Client/CmdClean.hs +++ b/cabal-install/src/Distribution/Client/CmdClean.hs @@ -4,12 +4,12 @@ module Distribution.Client.CmdClean (cleanCommand, cleanAction) where import Prelude () import Distribution.Client.Compat.Prelude +import Distribution.Client.Config + ( defaultScriptBuildsDir ) import Distribution.Client.DistDirLayout ( DistDirLayout(..), defaultDistDirLayout ) import Distribution.Client.ProjectConfig ( findProjectRoot ) -import Distribution.Client.ScriptUtils - ( getScriptCacheDirectoryRoot ) import Distribution.Client.Setup ( GlobalFlags ) import Distribution.ReadE ( succeedReadE ) @@ -121,7 +121,7 @@ cleanAction CleanFlags{..} extraArgs _ = do -- There is currently no good way to specify to only clean orphaned caches. -- It would be better as part of an explicit gc step (see issue #3333) toClean <- Set.fromList <$> mapM canonicalizePath extraArgs - cacheDir <- getScriptCacheDirectoryRoot + cacheDir <- defaultScriptBuildsDir existsCD <- doesDirectoryExist cacheDir caches <- if existsCD then listDirectory cacheDir else return [] paths <- fmap concat . forM caches $ \cache -> do diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 5a60cd5375e..1eaedfc1a92 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -24,6 +24,7 @@ module Distribution.Client.Config ( defaultConfigFile, defaultCacheDir, + defaultScriptBuildsDir, defaultStoreDir, defaultCompiler, defaultInstallPath, @@ -624,6 +625,10 @@ defaultCacheDir :: IO FilePath defaultCacheDir = getDefaultDir XdgCache "packages" +defaultScriptBuildsDir :: IO FilePath +defaultScriptBuildsDir = + getDefaultDir XdgCache "script-builds" + defaultStoreDir :: IO FilePath defaultStoreDir = getDefaultDir XdgState "store" diff --git a/cabal-install/src/Distribution/Client/ScriptUtils.hs b/cabal-install/src/Distribution/Client/ScriptUtils.hs index f981593045d..5f015fefc58 100644 --- a/cabal-install/src/Distribution/Client/ScriptUtils.hs +++ b/cabal-install/src/Distribution/Client/ScriptUtils.hs @@ -6,7 +6,7 @@ -- | Utilities to help commands with scripts -- module Distribution.Client.ScriptUtils ( - getScriptCacheDirectoryRoot, getScriptHash, getScriptCacheDirectory, ensureScriptCacheDirectory, + getScriptHash, getScriptCacheDirectory, ensureScriptCacheDirectory, withContextAndSelectors, AcceptNoTargets(..), TargetContext(..), updateContextAndWriteProjectFile, updateContextAndWriteProjectFile', fakeProjectSourcePackage, lSrcpkgDescription @@ -22,7 +22,7 @@ import Distribution.CabalSpecVersion ( CabalSpecVersion (..), cabalSpecLatest) import Distribution.Client.ProjectOrchestration import Distribution.Client.Config - ( defaultCacheDir ) + ( defaultScriptBuildsDir ) import Distribution.Client.DistDirLayout ( DistDirLayout(..) ) import Distribution.Client.HashValue @@ -120,14 +120,6 @@ import qualified Text.Parsec as P -- repl to deal with the fact that the repl is relative to the working directory and not -- the project root. --- | Get the directory where script builds are cached. --- --- @CABAL_DIR\/script-builds\/@ -getScriptCacheDirectoryRoot :: IO FilePath -getScriptCacheDirectoryRoot = do - cacheDir <- defaultCacheDir - return $ cacheDir "script-builds" - -- | Get the hash of a script's absolute path) -- -- Two hashes will be the same as long as the absolute paths @@ -138,14 +130,14 @@ getScriptHash script = showHashValue . hashValue . fromString <$> canonicalizePa -- | Get the directory for caching a script build. -- -- The only identity of a script is it's absolute path, so append the --- hashed path to @CABAL_DIR\/script-builds\/@ to get the cache directory. +-- hashed path to the @script-builds@ dir to get the cache directory. getScriptCacheDirectory :: FilePath -> IO FilePath -getScriptCacheDirectory script = () <$> getScriptCacheDirectoryRoot <*> getScriptHash script +getScriptCacheDirectory script = () <$> defaultScriptBuildsDir <*> getScriptHash script -- | Get the directory for caching a script build and ensure it exists. -- -- The only identity of a script is it's absolute path, so append the --- hashed path to @CABAL_DIR\/script-builds\/@ to get the cache directory. +-- hashed path to the @script-builds@ dir to get the cache directory. ensureScriptCacheDirectory :: Verbosity -> FilePath -> IO FilePath ensureScriptCacheDirectory verbosity script = do cacheDir <- getScriptCacheDirectory script diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs index dcfb75c382f..355a2a9de1e 100644 --- a/cabal-testsuite/src/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs @@ -839,7 +839,7 @@ getScriptCacheDirectory script = do cabalDir <- testCabalDir `fmap` getTestEnv hashinput <- liftIO $ canonicalizePath script let hash = C.unpack . Base16.encode . SHA256.hash . C.pack $ hashinput - return $ cabalDir "packages" "script-builds" hash + return $ cabalDir "script-builds" hash ------------------------------------------------------------------------ -- * Skipping tests From 341175f4ab0eea8f3c9770527d588bd887f60bdb Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 17:50:09 +0200 Subject: [PATCH 20/44] Document XDG behaviour. --- doc/cabal-commands.rst | 4 +-- doc/cabal-project.rst | 2 +- doc/config.rst | 56 ++++++++++++++++++++++++++++++++--------- doc/nix-integration.rst | 2 +- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index 37fe84ed424..f5cdcf06d1c 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -121,7 +121,7 @@ Arguments and flags common to some or all commands are: $ cabal install --allow-newer=foo:base,lens --allow-newer=bar:time Finally, one can enable :option:`--allow-newer` permanently by setting - ``allow-newer: True`` in the ``~/.cabal/config`` file. Enabling + ``allow-newer: True`` in the ``~/.config/cabal/config`` file. Enabling 'allow-newer' selectively is also supported in the config file (``allow-newer: foo, bar, baz:base``). @@ -950,7 +950,7 @@ cabal preferences. It is very useful when you are e.g. first configuring .. option:: --config-file=PATH - Specify config file path. (default: ``~/.cabal/config``). + Specify config file path. (default: ``~/.config/cabal/config``). .. option:: -f, --force diff --git a/doc/cabal-project.rst b/doc/cabal-project.rst index b9c925913b2..224b0d30def 100644 --- a/doc/cabal-project.rst +++ b/doc/cabal-project.rst @@ -24,7 +24,7 @@ The full configuration of a project is determined by combining the following sources (later entries override earlier ones, except for appendable options): -1. ``~/.cabal/config`` (the user-wide global configuration) +1. ``~/.config/cabal/config`` (the user-wide global configuration) 2. ``cabal.project`` (the project configuration) diff --git a/doc/config.rst b/doc/config.rst index 2f086637cbe..f9cff5b0d6f 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -7,7 +7,7 @@ Overview -------- The global configuration file for ``cabal-install`` is by default -``$HOME/.cabal/config``. If you do not have this file, ``cabal`` will create +``$XDG_CONFIG_HOME/cabal/config``. If you do not have this file, ``cabal`` will create it for you on the first call to ``cabal update`` (details see `configuration file discovery`_). Alternatively, you can explicitly ask ``cabal`` to create it for you using @@ -18,7 +18,7 @@ Alternatively, you can explicitly ask ``cabal`` to create it for you using You can change the location of the global configuration file by specifying either ``--config-file=FILE`` on the command line or by setting the -``CABAL_CONFIG`` environment variable. +``CABAL_CONFIG`` or ``CABAL_DIR`` environment variable. Most of the options in this configuration file are also available as command line arguments, and the corresponding documentation can be used @@ -51,16 +51,22 @@ Various environment variables affect ``cabal-install``. The variable to find global configuration file. ``CABAL_DIR`` - Default content directory for ``cabal-install`` files. - Default value is ``getXdgDirectory XdgCache "cabal"``, which is - ``$XDG_CACHE_HOME/cabal`` on unix systems and ``%APPDATA%\cabal`` in Windows. + + If set, *all* ``cabal-install`` content files will be stored as + subdirectories of this directory, including the configuration file + if ``CABAL_CONFIG`` is unset. If ``CABAL_DIR`` is unset, Cabal + will store data files according to the XDG Base Directory + Specification. .. note:: - The CABAL_DIR might be dropped in the future, when - ``cabal-install`` starts to use XDG Directory specification. + For backwards compatibility, if the directory ``~/.cabal`` on + Unix or ``%APPDATA%\cabal`` on Windows exist and ``CABAL_DIR`` + is unset, ``cabal-install`` will behave as if ``CABAL_DIR`` was + set to point at this directory. ``CABAL_BUILDDIR`` + The override for default ``dist`` build directory. Note, the nix-style builds build directory (``dist-newstyle``) is not affected by this environment variable. @@ -75,13 +81,39 @@ The configuration file location is determined as follows: 1. If option ``--config-file`` is given, use it; 2. otherwise, if ``$CABAL_CONFIG`` is set use it; 3. otherwise, if ``$CABAL_DIR`` is set use ``$CABAL_DIR/config``; -4. otherwise use ``config`` in ``getAppUserDirectory "cabal"``. +4. otherwise use ``config`` in ``$XDG_CONFIG_HOME/cabal``, which + defaults to ``~/.config/cabal`` on Unix. If the configuration file does not exist, and it was not given explicitly via ``--config-file`` or ``$CABAL_CONFIG``, then ``cabal-install`` will generate the default one, with directories -based on ``$CABAL_DIR`` (if set) or ``getAppUserDirectory "cabal"`` -prefix. +based on ``$CABAL_DIR`` (if set) or according to the XDG Base +Directory Specification. + +Directories +----------- + +Unless the ``CABAL_DIR`` environment variable is set, Cabal will store +data in directories according to the XDG Base Directory Specification. +The following directories are used: + +* ``$XDG_CONFIG_HOME/cabal`` for the main configuration file. On + Unix, this defaults to ``~/.config/cabal``, and most of the + documentation will assume this default. On Windows this defaults to + ``%APPDATA%/cabal``. Overridden by the ``CABAL_CONFIG`` environment + variable if set. + +* ``$XDG_CACHE_HOME/cabal`` for downloaded packages and script + executables. Defaults to ``~/.cache/cabal`` on Unix, and + ``%LOCALAPPDATA%`` on Windows. You can in delete this directory and + expect that its contents will be reconstructed as needed. + +* ``$XDG_STATE_HOME/cabal`` for compiled libraries and other stateful + artifacts. DEfaults to ``~/.local/state`` on Unix and + ``%LOCALAPPDATA%`` on Windows. Deleting this directory might cause + installed programs to stop working. + +* ``~/.local/bin`` for executables installed with ``cabal install``. Repository specification ------------------------ @@ -97,7 +129,7 @@ the repository to be the central Hackage server: The name of the repository is given on the first line, and can be anything; packages downloaded from this repository will be cached under -``~/.cabal/packages/hackage.haskell.org`` (or whatever name you specify; +``$XDG_CACHE_HOME/cabal/packages/hackage.haskell.org`` (or whatever name you specify; you can change the prefix by changing the value of :cfg-field:`remote-repo-cache`). If you want, you can configure multiple repositories, and ``cabal`` will combine them and be able to download @@ -214,7 +246,7 @@ thus, looks similar to a ``package-name.cabal``'s ``build-depends`` section. .. note:: The ``preferred-versions`` file can be used to restrict the package set from Hackage, by preferring certain versions or marking a specific version as deprecated. To achieve this, add a - local no-index repository to your ``~/.cabal/config``, where the directory contains your custom + local no-index repository to your ``~/.config/cabal/config``, where the directory contains your custom ``preferred-versions``. After running ``cabal update``, all ``cabal`` operations will honour the configuration. diff --git a/doc/nix-integration.rst b/doc/nix-integration.rst index 24b2a6de87b..6edf595b6f0 100644 --- a/doc/nix-integration.rst +++ b/doc/nix-integration.rst @@ -12,7 +12,7 @@ Enabling Nix Integration ------------------------ To enable Nix integration, simply pass the ``--enable-nix`` global option when you call ``cabal`` (eg. ``cabal --enable-nix v1-build``). -To use this option everywhere, edit your :ref:`global configuration file` (default: ``$HOME/.cabal/config``) to include: +To use this option everywhere, edit your :ref:`global configuration file` (default: ``~/.config/cabal/config``) to include: .. code-block:: cabal From 481d318ad6c7c9598a3ccf71f39831f2704b556a Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 17:58:37 +0200 Subject: [PATCH 21/44] Remove help text references to ~/.cabal. --- cabal-install/main/Main.hs | 2 +- .../src/Distribution/Client/CmdInstall.hs | 2 +- cabal-install/src/Distribution/Client/Config.hs | 6 +++--- cabal-install/src/Distribution/Client/HttpUtils.hs | 2 +- cabal-install/src/Distribution/Client/Install.hs | 2 +- .../src/Distribution/Client/ProjectConfig.hs | 2 +- .../Distribution/Client/ProjectConfig/Legacy.hs | 2 +- .../src/Distribution/Client/ProjectConfig/Types.hs | 2 +- .../Client/Sandbox/PackageEnvironment.hs | 4 ++-- cabal-install/src/Distribution/Client/Setup.hs | 14 +++++++------- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index a66081ad1d6..c13ca79b040 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -427,7 +427,7 @@ filterBuildFlags version config buildFlags buildNumJobs = NoFlag } buildFlags_latest = buildFlags { - -- Take the 'jobs' setting '~/.cabal/config' into account. + -- Take the 'jobs' setting config file into account. buildNumJobs = Flag . Just . determineNumJobs $ (numJobsConfigFlag `mappend` numJobsCmdLineFlag) } diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index 84fc86f65ba..fdac338c0d5 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -150,7 +150,7 @@ installCommand = CommandUI , commandDescription = Just $ \_ -> wrapText $ "Installs one or more packages. This is done by installing them " ++ "in the store and symlinking/copying the executables in the directory " - ++ "specified by the --installdir flag (`~/.cabal/bin/` by default). " + ++ "specified by the --installdir flag (`~/.local/bin/` by default). " ++ "If you want the installed executables to be available globally, " ++ "make sure that the PATH environment variable contains that directory. " ++ "\n\n" diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 1eaedfc1a92..c08ce5f1382 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -665,7 +665,7 @@ defaultRemoteRepo = RemoteRepo name uri Nothing [] 0 False str = "hackage.haskell.org" name = RepoName str uri = URI "http:" (Just (URIAuth "" str "")) "/" "" "" - -- Note that lots of old ~/.cabal/config files will have the old url + -- Note that lots of old config files will have the old url -- http://hackage.haskell.org/packages/archive -- but new config files can use the new url (without the /packages/archive) -- and avoid having to do a http redirect @@ -1459,7 +1459,7 @@ parseExtraLines verbosity extraLines = unlines (map (showPWarning "Error parsing additional config lines") ws) -- | Get the differences (as a pseudo code diff) between the user's --- '~/.cabal/config' and the one that cabal would generate if it didn't exist. +-- config file and the one that cabal would generate if it didn't exist. userConfigDiff :: Verbosity -> GlobalFlags -> [String] -> IO [String] userConfigDiff verbosity globalFlags extraLines = do userConfig <- loadRawConfig normal (globalConfigFile globalFlags) @@ -1506,7 +1506,7 @@ userConfigDiff verbosity globalFlags extraLines = do in (topAndTail left, topAndTail (drop 1 right)) --- | Update the user's ~/.cabal/config' keeping the user's customizations. +-- | Update the user's config file keeping the user's customizations. userConfigUpdate :: Verbosity -> GlobalFlags -> [String] -> IO () userConfigUpdate verbosity globalFlags extraLines = do userConfig <- loadRawConfig normal (globalConfigFile globalFlags) diff --git a/cabal-install/src/Distribution/Client/HttpUtils.hs b/cabal-install/src/Distribution/Client/HttpUtils.hs index 228c7dc44ac..54c88d97ea5 100644 --- a/cabal-install/src/Distribution/Client/HttpUtils.hs +++ b/cabal-install/src/Distribution/Client/HttpUtils.hs @@ -500,7 +500,7 @@ wgetTransport prog = warningMsg = "the 'wget' transport currently doesn't support" ++ " range requests, which wastes network bandwidth." ++ " To fix this, set 'http-transport' to 'curl' or" - ++ " 'plain-http' in '~/.cabal/config'." + ++ " 'plain-http' in '~/.config/cabal/config'." ++ " Note that the 'plain-http' transport doesn't" ++ " support HTTPS.\n" diff --git a/cabal-install/src/Distribution/Client/Install.hs b/cabal-install/src/Distribution/Client/Install.hs index fb35cc9649b..2baa8af9e49 100644 --- a/cabal-install/src/Distribution/Client/Install.hs +++ b/cabal-install/src/Distribution/Client/Install.hs @@ -197,7 +197,7 @@ install verbosity packageDBs repos comp platform progdb warn verbosity $ "--root-cmd is no longer supported, " ++ "see https://github.com/haskell/cabal/issues/3353" ++ " (if you didn't type --root-cmd, comment out root-cmd" - ++ " in your ~/.cabal/config file)" + ++ " in your ~/.config/cabal/config file)" let userOrSandbox = fromFlag (configUserInstall configFlags) unless userOrSandbox $ warn verbosity $ "the --global flag is deprecated -- " diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index e693d1aad66..f42723dc9b2 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -622,7 +622,7 @@ writeProjectConfigFile file = writeFile file . showProjectConfig --- | Read the user's @~/.cabal/config@ file. +-- | Read the user's Cabal config file. -- readGlobalConfig :: Verbosity -> Flag FilePath -> Rebuild ProjectConfig readGlobalConfig verbosity configFileFlag = do diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index 9a311dfcf3b..081dd28e7ee 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -348,7 +348,7 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag , packageConfigProgramPathExtra = packageConfigProgramPathExtra pc , packageConfigDocumentation = packageConfigDocumentation pc }) --- | Convert from the types currently used for the user-wide @~/.cabal/config@ +-- | Convert from the types currently used for the user-wide Cabal config -- file into the 'ProjectConfig' type. -- -- Only a subset of the 'ProjectConfig' can be represented in the user-wide diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs index e2a84f82d95..143e8fb1049 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs @@ -73,7 +73,7 @@ import qualified Data.Map as Map -- | This type corresponds directly to what can be written in the -- @cabal.project@ file. Other sources of configuration can also be injected --- into this type, such as the user-wide @~/.cabal/config@ file and the +-- into this type, such as the user-wide config file and the -- command line of @cabal configure@ or @cabal build@. -- -- Since it corresponds to the external project file it is an instance of diff --git a/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs b/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs index 4b7c18a2275..0d13cda1093 100644 --- a/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs +++ b/cabal-install/src/Distribution/Client/Sandbox/PackageEnvironment.hs @@ -81,7 +81,7 @@ userPackageEnvironmentFile = "cabal.config" -- | Type of the current package environment. data PackageEnvironmentType = UserPackageEnvironment -- ^ './cabal.config' - | AmbientPackageEnvironment -- ^ '~/.cabal/config' + | AmbientPackageEnvironment -- ^ '~/.config/cabal/config' -- | Is there a 'cabal.config' in this directory? classifyPackageEnvironment :: FilePath -> IO PackageEnvironmentType @@ -271,7 +271,7 @@ showPackageEnvironment :: PackageEnvironment -> String showPackageEnvironment pkgEnv = showPackageEnvironmentWithComments Nothing pkgEnv -- | Pretty-print the package environment with default values for empty fields --- commented out (just like the default ~/.cabal/config). +-- commented out (just like the default Cabal config file). showPackageEnvironmentWithComments :: (Maybe PackageEnvironment) -> PackageEnvironment -> String diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 46be79ce605..6f138200453 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -1270,7 +1270,7 @@ reportCommand = CommandUI { commandSynopsis = "Upload build reports to a remote server.", commandDescription = Nothing, commandNotes = Just $ \_ -> - "You can store your Hackage login in the ~/.cabal/config file\n", + "You can store your Hackage login in the ~/.config/cabal/config file\n", commandUsage = usageAlternatives "report" ["[FLAGS]"], commandDefaultFlags = defaultReportFlags, commandOptions = \_ -> @@ -1677,7 +1677,7 @@ installCommand = CommandUI { ++ " `v1-configure` for a list of commands being affected.\n" ++ "\n" ++ "Installed executables will by default" - ++ " be put into `~/.cabal/bin/`." + ++ " be put into `~/.local/bin/`." ++ " If you want installed executable to be available globally, make" ++ " sure that the PATH environment variable contains that directory.\n" ++ "\n", @@ -1999,7 +1999,7 @@ uploadCommand = CommandUI { commandSynopsis = "Uploads source packages or documentation to Hackage.", commandDescription = Nothing, commandNotes = Just $ \_ -> - "You can store your Hackage login in the ~/.cabal/config file\n" + "You can store your Hackage login in the ~/.config/cabal/config file\n" ++ relevantConfigValuesText ["username", "password", "password-command"], commandUsage = \pname -> "Usage: " ++ pname ++ " upload [FLAGS] TARFILES\n", @@ -2354,18 +2354,18 @@ userConfigCommand = CommandUI { commandDescription = Just $ \_ -> wrapText $ "When upgrading cabal, the set of configuration keys and their default" ++ " values may change. This command provides means to merge the existing" - ++ " config in ~/.cabal/config" + ++ " config in ~/.config/cabal/config" ++ " (i.e. all bindings that are actually defined and not commented out)" ++ " and the default config of the new version.\n" ++ "\n" - ++ "init: Creates a new config file at either ~/.cabal/config or as" + ++ "init: Creates a new config file at either ~/.config/cabal/config or as" ++ " specified by --config-file, if given. An existing file won't be " ++ " overwritten unless -f or --force is given.\n" - ++ "diff: Shows a pseudo-diff of the user's ~/.cabal/config file and" + ++ "diff: Shows a pseudo-diff of the user's ~/.config/cabal/config file and" ++ " the default configuration that would be created by cabal if the" ++ " config file did not exist.\n" ++ "update: Applies the pseudo-diff to the configuration that would be" - ++ " created by default, and write the result back to ~/.cabal/config.", + ++ " created by default, and write the result back to ~/.config/cabal/config.", commandNotes = Nothing, commandUsage = usageAlternatives "user-config" ["init", "diff", "update"], From 1b004372207cb2c8f2bef084569930a87372a0e7 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 18:00:10 +0200 Subject: [PATCH 22/44] Remove references to .cabla/bin. --- doc/cabal-commands.rst | 2 +- doc/cabal-package.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index f5cdcf06d1c..32b0920351d 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -735,7 +735,7 @@ cabal install ------------- ``cabal install [FLAGS] [TARGETS]`` builds the specified target packages and -symlinks/copies their executables in ``installdir`` (usually ``~/.cabal/bin``). +symlinks/copies their executables in ``installdir`` (usually ``~/.local/bin``). .. warning:: diff --git a/doc/cabal-package.rst b/doc/cabal-package.rst index 9ba500cf472..b9c4221eed6 100644 --- a/doc/cabal-package.rst +++ b/doc/cabal-package.rst @@ -1574,7 +1574,7 @@ in ghc's package DB and so we can figure out what the location of the library is. Foreign libraries however don't get registered, which means that we'd have to have a way of finding out where a platform library got installed (other than by searching the ``lib/`` directory). Instead, we install foreign libraries in -``~/.cabal/lib``, much like we install executables in ``~/.cabal/bin``. +``~/.cabal/lib``. Build information ^^^^^^^^^^^^^^^^^ From 52256252f3a02f1aace975d43061f6d364aea3be Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 18:07:21 +0200 Subject: [PATCH 23/44] Backwards compatible install paths. --- .../src/Distribution/Client/Config.hs | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index c08ce5f1382..faae2537e8c 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -599,6 +599,18 @@ getCabalDir = do Nothing -> defaultCabalDir Just dir -> return dir +maybeGetCabalDir :: IO (Maybe FilePath) +maybeGetCabalDir = do + mDir <- lookupEnv "CABAL_DIR" + case mDir of + Just dir -> return $ Just dir + Nothing -> do + defaultDir <- defaultCabalDir + dotCabalExists <- doesDirectoryExist defaultDir + return $ if dotCabalExists + then Just defaultDir + else Nothing + -- The default behaviour of cabal-install is to use the XDG directory -- standard. However, if CABAL_DIR is set, we instead use that -- directory as a single store for everything cabal-related, like the @@ -607,15 +619,10 @@ getCabalDir = do -- This function abstracts that decision-making. getDefaultDir :: XdgDirectory -> FilePath -> IO FilePath getDefaultDir xdg subdir = do - mDir <- lookupEnv "CABAL_DIR" + mDir <- maybeGetCabalDir case mDir of Just dir -> return $ dir subdir - Nothing -> do - defaultDir <- defaultCabalDir - dotCabalExists <- doesDirectoryExist defaultDir - if dotCabalExists - then return $ defaultDir subdir - else getXdgDirectory xdg $ "cabal" subdir + Nothing -> getXdgDirectory xdg $ "cabal" subdir defaultConfigFile :: IO FilePath defaultConfigFile = @@ -643,13 +650,23 @@ defaultReportsDir = defaultExtraPath :: IO [FilePath] defaultExtraPath = do - dir <- getHomeDirectory - return [dir ".local" "bin"] + mDir <- maybeGetCabalDir + case mDir of + Just dir -> + return [dir "bin"] + Nothing -> do + dir <- getHomeDirectory + return [dir ".local" "bin"] defaultInstallPath :: IO FilePath defaultInstallPath = do - dir <- getHomeDirectory - return (dir ".local" "bin") + mDir <- maybeGetCabalDir + case mDir of + Just dir -> + return $ dir "bin" + Nothing -> do + dir <- getHomeDirectory + return $ dir ".local" "bin" defaultCompiler :: CompilerFlavor defaultCompiler = fromMaybe GHC defaultCompilerFlavor From 51903fe1dbf0212d3a16ee246cd6e379b184bcc8 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 18:36:58 +0200 Subject: [PATCH 24/44] Remove more references to ~/.cabal. --- cabal-install/src/Distribution/Client/Manpage.hs | 2 +- cabal-install/src/Distribution/Client/SetupWrapper.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Manpage.hs b/cabal-install/src/Distribution/Client/Manpage.hs index f93c711753c..00ad6bf58fe 100644 --- a/cabal-install/src/Distribution/Client/Manpage.hs +++ b/cabal-install/src/Distribution/Client/Manpage.hs @@ -46,7 +46,7 @@ data FileInfo = FileInfo String String -- ^ path, description -- | A list of files that should be documented in the manual page. files :: [FileInfo] files = - [ (FileInfo "~/.cabal/config" "The defaults that can be overridden with command-line options.") + [ (FileInfo "~/.config/cabal/config" "The defaults that can be overridden with command-line options.") ] manpageCmd :: String -> [CommandSpec a] -> ManpageFlags -> IO () diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs index 20f20691b2e..e4885ed07c6 100644 --- a/cabal-install/src/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs @@ -240,7 +240,7 @@ data SetupScriptOptions = SetupScriptOptions { -- When we are installing in parallel, we always use the external setup -- method. Since compiling the setup script each time adds noticeable -- overhead, we use a shared setup script cache - -- ('~/.cabal/setup-exe-cache'). For each (compiler, platform, Cabal + -- ('$XDG_CACHE_HOME/cabal/setup-exe-cache'). For each (compiler, platform, Cabal -- version) combination the cache holds a compiled setup script -- executable. This only affects the Simple build type; for the Custom, -- Configure and Make build types we always compile the setup script anew. From 5ca70cf132341efbd3f59bb51dde80aa8231aeb3 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 18:37:03 +0200 Subject: [PATCH 25/44] Fix typo. --- doc/config.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/config.rst b/doc/config.rst index f9cff5b0d6f..ab18821a4d7 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -109,7 +109,7 @@ The following directories are used: expect that its contents will be reconstructed as needed. * ``$XDG_STATE_HOME/cabal`` for compiled libraries and other stateful - artifacts. DEfaults to ``~/.local/state`` on Unix and + artifacts. Defaults to ``~/.local/state`` on Unix and ``%LOCALAPPDATA%`` on Windows. Deleting this directory might cause installed programs to stop working. From b8257bfce3b064cf6086ab2bbf1b45037fa14333 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Fri, 19 Aug 2022 22:40:11 +0200 Subject: [PATCH 26/44] Fix ~/.cabal paths making their way into default config. --- Cabal/src/Distribution/Simple/InstallDirs.hs | 20 ++++++++++++--- .../src/Distribution/Client/Config.hs | 25 ++++++++++--------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Cabal/src/Distribution/Simple/InstallDirs.hs b/Cabal/src/Distribution/Simple/InstallDirs.hs index 739b87d58c9..c48f61337d0 100644 --- a/Cabal/src/Distribution/Simple/InstallDirs.hs +++ b/Cabal/src/Distribution/Simple/InstallDirs.hs @@ -59,7 +59,7 @@ import Distribution.System import Distribution.Compiler import Distribution.Simple.InstallDirs.Internal -import System.Directory (getAppUserDataDirectory) +import System.Directory (getAppUserDataDirectory, doesDirectoryExist, getHomeDirectory) import System.FilePath ( (), isPathSeparator , pathSeparator, dropDrive @@ -174,6 +174,18 @@ type InstallDirTemplates = InstallDirs PathTemplate defaultInstallDirs :: CompilerFlavor -> Bool -> Bool -> IO InstallDirTemplates defaultInstallDirs = defaultInstallDirs' False +maybeGetCabalDir :: IO (Maybe FilePath) +maybeGetCabalDir = do + mDir <- lookupEnv "CABAL_DIR" + case mDir of + Just dir -> return $ Just dir + Nothing -> do + defaultDir <- getAppUserDataDirectory "cabal" + dotCabalExists <- doesDirectoryExist defaultDir + return $ if dotCabalExists + then Just defaultDir + else Nothing + defaultInstallDirs' :: Bool {- use external internal deps -} -> CompilerFlavor -> Bool -> Bool -> IO InstallDirTemplates defaultInstallDirs' True comp userInstall hasLibs = do @@ -186,10 +198,12 @@ defaultInstallDirs' False comp userInstall _hasLibs = do installPrefix <- if userInstall then do - mDir <- lookupEnv "CABAL_DIR" + mDir <- maybeGetCabalDir case mDir of - Nothing -> getAppUserDataDirectory "cabal" Just dir -> return dir + Nothing -> do + dir <- getHomeDirectory + return $ dir ".local" else case buildOS of Windows -> do windowsProgramFilesDir <- getWindowsProgramFilesDir return (windowsProgramFilesDir "Haskell") diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index faae2537e8c..95d839f80a0 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -30,6 +30,7 @@ module Distribution.Client.Config ( defaultInstallPath, defaultLogsDir, defaultReportsDir, + defaultPrefix, defaultUserInstall, baseSavedConfig, @@ -541,7 +542,7 @@ instance Semigroup SavedConfig where -- baseSavedConfig :: IO SavedConfig baseSavedConfig = do - userPrefix <- getCabalDir + userPrefix <- defaultPrefix cacheDir <- defaultCacheDir logsDir <- defaultLogsDir return mempty { @@ -589,23 +590,13 @@ initialSavedConfig = do } } -defaultCabalDir :: IO FilePath -defaultCabalDir = getAppUserDataDirectory "cabal" - -getCabalDir :: IO FilePath -getCabalDir = do - mDir <- lookupEnv "CABAL_DIR" - case mDir of - Nothing -> defaultCabalDir - Just dir -> return dir - maybeGetCabalDir :: IO (Maybe FilePath) maybeGetCabalDir = do mDir <- lookupEnv "CABAL_DIR" case mDir of Just dir -> return $ Just dir Nothing -> do - defaultDir <- defaultCabalDir + defaultDir <- getAppUserDataDirectory "cabal" dotCabalExists <- doesDirectoryExist defaultDir return $ if dotCabalExists then Just defaultDir @@ -648,6 +639,16 @@ defaultReportsDir :: IO FilePath defaultReportsDir = getDefaultDir XdgCache "reports" +defaultPrefix :: IO FilePath +defaultPrefix = do + mDir <- maybeGetCabalDir + case mDir of + Just dir -> + return dir + Nothing -> do + dir <- getHomeDirectory + return $ dir ".local" + defaultExtraPath :: IO [FilePath] defaultExtraPath = do mDir <- maybeGetCabalDir From 3102687098dad8d117a957e74db655a8e32321b2 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sat, 20 Aug 2022 08:16:13 +0200 Subject: [PATCH 27/44] Reduce duplication. --- Cabal/src/Distribution/Simple/InstallDirs.hs | 16 ++++++++++ .../src/Distribution/Client/Config.hs | 32 +++---------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Cabal/src/Distribution/Simple/InstallDirs.hs b/Cabal/src/Distribution/Simple/InstallDirs.hs index c48f61337d0..d7705e66468 100644 --- a/Cabal/src/Distribution/Simple/InstallDirs.hs +++ b/Cabal/src/Distribution/Simple/InstallDirs.hs @@ -47,6 +47,9 @@ module Distribution.Simple.InstallDirs ( packageTemplateEnv, abiTemplateEnv, installDirsTemplateEnv, + + maybeGetCabalDir, + defaultInstallPrefix ) where import Prelude () @@ -174,6 +177,8 @@ type InstallDirTemplates = InstallDirs PathTemplate defaultInstallDirs :: CompilerFlavor -> Bool -> Bool -> IO InstallDirTemplates defaultInstallDirs = defaultInstallDirs' False +-- | If @CABAL\_DIR@ is set or @~/.cabal@ exists, return that +-- directory. maybeGetCabalDir :: IO (Maybe FilePath) maybeGetCabalDir = do mDir <- lookupEnv "CABAL_DIR" @@ -186,6 +191,17 @@ maybeGetCabalDir = do then Just defaultDir else Nothing +-- | The default prefix used for installation. +defaultInstallPrefix :: IO FilePath +defaultInstallPrefix = do + mDir <- maybeGetCabalDir + case mDir of + Just dir -> + return dir + Nothing -> do + dir <- getHomeDirectory + return $ dir ".local" + defaultInstallDirs' :: Bool {- use external internal deps -} -> CompilerFlavor -> Bool -> Bool -> IO InstallDirTemplates defaultInstallDirs' True comp userInstall hasLibs = do diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 95d839f80a0..3a1a81ff5ff 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -30,7 +30,6 @@ module Distribution.Client.Config ( defaultInstallPath, defaultLogsDir, defaultReportsDir, - defaultPrefix, defaultUserInstall, baseSavedConfig, @@ -93,7 +92,8 @@ import Distribution.Simple.Setup , Flag(..), toFlag, flagToMaybe, fromFlagOrDefault ) import Distribution.Simple.InstallDirs ( InstallDirs(..), defaultInstallDirs - , PathTemplate, toPathTemplate ) + , PathTemplate, toPathTemplate, + maybeGetCabalDir, defaultInstallPrefix) import Distribution.Deprecated.ParseUtils ( FieldDescr(..), liftField, runP , ParseResult(..), PError(..), PWarning(..) @@ -133,7 +133,7 @@ import Text.PrettyPrint import Text.PrettyPrint.HughesPJ ( text, Doc ) import System.Directory - ( createDirectoryIfMissing, getAppUserDataDirectory, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile, doesDirectoryExist ) + ( createDirectoryIfMissing, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile ) import Network.URI ( URI(..), URIAuth(..), parseURI ) import System.FilePath @@ -141,7 +141,7 @@ import System.FilePath import System.IO.Error ( isDoesNotExistError ) import Distribution.Compat.Environment - ( getEnvironment, lookupEnv ) + ( getEnvironment ) import qualified Data.Map as M import qualified Data.ByteString as BS @@ -542,7 +542,7 @@ instance Semigroup SavedConfig where -- baseSavedConfig :: IO SavedConfig baseSavedConfig = do - userPrefix <- defaultPrefix + userPrefix <- defaultInstallPrefix cacheDir <- defaultCacheDir logsDir <- defaultLogsDir return mempty { @@ -590,18 +590,6 @@ initialSavedConfig = do } } -maybeGetCabalDir :: IO (Maybe FilePath) -maybeGetCabalDir = do - mDir <- lookupEnv "CABAL_DIR" - case mDir of - Just dir -> return $ Just dir - Nothing -> do - defaultDir <- getAppUserDataDirectory "cabal" - dotCabalExists <- doesDirectoryExist defaultDir - return $ if dotCabalExists - then Just defaultDir - else Nothing - -- The default behaviour of cabal-install is to use the XDG directory -- standard. However, if CABAL_DIR is set, we instead use that -- directory as a single store for everything cabal-related, like the @@ -639,16 +627,6 @@ defaultReportsDir :: IO FilePath defaultReportsDir = getDefaultDir XdgCache "reports" -defaultPrefix :: IO FilePath -defaultPrefix = do - mDir <- maybeGetCabalDir - case mDir of - Just dir -> - return dir - Nothing -> do - dir <- getHomeDirectory - return $ dir ".local" - defaultExtraPath :: IO [FilePath] defaultExtraPath = do mDir <- maybeGetCabalDir From e21ee8d669beade26ce457283f04dd43a736688e Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sat, 20 Aug 2022 09:12:26 +0200 Subject: [PATCH 28/44] Add changelog entry. --- changelog.d/pr-7386 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 changelog.d/pr-7386 diff --git a/changelog.d/pr-7386 b/changelog.d/pr-7386 new file mode 100644 index 00000000000..7e51e22ae36 --- /dev/null +++ b/changelog.d/pr-7386 @@ -0,0 +1,31 @@ +synopsis: Switch to using XDG directories +prs: #7386 +issues: #680 +significance: significant + +description: { + +Cabal/cabal-install now uses the XDG Base Directory Specification to +store configuration, caches, and the store. Specifically, +`$XDG_CONFIG_HOME/cabal` stores the configuration file, +`$XDG_CACHE_HOME/cabal` stores downloaded packages and similar, and +`$XDG_STATE_HOME/cabal` mainly contains the store of compiled +packages. + +The `dist`/`dist-newstyle` directories are not affected. + +On Windows, these XDG paths are mapped to other (hopefully) +appropriate locations. See the Cabal User Guide for information. + +If the `CABAL_DIR` environment variable is set, the indicated +directory will be used to store all Cabal-related files, as in +previous versions. + +Backwards compatibility: If `~/.cabal` already exists, this will be +interpreted as `CABAL_DIR=~/.cabal`. This means that upgrading on an +existing system already using cabal-install should not cause any +change in behaviour. An existing system can be migrated by deleting +`~/.cabal` (possibly copying `~/.cabal/config` to +`~/.config/cabal/config` first). + +} \ No newline at end of file From d4bc491c95948d7be1d86b659f6e0455e5fbc3d9 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sat, 20 Aug 2022 10:57:27 +0200 Subject: [PATCH 29/44] Also note install dir change. --- changelog.d/pr-7386 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.d/pr-7386 b/changelog.d/pr-7386 index 7e51e22ae36..41452c2d2e7 100644 --- a/changelog.d/pr-7386 +++ b/changelog.d/pr-7386 @@ -10,7 +10,8 @@ store configuration, caches, and the store. Specifically, `$XDG_CONFIG_HOME/cabal` stores the configuration file, `$XDG_CACHE_HOME/cabal` stores downloaded packages and similar, and `$XDG_STATE_HOME/cabal` mainly contains the store of compiled -packages. +packages. Further, `cabal install will put executables in +`~/.local/bin` by default. The `dist`/`dist-newstyle` directories are not affected. From 2701a03a08a31fb4f64c477943aba0ad22edec20 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 21 Aug 2022 12:20:12 +0200 Subject: [PATCH 30/44] It is the cabal-install config file. --- cabal-install/src/Distribution/Client/ProjectConfig.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index f42723dc9b2..645ebe6f621 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -622,7 +622,7 @@ writeProjectConfigFile file = writeFile file . showProjectConfig --- | Read the user's Cabal config file. +-- | Read the user's cabal-install config file. -- readGlobalConfig :: Verbosity -> Flag FilePath -> Rebuild ProjectConfig readGlobalConfig verbosity configFileFlag = do From e990f860f2e390431d698258b4bbb8ff5d4fd960 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 21 Aug 2022 12:27:39 +0200 Subject: [PATCH 31/44] Avoid dependending on cabal-install in Hackage-tests. --- Cabal-tests/Cabal-tests.cabal | 1 - Cabal-tests/tests/HackageTests.hs | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cabal-tests/Cabal-tests.cabal b/Cabal-tests/Cabal-tests.cabal index 595abdb02af..1f6a9b6d814 100644 --- a/Cabal-tests/Cabal-tests.cabal +++ b/Cabal-tests/Cabal-tests.cabal @@ -149,7 +149,6 @@ test-suite hackage-tests , Cabal , Cabal-syntax , Cabal-tree-diff - , cabal-install , containers , deepseq , directory diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index 12a339c40c8..c70876e9d9f 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -20,12 +20,13 @@ import Data.Foldable (traverse_) import Data.List (isPrefixOf, isSuffixOf) import Data.Maybe (mapMaybe) import Data.Monoid (Sum (..)) -import Distribution.Client.Config (getConfigFilePath, defaultCacheDir) import Distribution.PackageDescription.Check (PackageCheck (..), checkPackage) import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription) import Distribution.PackageDescription.Quirks (patchQuirks) import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS) import Numeric (showFFloat) +import System.Directory (getXdgDirectory, XdgDirectory(XdgCache, XdgConfig)) +import System.Environment (lookupEnv) import System.Exit (exitFailure) import System.FilePath (()) @@ -62,16 +63,23 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact) parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool) -> (FilePath -> B.ByteString -> IO a) -> IO a parseIndex predicate action = do - configPath <- getConfigFilePath mempty + configPath <- getCabalConfigPath cfg <- B.readFile configPath cfgFields <- either (fail . show) pure $ Parsec.readFields cfg repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of - [] -> defaultCacheDir -- Default + [] -> getCacheDirPath -- Default (rrc : _) -> return rrc -- User-specified let repos = reposFromConfig cfgFields tarName repo = repoCache repo "01-index.tar" mconcat <$> traverse (parseIndex' predicate action . tarName) repos - + where + getCacheDirPath = + getXdgDirectory XdgCache $ "cabal" "packages" + getCabalConfigPath = do + mx <- lookupEnv "CABAL_CONFIG" + case mx of + Just x -> return x + Nothing -> getXdgDirectory XdgConfig $ "cabal" "config" parseIndex' :: (Monoid a, NFData a) From f9c710ab14b212094a0d8fb4adcb33f8863391f7 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 21 Aug 2022 15:24:46 +0200 Subject: [PATCH 32/44] ALso respect CABAL_DIR here. --- Cabal-tests/tests/HackageTests.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index c70876e9d9f..b78336376b7 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -24,6 +24,7 @@ import Distribution.PackageDescription.Check (PackageCheck (..), checkPack import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription) import Distribution.PackageDescription.Quirks (patchQuirks) import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS) +import Distribution.Simple.InstallDirs (maybeGetCabalDir) import Numeric (showFFloat) import System.Directory (getXdgDirectory, XdgDirectory(XdgCache, XdgConfig)) import System.Environment (lookupEnv) @@ -79,7 +80,11 @@ parseIndex predicate action = do mx <- lookupEnv "CABAL_CONFIG" case mx of Just x -> return x - Nothing -> getXdgDirectory XdgConfig $ "cabal" "config" + Nothing -> do + mDir <- maybeGetCabalDir + case mDir of + Nothing -> getXdgDirectory XdgConfig $ "cabal" "config" + Just dir -> return $ dir "config" parseIndex' :: (Monoid a, NFData a) From 909f7a5e4f431bf43ff5468ee84c45110e26cf80 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 21 Aug 2022 17:54:10 +0200 Subject: [PATCH 33/44] Try leaving InstallDirs alone. --- Cabal/src/Distribution/Simple/InstallDirs.hs | 36 ++----------------- .../src/Distribution/Client/Config.hs | 31 ++++++++++++++-- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Cabal/src/Distribution/Simple/InstallDirs.hs b/Cabal/src/Distribution/Simple/InstallDirs.hs index d7705e66468..739b87d58c9 100644 --- a/Cabal/src/Distribution/Simple/InstallDirs.hs +++ b/Cabal/src/Distribution/Simple/InstallDirs.hs @@ -47,9 +47,6 @@ module Distribution.Simple.InstallDirs ( packageTemplateEnv, abiTemplateEnv, installDirsTemplateEnv, - - maybeGetCabalDir, - defaultInstallPrefix ) where import Prelude () @@ -62,7 +59,7 @@ import Distribution.System import Distribution.Compiler import Distribution.Simple.InstallDirs.Internal -import System.Directory (getAppUserDataDirectory, doesDirectoryExist, getHomeDirectory) +import System.Directory (getAppUserDataDirectory) import System.FilePath ( (), isPathSeparator , pathSeparator, dropDrive @@ -177,31 +174,6 @@ type InstallDirTemplates = InstallDirs PathTemplate defaultInstallDirs :: CompilerFlavor -> Bool -> Bool -> IO InstallDirTemplates defaultInstallDirs = defaultInstallDirs' False --- | If @CABAL\_DIR@ is set or @~/.cabal@ exists, return that --- directory. -maybeGetCabalDir :: IO (Maybe FilePath) -maybeGetCabalDir = do - mDir <- lookupEnv "CABAL_DIR" - case mDir of - Just dir -> return $ Just dir - Nothing -> do - defaultDir <- getAppUserDataDirectory "cabal" - dotCabalExists <- doesDirectoryExist defaultDir - return $ if dotCabalExists - then Just defaultDir - else Nothing - --- | The default prefix used for installation. -defaultInstallPrefix :: IO FilePath -defaultInstallPrefix = do - mDir <- maybeGetCabalDir - case mDir of - Just dir -> - return dir - Nothing -> do - dir <- getHomeDirectory - return $ dir ".local" - defaultInstallDirs' :: Bool {- use external internal deps -} -> CompilerFlavor -> Bool -> Bool -> IO InstallDirTemplates defaultInstallDirs' True comp userInstall hasLibs = do @@ -214,12 +186,10 @@ defaultInstallDirs' False comp userInstall _hasLibs = do installPrefix <- if userInstall then do - mDir <- maybeGetCabalDir + mDir <- lookupEnv "CABAL_DIR" case mDir of + Nothing -> getAppUserDataDirectory "cabal" Just dir -> return dir - Nothing -> do - dir <- getHomeDirectory - return $ dir ".local" else case buildOS of Windows -> do windowsProgramFilesDir <- getWindowsProgramFilesDir return (windowsProgramFilesDir "Haskell") diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 3a1a81ff5ff..425e9f32431 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -48,6 +48,7 @@ module Distribution.Client.Config ( postProcessRepo, ) where +import Distribution.Compat.Environment (lookupEnv) import Distribution.Client.Compat.Prelude import Prelude () @@ -92,8 +93,7 @@ import Distribution.Simple.Setup , Flag(..), toFlag, flagToMaybe, fromFlagOrDefault ) import Distribution.Simple.InstallDirs ( InstallDirs(..), defaultInstallDirs - , PathTemplate, toPathTemplate, - maybeGetCabalDir, defaultInstallPrefix) + , PathTemplate, toPathTemplate) import Distribution.Deprecated.ParseUtils ( FieldDescr(..), liftField, runP , ParseResult(..), PError(..), PWarning(..) @@ -133,7 +133,7 @@ import Text.PrettyPrint import Text.PrettyPrint.HughesPJ ( text, Doc ) import System.Directory - ( createDirectoryIfMissing, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile ) + ( createDirectoryIfMissing, getHomeDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig, XdgState), renameFile, getAppUserDataDirectory, doesDirectoryExist ) import Network.URI ( URI(..), URIAuth(..), parseURI ) import System.FilePath @@ -590,6 +590,20 @@ initialSavedConfig = do } } +-- | If @CABAL\_DIR@ is set or @~/.cabal@ exists, return that +-- directory. +maybeGetCabalDir :: IO (Maybe FilePath) +maybeGetCabalDir = do + mDir <- lookupEnv "CABAL_DIR" + case mDir of + Just dir -> return $ Just dir + Nothing -> do + defaultDir <- getAppUserDataDirectory "cabal" + dotCabalExists <- doesDirectoryExist defaultDir + return $ if dotCabalExists + then Just defaultDir + else Nothing + -- The default behaviour of cabal-install is to use the XDG directory -- standard. However, if CABAL_DIR is set, we instead use that -- directory as a single store for everything cabal-related, like the @@ -603,6 +617,17 @@ getDefaultDir xdg subdir = do Just dir -> return $ dir subdir Nothing -> getXdgDirectory xdg $ "cabal" subdir +-- | The default prefix used for installation. +defaultInstallPrefix :: IO FilePath +defaultInstallPrefix = do + mDir <- maybeGetCabalDir + case mDir of + Just dir -> + return dir + Nothing -> do + dir <- getHomeDirectory + return $ dir ".local" + defaultConfigFile :: IO FilePath defaultConfigFile = getDefaultDir XdgConfig "config" From 200738706257469ff9229a21675b922d040c8151 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 21 Aug 2022 18:36:16 +0200 Subject: [PATCH 34/44] Also need duplication here. --- Cabal-tests/tests/HackageTests.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index b78336376b7..df27938d221 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -24,9 +24,8 @@ import Distribution.PackageDescription.Check (PackageCheck (..), checkPack import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription) import Distribution.PackageDescription.Quirks (patchQuirks) import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS) -import Distribution.Simple.InstallDirs (maybeGetCabalDir) import Numeric (showFFloat) -import System.Directory (getXdgDirectory, XdgDirectory(XdgCache, XdgConfig)) +import System.Directory (getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), getAppUserDataDirectory, doesDirectoryExist) import System.Environment (lookupEnv) import System.Exit (exitFailure) import System.FilePath (()) @@ -85,6 +84,18 @@ parseIndex predicate action = do case mDir of Nothing -> getXdgDirectory XdgConfig $ "cabal" "config" Just dir -> return $ dir "config" + maybeGetCabalDir :: IO (Maybe FilePath) + maybeGetCabalDir = do + mDir <- lookupEnv "CABAL_DIR" + case mDir of + Just dir -> return $ Just dir + Nothing -> do + defaultDir <- getAppUserDataDirectory "cabal" + dotCabalExists <- doesDirectoryExist defaultDir + return $ if dotCabalExists + then Just defaultDir + else Nothing + parseIndex' :: (Monoid a, NFData a) From a08ba7bbce73e192ee06908ad9d770eaf302e8b5 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 24 Aug 2022 13:35:33 +0200 Subject: [PATCH 35/44] Add missing newline. --- changelog.d/pr-7386 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/pr-7386 b/changelog.d/pr-7386 index 41452c2d2e7..36c81b21e65 100644 --- a/changelog.d/pr-7386 +++ b/changelog.d/pr-7386 @@ -29,4 +29,4 @@ change in behaviour. An existing system can be migrated by deleting `~/.cabal` (possibly copying `~/.cabal/config` to `~/.config/cabal/config` first). -} \ No newline at end of file +} From 770551836f2273d0188bf513fd2df24098b986bf Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 24 Aug 2022 13:37:10 +0200 Subject: [PATCH 36/44] Fix doc typos. --- doc/config.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index ab18821a4d7..6798a1c5bc7 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -105,13 +105,13 @@ The following directories are used: * ``$XDG_CACHE_HOME/cabal`` for downloaded packages and script executables. Defaults to ``~/.cache/cabal`` on Unix, and - ``%LOCALAPPDATA%`` on Windows. You can in delete this directory and - expect that its contents will be reconstructed as needed. + ``%LOCALAPPDATA%/cabal`` on Windows. You can delete this directory + and expect that its contents will be reconstructed as needed. * ``$XDG_STATE_HOME/cabal`` for compiled libraries and other stateful - artifacts. Defaults to ``~/.local/state`` on Unix and - ``%LOCALAPPDATA%`` on Windows. Deleting this directory might cause - installed programs to stop working. + artifacts. Defaults to ``~/.local/state/cabal`` on Unix and + ``%LOCALAPPDATA%/cabal`` on Windows. Deleting this directory might + cause installed programs to stop working. * ``~/.local/bin`` for executables installed with ``cabal install``. From 727aa4d580d6fa59311f10eefc088d3a4212cfd5 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 18 Sep 2022 13:01:30 +0200 Subject: [PATCH 37/44] Make this a Haddock comment. --- cabal-install/src/Distribution/Client/Config.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 425e9f32431..8ef898eae86 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -604,12 +604,12 @@ maybeGetCabalDir = do then Just defaultDir else Nothing --- The default behaviour of cabal-install is to use the XDG directory --- standard. However, if CABAL_DIR is set, we instead use that --- directory as a single store for everything cabal-related, like the --- old ~/.cabal behaviour. Also, for backwards compatibility, if --- ~/.cabal exists we treat that as equivalent to CABAL_DIR being set. --- This function abstracts that decision-making. +-- | The default behaviour of cabal-install is to use the XDG +-- directory standard. However, if @CABAL_DIR@ is set, we instead use +-- that directory as a single store for everything cabal-related, like +-- the old @~/.cabal@ behaviour. Also, for backwards compatibility, +-- if @~/.cabal@ exists we treat that as equivalent to @CABAL_DIR@ +-- being set. This function abstracts that decision-making. getDefaultDir :: XdgDirectory -> FilePath -> IO FilePath getDefaultDir xdg subdir = do mDir <- maybeGetCabalDir From 927442e81c619ef8ce2ea3ce4207a78d73be64fc Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Mon, 19 Sep 2022 11:07:22 +0200 Subject: [PATCH 38/44] Revision field must not be null. --- bootstrap/linux-8.10.7.json | 2 +- bootstrap/linux-8.6.5.json | 2 +- bootstrap/linux-8.8.4.json | 2 +- bootstrap/linux-9.0.2.json | 2 +- bootstrap/linux-9.2.3.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bootstrap/linux-8.10.7.json b/bootstrap/linux-8.10.7.json index b852f5e1854..a27028a1e3b 100644 --- a/bootstrap/linux-8.10.7.json +++ b/bootstrap/linux-8.10.7.json @@ -2,7 +2,7 @@ "dependencies": [ { "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, + "revision": 0, "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", "flags": [], "package": "directory", diff --git a/bootstrap/linux-8.6.5.json b/bootstrap/linux-8.6.5.json index f95aa856c8f..4b6d7d16c6f 100644 --- a/bootstrap/linux-8.6.5.json +++ b/bootstrap/linux-8.6.5.json @@ -2,7 +2,7 @@ "dependencies": [ { "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, + "revision": 0, "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", "flags": [], "package": "directory", diff --git a/bootstrap/linux-8.8.4.json b/bootstrap/linux-8.8.4.json index b87d5f63295..c9a6c9c5ea1 100644 --- a/bootstrap/linux-8.8.4.json +++ b/bootstrap/linux-8.8.4.json @@ -2,7 +2,7 @@ "dependencies": [ { "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, + "revision": 0, "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", "flags": [], "package": "directory", diff --git a/bootstrap/linux-9.0.2.json b/bootstrap/linux-9.0.2.json index 68652c2d5ef..753984e7016 100644 --- a/bootstrap/linux-9.0.2.json +++ b/bootstrap/linux-9.0.2.json @@ -2,7 +2,7 @@ "dependencies": [ { "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, + "revision": 0, "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", "flags": [], "package": "directory", diff --git a/bootstrap/linux-9.2.3.json b/bootstrap/linux-9.2.3.json index cea47336119..98d7d689c1f 100644 --- a/bootstrap/linux-9.2.3.json +++ b/bootstrap/linux-9.2.3.json @@ -2,7 +2,7 @@ "dependencies": [ { "cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590", - "revision": null, + "revision": 0, "src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd", "flags": [], "package": "directory", From e6e23e7b78fef51bf1f686816e448510fc16b6dc Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 21 Sep 2022 17:18:59 +0200 Subject: [PATCH 39/44] Link directories. --- doc/config.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/config.rst b/doc/config.rst index 6798a1c5bc7..2a197a153b1 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -56,7 +56,7 @@ Various environment variables affect ``cabal-install``. subdirectories of this directory, including the configuration file if ``CABAL_CONFIG`` is unset. If ``CABAL_DIR`` is unset, Cabal will store data files according to the XDG Base Directory - Specification. + Specification (see `directories`_). .. note:: @@ -90,6 +90,8 @@ explicitly via ``--config-file`` or ``$CABAL_CONFIG``, then based on ``$CABAL_DIR`` (if set) or according to the XDG Base Directory Specification. +.. _directories: + Directories ----------- From 24a19dc23dd8ace3408d8cc55220bede4ada062b Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 21 Sep 2022 17:21:24 +0200 Subject: [PATCH 40/44] Update doc/config.rst Co-authored-by: Artem Pelenitsyn --- doc/config.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/config.rst b/doc/config.rst index 2a197a153b1..bbc65f725d6 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -95,7 +95,7 @@ Directory Specification. Directories ----------- -Unless the ``CABAL_DIR`` environment variable is set, Cabal will store +Unless the ``CABAL_DIR`` environment variable is set or `~/.cabal` exists, Cabal will store data in directories according to the XDG Base Directory Specification. The following directories are used: From f8f47f34f892d07da75ddc36246353ba713932ee Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 21 Sep 2022 17:35:09 +0200 Subject: [PATCH 41/44] No need for this. --- cabal-install/src/Distribution/Client/ProjectOrchestration.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/ProjectOrchestration.hs b/cabal-install/src/Distribution/Client/ProjectOrchestration.hs index 83eb723e7ae..ccbd84d43c3 100644 --- a/cabal-install/src/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/src/Distribution/Client/ProjectOrchestration.hs @@ -138,7 +138,6 @@ import qualified Distribution.Client.BuildReports.Anonymous as BuildReports import qualified Distribution.Client.BuildReports.Storage as BuildReports ( storeLocal ) -import Distribution.Client.Config () import Distribution.Client.HttpUtils import Distribution.Client.Setup hiding (packageName) import Distribution.Compiler From b41d9ba993a48bfed78bdb2b74d9cc2f9c5a4dde Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 21 Sep 2022 18:06:07 +0200 Subject: [PATCH 42/44] We install foreign libraries here now. --- doc/cabal-package.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/cabal-package.rst b/doc/cabal-package.rst index b9c4221eed6..ef236aeb586 100644 --- a/doc/cabal-package.rst +++ b/doc/cabal-package.rst @@ -1574,7 +1574,7 @@ in ghc's package DB and so we can figure out what the location of the library is. Foreign libraries however don't get registered, which means that we'd have to have a way of finding out where a platform library got installed (other than by searching the ``lib/`` directory). Instead, we install foreign libraries in -``~/.cabal/lib``. +``~/.local/lib``. Build information ^^^^^^^^^^^^^^^^^ From 12d3e113157c6825f961b899d8e0be0ad0c1ba43 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 21 Sep 2022 18:15:07 +0200 Subject: [PATCH 43/44] Clarify Nothing case. --- cabal-install/src/Distribution/Client/Config.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 8ef898eae86..023d6a6fdbc 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -591,7 +591,11 @@ initialSavedConfig = do } -- | If @CABAL\_DIR@ is set or @~/.cabal@ exists, return that --- directory. +-- directory. Otherwise returns Nothing. If this function returns +-- Nothing, then it implies that we are not using a single directory +-- for everything, but instead use XDG paths. Fundamentally, this +-- function is used to implement transparent backwards compatibility +-- with pre-XDG versions of cabal-install. maybeGetCabalDir :: IO (Maybe FilePath) maybeGetCabalDir = do mDir <- lookupEnv "CABAL_DIR" From f976ebd9b49cd3b9b33a23686888e5b187949e0f Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Wed, 21 Sep 2022 19:15:46 +0200 Subject: [PATCH 44/44] Avoid using ~/.config/cabal in manual. --- doc/cabal-commands.rst | 2 +- doc/cabal-project.rst | 2 +- doc/config.rst | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index 151a7f95eab..7671e41cdf9 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -121,7 +121,7 @@ Arguments and flags common to some or all commands are: $ cabal install --allow-newer=foo:base,lens --allow-newer=bar:time Finally, one can enable :option:`--allow-newer` permanently by setting - ``allow-newer: True`` in the ``~/.config/cabal/config`` file. Enabling + ``allow-newer: True`` in the :ref:`config file `. Enabling 'allow-newer' selectively is also supported in the config file (``allow-newer: foo, bar, baz:base``). diff --git a/doc/cabal-project.rst b/doc/cabal-project.rst index 224b0d30def..fc328c2b3c7 100644 --- a/doc/cabal-project.rst +++ b/doc/cabal-project.rst @@ -24,7 +24,7 @@ The full configuration of a project is determined by combining the following sources (later entries override earlier ones, except for appendable options): -1. ``~/.config/cabal/config`` (the user-wide global configuration) +1. :ref:`The user-wide global configuration ` (default: ``~/.config/cabal/config``) 2. ``cabal.project`` (the project configuration) diff --git a/doc/config.rst b/doc/config.rst index bbc65f725d6..a97b954037e 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -88,7 +88,7 @@ If the configuration file does not exist, and it was not given explicitly via ``--config-file`` or ``$CABAL_CONFIG``, then ``cabal-install`` will generate the default one, with directories based on ``$CABAL_DIR`` (if set) or according to the XDG Base -Directory Specification. +Directory Specification, as listed below. .. _directories: @@ -100,8 +100,7 @@ data in directories according to the XDG Base Directory Specification. The following directories are used: * ``$XDG_CONFIG_HOME/cabal`` for the main configuration file. On - Unix, this defaults to ``~/.config/cabal``, and most of the - documentation will assume this default. On Windows this defaults to + Unix, this defaults to ``~/.config/cabal``. On Windows this defaults to ``%APPDATA%/cabal``. Overridden by the ``CABAL_CONFIG`` environment variable if set. @@ -248,7 +247,8 @@ thus, looks similar to a ``package-name.cabal``'s ``build-depends`` section. .. note:: The ``preferred-versions`` file can be used to restrict the package set from Hackage, by preferring certain versions or marking a specific version as deprecated. To achieve this, add a - local no-index repository to your ``~/.config/cabal/config``, where the directory contains your custom + local no-index repository to your :ref:`configuration file `, + where the directory contains your custom ``preferred-versions``. After running ``cabal update``, all ``cabal`` operations will honour the configuration.