Skip to content

Commit

Permalink
Add CABAL_DIR environment variable for specifying the cabal directory.
Browse files Browse the repository at this point in the history
CABAL_DIR can be used to run integration tests independently on Windows,
since setting HOME doesn't affect the location of the APPDATA directory.
  • Loading branch information
grayjay committed Mar 31, 2018
1 parent a631206 commit d44329f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
7 changes: 6 additions & 1 deletion Cabal/Distribution/Simple/InstallDirs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Distribution.Client.Config (
showConfigWithComments,
parseConfig,

defaultCabalDir,
getCabalDir,
defaultConfigFile,
defaultCacheDir,
defaultCompiler,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -431,7 +431,7 @@ instance Semigroup SavedConfig where
--
baseSavedConfig :: IO SavedConfig
baseSavedConfig = do
userPrefix <- defaultCabalDir
userPrefix <- getCabalDir
cacheDir <- defaultCacheDir
logsDir <- defaultLogsDir
worldFile <- defaultWorldFile
Expand Down Expand Up @@ -481,40 +481,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
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -171,7 +171,7 @@ establishProjectBaseContext :: Verbosity
-> IO ProjectBaseContext
establishProjectBaseContext verbosity cliConfig = do

cabalDir <- defaultCabalDir
cabalDir <- getCabalDir
projectRoot <- either throwIO return =<<
findProjectRoot Nothing mprojectFile

Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ++ "-"
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Upload.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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
Expand Down Expand Up @@ -1463,7 +1463,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)
Expand Down

0 comments on commit d44329f

Please sign in to comment.