Commit a343dee1 authored by kristenk's avatar kristenk Committed by Mikhail Glushenkov
Browse files

Add CABAL_DIR environment variable for specifying the cabal directory.

CABAL_DIR can be used to run integration tests independently on Windows,
since setting HOME doesn't affect the location of the APPDATA directory.
parent f7758909
......@@ -51,6 +51,7 @@ module Distribution.Simple.InstallDirs (
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Compat.Environment (lookupEnv)
import Distribution.Package
import Distribution.System
import Distribution.Compiler
......@@ -181,7 +182,11 @@ defaultInstallDirs' True comp userInstall hasLibs = do
defaultInstallDirs' False comp userInstall _hasLibs = do
installPrefix <-
if userInstall
then getAppUserDataDirectory "cabal"
then do
mDir <- lookupEnv "CABAL_DIR"
case mDir of
Nothing -> getAppUserDataDirectory "cabal"
Just dir -> return dir
else case buildOS of
Windows -> do windowsProgramFilesDir <- getWindowsProgramFilesDir
return (windowsProgramFilesDir </> "Haskell")
......
......@@ -32,7 +32,7 @@ import Distribution.Client.ProjectConfig.Types
, projectConfigBuildOnly, projectConfigDistDir
, projectConfigConfigFile )
import Distribution.Client.Config
( defaultCabalDir )
( getCabalDir )
import Distribution.Client.ProjectConfig
( readGlobalConfig, resolveBuildTimeSettings )
import Distribution.Client.DistDirLayout
......@@ -250,7 +250,7 @@ establishDummyProjectBaseContext
-> IO ProjectBaseContext
establishDummyProjectBaseContext verbosity cliConfig tmpDir localPackages = do
cabalDir <- defaultCabalDir
cabalDir <- getCabalDir
-- Create the dist directories
createDirectoryIfMissingVerbose verbosity True $ distDirectory distDirLayout
......
......@@ -22,7 +22,7 @@ module Distribution.Client.Config (
showConfigWithComments,
parseConfig,
defaultCabalDir,
getCabalDir,
defaultConfigFile,
defaultCacheDir,
defaultCompiler,
......@@ -124,7 +124,7 @@ import System.FilePath
import System.IO.Error
( isDoesNotExistError )
import Distribution.Compat.Environment
( getEnvironment )
( getEnvironment, lookupEnv )
import Distribution.Compat.Exception
( catchIO )
import qualified Paths_cabal_install
......@@ -432,7 +432,7 @@ instance Semigroup SavedConfig where
--
baseSavedConfig :: IO SavedConfig
baseSavedConfig = do
userPrefix <- defaultCabalDir
userPrefix <- getCabalDir
cacheDir <- defaultCacheDir
logsDir <- defaultLogsDir
worldFile <- defaultWorldFile
......@@ -482,40 +482,45 @@ initialSavedConfig = do
}
}
--TODO: misleading, there's no way to override this default
-- either make it possible or rename to simply getCabalDir.
defaultCabalDir :: IO FilePath
defaultCabalDir = getAppUserDataDirectory "cabal"
getCabalDir :: IO FilePath
getCabalDir = do
mDir <- lookupEnv "CABAL_DIR"
case mDir of
Nothing -> defaultCabalDir
Just dir -> return dir
defaultConfigFile :: IO FilePath
defaultConfigFile = do
dir <- defaultCabalDir
dir <- getCabalDir
return $ dir </> "config"
defaultCacheDir :: IO FilePath
defaultCacheDir = do
dir <- defaultCabalDir
dir <- getCabalDir
return $ dir </> "packages"
defaultLogsDir :: IO FilePath
defaultLogsDir = do
dir <- defaultCabalDir
dir <- getCabalDir
return $ dir </> "logs"
-- | Default position of the world file
defaultWorldFile :: IO FilePath
defaultWorldFile = do
dir <- defaultCabalDir
dir <- getCabalDir
return $ dir </> "world"
defaultExtraPath :: IO [FilePath]
defaultExtraPath = do
dir <- defaultCabalDir
dir <- getCabalDir
return [dir </> "bin"]
defaultSymlinkPath :: IO FilePath
defaultSymlinkPath = do
dir <- defaultCabalDir
dir <- getCabalDir
return (dir </> "bin")
defaultCompiler :: CompilerFlavor
......
......@@ -80,7 +80,7 @@ import Distribution.Client.Setup
, ConfigFlags(..), configureCommand, filterConfigureFlags
, ConfigExFlags(..), InstallFlags(..) )
import Distribution.Client.Config
( defaultCabalDir, defaultUserInstall )
( getCabalDir, defaultUserInstall )
import Distribution.Client.Sandbox.Timestamp
( withUpdateTimestamps )
import Distribution.Client.Sandbox.Types
......@@ -858,7 +858,7 @@ postInstallActions verbosity
storeDetailedBuildReports :: Verbosity -> FilePath
-> [(BuildReports.BuildReport, Maybe Repo)] -> IO ()
storeDetailedBuildReports verbosity logsDir reports = sequence_
[ do dotCabal <- defaultCabalDir
[ do dotCabal <- getCabalDir
let logFileName = display (BuildReports.package report) <.> "log"
logFile = logsDir </> logFileName
reportsDir = dotCabal </> "reports" </> remoteRepoName remoteRepo
......
......@@ -115,7 +115,7 @@ import Distribution.Client.TargetSelector
, ComponentKind(..), componentKind
, readTargetSelectors, reportTargetSelectorProblems )
import Distribution.Client.DistDirLayout
import Distribution.Client.Config (defaultCabalDir)
import Distribution.Client.Config (getCabalDir)
import Distribution.Client.Setup hiding (packageName)
import Distribution.Types.ComponentName
( componentNameString )
......@@ -171,7 +171,7 @@ establishProjectBaseContext :: Verbosity
-> IO ProjectBaseContext
establishProjectBaseContext verbosity cliConfig = do
cabalDir <- defaultCabalDir
cabalDir <- getCabalDir
projectRoot <- either throwIO return =<<
findProjectRoot Nothing mprojectFile
......
......@@ -75,7 +75,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import qualified Distribution.InstalledPackageInfo as IPI
import Distribution.Client.Types
import Distribution.Client.Config
( defaultCabalDir )
( getCabalDir )
import Distribution.Client.IndexUtils
( getInstalledPackages )
import Distribution.Client.JobControl
......@@ -780,7 +780,7 @@ getExternalSetupMethod verbosity options pkg bt = do
cachedSetupDirAndProg :: SetupScriptOptions -> Version
-> IO (FilePath, FilePath)
cachedSetupDirAndProg options' cabalLibVersion = do
cabalDir <- defaultCabalDir
cabalDir <- getCabalDir
let setupCacheDir = cabalDir </> "setup-exe-cache"
cachedSetupProgFile = setupCacheDir
</> ("setup-" ++ buildTypeString ++ "-"
......
......@@ -172,7 +172,7 @@ report verbosity repoCtxt mUsername mPassword = do
repos = repoContextRepos repoCtxt
remoteRepos = mapMaybe maybeRepoRemote repos
forM_ remoteRepos $ \remoteRepo ->
do dotCabal <- defaultCabalDir
do dotCabal <- getCabalDir
let srcDir = dotCabal </> "reports" </> remoteRepoName remoteRepo
-- We don't want to bomb out just because we haven't built any packages
-- from this repo yet.
......
......@@ -10,7 +10,7 @@ module IntegrationTests2 where
import Distribution.Client.DistDirLayout
import Distribution.Client.ProjectConfig
import Distribution.Client.Config (defaultCabalDir)
import Distribution.Client.Config (getCabalDir)
import Distribution.Client.TargetSelector hiding (DirActions(..))
import qualified Distribution.Client.TargetSelector as TS (DirActions(..))
import Distribution.Client.ProjectPlanning
......@@ -1466,7 +1466,7 @@ type ProjDetails = (DistDirLayout,
configureProject :: FilePath -> ProjectConfig -> IO ProjDetails
configureProject testdir cliConfig = do
cabalDir <- defaultCabalDir
cabalDir <- getCabalDir
let cabalDirLayout = defaultCabalDirLayout cabalDir
projectRootDir <- canonicalizePath (basedir </> testdir)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment