Skip to content

Commit

Permalink
Revert "Adopt XDG Base Directory Specification (haskell#7386)"
Browse files Browse the repository at this point in the history
This reverts commit 9f7dc55.
  • Loading branch information
Miezhiko committed Dec 22, 2022
1 parent a750248 commit 7e23660
Show file tree
Hide file tree
Showing 31 changed files with 153 additions and 293 deletions.
37 changes: 13 additions & 24 deletions Cabal-tests/tests/HackageTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescriptio
import Distribution.PackageDescription.Quirks (patchQuirks)
import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS)
import Numeric (showFFloat)
import System.Directory (getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), getAppUserDataDirectory, doesDirectoryExist)
import System.Directory (getAppUserDataDirectory)
import System.Environment (lookupEnv)
import System.Exit (exitFailure)
import System.FilePath ((</>))
Expand Down Expand Up @@ -63,38 +63,27 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact)
parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool)
-> (FilePath -> B.ByteString -> IO a) -> IO a
parseIndex predicate action = do
configPath <- getCabalConfigPath
cabalDir <- getCabalDir
configPath <- getCabalConfigPath cabalDir
cfg <- B.readFile configPath
cfgFields <- either (fail . show) pure $ Parsec.readFields cfg
repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of
[] -> getCacheDirPath -- 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
getCacheDirPath =
getXdgDirectory XdgCache $ "cabal" </> "packages"
getCabalConfigPath = do
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 -> do
mDir <- maybeGetCabalDir
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
Nothing -> return (cabalDir </> "config")


parseIndex'
Expand Down
13 changes: 4 additions & 9 deletions bootstrap/linux-8.10.7.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"dependencies": [
{
"cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590",
"revision": 0,
"src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd",
"flags": [],
"package": "directory",
"source": "hackage",
"version": "1.3.7.1"
},
{
"cabal_sha256": null,
"revision": null,
Expand Down Expand Up @@ -361,6 +352,10 @@
"package": "unix",
"version": "2.7.2.2"
},
{
"package": "directory",
"version": "1.3.6.0"
},
{
"package": "transformers",
"version": "0.5.6.2"
Expand Down
13 changes: 4 additions & 9 deletions bootstrap/linux-8.6.5.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"dependencies": [
{
"cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590",
"revision": 0,
"src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd",
"flags": [],
"package": "directory",
"source": "hackage",
"version": "1.3.7.1"
},
{
"cabal_sha256": null,
"revision": null,
Expand Down Expand Up @@ -372,6 +363,10 @@
"package": "unix",
"version": "2.7.2.2"
},
{
"package": "directory",
"version": "1.3.3.0"
},
{
"package": "transformers",
"version": "0.5.6.2"
Expand Down
13 changes: 4 additions & 9 deletions bootstrap/linux-8.8.4.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"dependencies": [
{
"cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590",
"revision": 0,
"src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd",
"flags": [],
"package": "directory",
"source": "hackage",
"version": "1.3.7.1"
},
{
"cabal_sha256": null,
"revision": null,
Expand Down Expand Up @@ -372,6 +363,10 @@
"package": "unix",
"version": "2.7.2.2"
},
{
"package": "directory",
"version": "1.3.6.0"
},
{
"package": "transformers",
"version": "0.5.6.2"
Expand Down
13 changes: 4 additions & 9 deletions bootstrap/linux-9.0.2.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"dependencies": [
{
"cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590",
"revision": 0,
"src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd",
"flags": [],
"package": "directory",
"source": "hackage",
"version": "1.3.7.1"
},
{
"cabal_sha256": null,
"revision": null,
Expand Down Expand Up @@ -361,6 +352,10 @@
"package": "unix",
"version": "2.7.2.2"
},
{
"package": "directory",
"version": "1.3.6.2"
},
{
"package": "transformers",
"version": "0.5.6.2"
Expand Down
13 changes: 4 additions & 9 deletions bootstrap/linux-9.2.3.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"dependencies": [
{
"cabal_sha256": "1125a0a4be3aafc8da208940f219d4e4df8a0db87d892cc42bb369071855c590",
"revision": 0,
"src_sha256": "dc2785d6548cec2e80700fab007d3e9467f65d3c58ab3efa21b34d9017cf0efd",
"flags": [],
"package": "directory",
"source": "hackage",
"version": "1.3.7.1"
},
{
"cabal_sha256": null,
"revision": null,
Expand Down Expand Up @@ -364,6 +355,10 @@
"package": "unix",
"version": "2.7.2.2"
},
{
"package": "directory",
"version": "1.3.6.2"
},
{
"package": "transformers",
"version": "0.5.6.2"
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ library
bytestring >= 0.10.6.0 && < 0.12,
containers >= 0.5.6.2 && < 0.7,
cryptohash-sha256 >= 0.11 && < 0.12,
directory >= 1.3.7.0 && < 1.4,
directory >= 1.2.2.0 && < 1.4,
echo >= 0.1.3 && < 0.2,
edit-distance >= 0.2.2 && < 0.3,
exceptions >= 0.10.4 && < 0.11,
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ filterBuildFlags version config buildFlags
buildNumJobs = NoFlag
}
buildFlags_latest = buildFlags {
-- Take the 'jobs' setting config file into account.
-- Take the 'jobs' setting '~/.cabal/config' into account.
buildNumJobs = Flag . Just . determineNumJobs $
(numJobsConfigFlag `mappend` numJobsCmdLineFlag)
}
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/CmdClean.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 <- defaultScriptBuildsDir
cacheDir <- getScriptCacheDirectoryRoot
existsCD <- doesDirectoryExist cacheDir
caches <- if existsCD then listDirectory cacheDir else return []
paths <- fmap concat . forM caches $ \cache -> do
Expand Down
13 changes: 7 additions & 6 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Distribution.Simple.BuildPaths
import Distribution.Simple.Program.Find
( ProgramSearchPathEntry(..) )
import Distribution.Client.Config
( defaultInstallPath, loadConfig, SavedConfig(..) )
( defaultInstallPath, getCabalDir, loadConfig, SavedConfig(..) )
import qualified Distribution.Simple.PackageIndex as PI
import Distribution.Solver.Types.PackageIndex
( lookupPackageName, searchByName )
Expand Down Expand Up @@ -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 (`~/.local/bin/` by default). "
++ "specified by the --installdir flag (`~/.cabal/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"
Expand Down Expand Up @@ -254,6 +254,7 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe
withoutProject globalConfig = do
tss <- traverse (parseWithoutProjectTargetSelector verbosity) targetStrings'

cabalDir <- getCabalDir
let
projectConfig = globalConfig <> cliConfig

Expand All @@ -267,9 +268,8 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe

mlogsDir = flagToMaybe projectConfigLogsDir
mstoreDir = flagToMaybe projectConfigStoreDir
cabalDirLayout <- mkCabalDirLayout mstoreDir mlogsDir
cabalDirLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir

let
buildSettings = resolveBuildTimeSettings
verbosity cabalDirLayout
projectConfig
Expand Down Expand Up @@ -605,7 +605,7 @@ installExes verbosity baseCtx buildCtx platform compiler
installdir <- fromFlagOrDefault
(warn verbosity installdirUnknown >> pure installPath) $
pure <$> cinstInstalldir clientInstallFlags
createDirectoryIfMissingVerbose verbosity True installdir
createDirectoryIfMissingVerbose verbosity False installdir
warnIfNoExes verbosity buildCtx

installMethod <- flagElim defaultMethod return $
Expand Down Expand Up @@ -912,10 +912,11 @@ getPackageDbStack
-> Flag FilePath
-> IO PackageDBStack
getPackageDbStack compilerId storeDirFlag logsDirFlag = do
cabalDir <- getCabalDir
mstoreDir <- traverse makeAbsolute $ flagToMaybe storeDirFlag
let
mlogsDir = flagToMaybe logsDirFlag
cabalLayout <- mkCabalDirLayout mstoreDir mlogsDir
cabalLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir
pure $ storePackageDBStack (cabalStoreDirLayout cabalLayout) compilerId

-- | This defines what a 'TargetSelector' means for the @bench@ command.
Expand Down
Loading

0 comments on commit 7e23660

Please sign in to comment.