aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2016-09-16 00:09:31 +0200
committerDaniel Gröber <dxld@darkboxed.org>2017-09-18 01:41:49 +0200
commite877c5b10c9e42f4e709b30929f55d6cb3b60524 (patch)
treefac73fbaf3e691c8134ba4406e93839807ab52bb
parent2a2c305c395cffbee8bfa84fdc372466a0ea257f (diff)
Use $XDG_CACHE_HOME instead of '.ghc-mod' (Fix DanielG/ghc-mod#833)
-rw-r--r--CabalHelper/Compiletime/Compile.hs8
-rw-r--r--CabalHelper/Compiletime/Wrapper.hs5
-rw-r--r--CabalHelper/Shared/Common.hs16
3 files changed, 21 insertions, 8 deletions
diff --git a/CabalHelper/Compiletime/Compile.hs b/CabalHelper/Compiletime/Compile.hs
index 8da3802..0af950d 100644
--- a/CabalHelper/Compiletime/Compile.hs
+++ b/CabalHelper/Compiletime/Compile.hs
@@ -151,7 +151,7 @@ compileHelper opts cabalVer projdir distdir = do
compile :: FilePath -> Options -> Compile -> IO (Either ExitCode FilePath)
compile distdir opts@Options {..} Compile {..} = do
cnCabalSourceDir <- canonicalizePath `traverse` compCabalSourceDir
- appdir <- appDataDir
+ appdir <- appCacheDir
let (outdir, exedir, exe, mchsrcdir) =
case cnCabalSourceDir of
@@ -250,7 +250,7 @@ processFailedException fn exe args rv =
installCabal :: Options -> Version -> IO FilePath
installCabal opts ver = do
- appdir <- appDataDir
+ appdir <- appCacheDir
let sver = showVersion ver
hPutStr stderr $ printf "\
\cabal-helper-wrapper: Installing a private copy of Cabal because we couldn't\n\
@@ -435,7 +435,7 @@ errorInstallCabal cabalVer _distdir = panic $ printf "\
cachedExe :: Version -> IO (Maybe FilePath)
cachedExe compCabalVersion = do
- appdir <- appDataDir
+ appdir <- appCacheDir
let exe = appdir </> exeName (Right compCabalVersion)
exists <- doesFileExist exe
return $ if exists then Just exe else Nothing
@@ -487,7 +487,7 @@ createPkgDb opts@Options {..} cabalVer = do
getPrivateCabalPkgDb :: Options -> Either String Version -> IO FilePath
getPrivateCabalPkgDb opts cabalVer = do
- appdir <- appDataDir
+ appdir <- appCacheDir
ghcVer <- ghcVersion opts
return $ appdir </> exeName cabalVer ++ "-ghc" ++ showVersion ghcVer ++ ".package-db"
diff --git a/CabalHelper/Compiletime/Wrapper.hs b/CabalHelper/Compiletime/Wrapper.hs
index d002886..dccbc29 100644
--- a/CabalHelper/Compiletime/Wrapper.hs
+++ b/CabalHelper/Compiletime/Wrapper.hs
@@ -51,7 +51,7 @@ usage = do
hPutStr stderr $ "Usage: " ++ prog ++ " " ++ usageMsg
where
usageMsg = "\
-\( print-appdatadir\n\
+\( print-appcachedir\n\
\| print-build-platform\n\
\| [--verbose]\n\
\ [--with-ghc=GHC_PATH]\n\
@@ -124,7 +124,8 @@ main = handlePanic $ do
[] -> usage
"help":[] -> usage
"version":[] -> putStrLn $ showVersion version
- "print-appdatadir":[] -> putStrLn =<< appDataDir
+ "print-appdatadir":[] -> putStrLn =<< appCacheDir
+ "print-appcachedir":[] -> putStrLn =<< appCacheDir
"print-build-platform":[] -> putStrLn $ display buildPlatform
projdir:_distdir:"package-id":[] -> do
diff --git a/CabalHelper/Shared/Common.hs b/CabalHelper/Shared/Common.hs
index 3d79f90..588cd03 100644
--- a/CabalHelper/Shared/Common.hs
+++ b/CabalHelper/Shared/Common.hs
@@ -29,6 +29,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import System.Environment
import System.IO
+import qualified System.Info
import System.Exit
import System.Directory
import System.FilePath
@@ -84,8 +85,19 @@ runReadP p i = case filter ((=="") . snd) $ readP_to_S p i of
(a,""):[] -> a
_ -> error $ "Error parsing: " ++ show i
-appDataDir :: IO FilePath
-appDataDir = (</> "cabal-helper") <$> getAppUserDataDirectory "ghc-mod"
+appCacheDir :: IO FilePath
+appCacheDir =
+ (</> "ghc-mod") <$> getEnvDefault "XDG_CACHE_HOME" (homeRel cache)
+ where
+ getEnvDefault var def = lookupEnv var >>= \m -> case m of Nothing -> def; Just x -> return x
+ homeRel path = (</> path) <$> getHomeDirectory
+ cache =
+ case System.Info.os of
+ "mingw32" -> windowsCache
+ _ -> unixCache
+
+ windowsCache = "Local Settings" </> "Cache"
+ unixCache = ".cache"
isCabalFile :: FilePath -> Bool
isCabalFile f = takeExtension' f == ".cabal"