Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt XDG Base Directory Specification #7386

Merged
merged 56 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9c1624e
Move towards using XDG directories.
athas May 9, 2021
8dc18d5
Merge branch 'master' into xdg
Mikolaj Jun 25, 2021
aadd47c
Install binaries in $HOME/.local/bin.
athas Jun 25, 2021
813c4ee
Fix tests.
athas Jun 25, 2021
39ad396
Ensure config file is where it should be.
athas Sep 4, 2021
90e6c82
Merge branch 'master' into xdg
athas Sep 4, 2021
ada65b1
Merge branch 'master' into xdg
athas Aug 18, 2022
299ab6c
Require newer directory for XdgState.
athas Aug 18, 2022
787ddca
Put world file in XDG_STATE_HOME.
athas Aug 18, 2022
6642663
Oops, forgot to import.
athas Aug 18, 2022
d5a10e9
Remove uses of getCabalDir.
athas Aug 18, 2022
70b1214
These all need directory-1.3.7.0 now.
athas Aug 18, 2022
28febc3
Oh right, not a builtin anymore.
athas Aug 18, 2022
f11619a
Try it by hand.
athas Aug 18, 2022
899718e
Haskell is better than JSON.
athas Aug 18, 2022
4cb1d86
Bump directory in all jsons.
athas Aug 18, 2022
a3d4676
Put directory first.
athas Aug 19, 2022
8c6cc67
Let us assume that getConfigFilePath gets this right.
athas Aug 19, 2022
eda8190
Implement backwards compatibility.
athas Aug 19, 2022
2d97c74
This is now elsewhere.
athas Aug 19, 2022
cb3016f
We need to create parents as well because ~/.local might not exist.
athas Aug 19, 2022
b4e97fe
Put scripts-build in distinct cache directory.
athas Aug 19, 2022
4d2da83
Merge branch 'master' into xdg
athas Aug 19, 2022
341175f
Document XDG behaviour.
athas Aug 19, 2022
481d318
Remove help text references to ~/.cabal.
athas Aug 19, 2022
1b00437
Remove references to .cabla/bin.
athas Aug 19, 2022
5225625
Backwards compatible install paths.
athas Aug 19, 2022
51903fe
Remove more references to ~/.cabal.
athas Aug 19, 2022
5ca70cf
Fix typo.
athas Aug 19, 2022
b8257bf
Fix ~/.cabal paths making their way into default config.
athas Aug 19, 2022
3102687
Reduce duplication.
athas Aug 20, 2022
e21ee8d
Add changelog entry.
athas Aug 20, 2022
d4bc491
Also note install dir change.
athas Aug 20, 2022
2701a03
It is the cabal-install config file.
athas Aug 21, 2022
e990f86
Avoid dependending on cabal-install in Hackage-tests.
athas Aug 21, 2022
f9c710a
ALso respect CABAL_DIR here.
athas Aug 21, 2022
909f7a5
Try leaving InstallDirs alone.
athas Aug 21, 2022
2007387
Also need duplication here.
athas Aug 21, 2022
4e18f0e
Merge branch 'master' into xdg
athas Aug 22, 2022
a08ba7b
Add missing newline.
athas Aug 24, 2022
7705518
Fix doc typos.
athas Aug 24, 2022
4bbcfd6
Merge remote-tracking branch 'origin/master' into xdg
athas Sep 2, 2022
c71a5fd
Merge branch 'master' into xdg
athas Sep 2, 2022
8098a68
Merge branch 'master' into xdg
athas Sep 15, 2022
727aa4d
Make this a Haddock comment.
athas Sep 18, 2022
b259a2d
Merge branch 'master' into xdg
athas Sep 19, 2022
927442e
Revision field must not be null.
athas Sep 19, 2022
e6e23e7
Link directories.
athas Sep 21, 2022
24a19dc
Update doc/config.rst
athas Sep 21, 2022
f8f47f3
No need for this.
athas Sep 21, 2022
b41d9ba
We install foreign libraries here now.
athas Sep 21, 2022
12d3e11
Clarify Nothing case.
athas Sep 21, 2022
f976ebd
Avoid using ~/.config/cabal in manual.
athas Sep 21, 2022
3596dbb
Merge branch 'master' into xdg
athas Sep 30, 2022
14e414d
Merge remote-tracking branch 'athas/xdg' into xdg
athas Sep 30, 2022
c47c691
Merge branch 'master' into xdg
Mikolaj Sep 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 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 (getAppUserDataDirectory)
import System.Directory (getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), getAppUserDataDirectory, doesDirectoryExist)
import System.Environment (lookupEnv)
import System.Exit (exitFailure)
import System.FilePath ((</>))
Expand Down Expand Up @@ -63,27 +63,38 @@ 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 <- getCabalConfigPath
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
getCabalDir = do
mx <- lookupEnv "CABAL_DIR"
case mx of
Just x -> return x
Nothing -> getAppUserDataDirectory "cabal"
getCabalConfigPath cabalDir = do
getCacheDirPath =
getXdgDirectory XdgCache $ "cabal" </> "packages"
getCabalConfigPath = do
mx <- lookupEnv "CABAL_CONFIG"
case mx of
Just x -> return x
Nothing -> return (cabalDir </> "config")
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


parseIndex'
Expand Down
13 changes: 9 additions & 4 deletions bootstrap/linux-8.10.7.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"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 @@ -352,10 +361,6 @@
"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: 9 additions & 4 deletions bootstrap/linux-8.6.5.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"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 @@ -363,10 +372,6 @@
"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: 9 additions & 4 deletions bootstrap/linux-8.8.4.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"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 @@ -363,10 +372,6 @@
"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: 9 additions & 4 deletions bootstrap/linux-9.0.2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"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 @@ -352,10 +361,6 @@
"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: 9 additions & 4 deletions bootstrap/linux-9.2.3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"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 @@ -355,10 +364,6 @@
"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 @@ -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,
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 '~/.cabal/config' into account.
-- Take the 'jobs' setting config file 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 <- getScriptCacheDirectoryRoot
cacheDir <- defaultScriptBuildsDir
existsCD <- doesDirectoryExist cacheDir
caches <- if existsCD then listDirectory cacheDir else return []
paths <- fmap concat . forM caches $ \cache -> do
Expand Down
13 changes: 6 additions & 7 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, getCabalDir, loadConfig, SavedConfig(..) )
( defaultInstallPath, 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 (`~/.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"
Expand Down Expand Up @@ -254,7 +254,6 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe
withoutProject globalConfig = do
tss <- traverse (parseWithoutProjectTargetSelector verbosity) targetStrings'

cabalDir <- getCabalDir
let
projectConfig = globalConfig <> cliConfig

Expand All @@ -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
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 False installdir
createDirectoryIfMissingVerbose verbosity True installdir
warnIfNoExes verbosity buildCtx

installMethod <- flagElim defaultMethod return $
Expand Down Expand Up @@ -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.
Expand Down
Loading