aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Distribution/Helper.hs20
-rw-r--r--lib/Distribution/Helper/Discover.hs6
-rw-r--r--src/CabalHelper/Compiletime/Types.hs12
-rw-r--r--tests/GhcSession.hs2
4 files changed, 22 insertions, 18 deletions
diff --git a/lib/Distribution/Helper.hs b/lib/Distribution/Helper.hs
index c7ffe63..98afbd3 100644
--- a/lib/Distribution/Helper.hs
+++ b/lib/Distribution/Helper.hs
@@ -220,8 +220,8 @@ projConf (ProjLocV1Dir pkgdir) =
projConf (ProjLocV1CabalFile cabal_file _) = return $
ProjConfV1 cabal_file
projConf (ProjLocV2Dir projdir_path) =
- projConf $ ProjLocV2File $ projdir_path </> "cabal.project"
-projConf (ProjLocV2File proj_file) = return $
+ projConf $ ProjLocV2File (projdir_path </> "cabal.project") projdir_path
+projConf (ProjLocV2File proj_file _) = return $
ProjConfV2
{ pcV2CabalProjFile = proj_file
, pcV2CabalProjLocalFile = proj_file <.> "local"
@@ -380,9 +380,8 @@ shallowReconfigureProject QueryEnv
, qeDistDir = DistDirCabal SCV1 _distdirv1 } =
return ()
shallowReconfigureProject QueryEnv
- { qeProjLoc = ProjLocV2File projfile
+ { qeProjLoc = ProjLocV2File projfile projdir
, qeDistDir = DistDirCabal SCV2 _distdirv2, .. } = do
- let projdir = takeDirectory projfile
_ <- qeCallProcess (Just projdir) [] (cabalProgram qePrograms)
["new-build", "--dry-run", "--project-file="++projfile, "all"]
return ()
@@ -405,7 +404,7 @@ reconfigureUnit :: QueryEnvI c pt -> Unit pt -> IO ()
reconfigureUnit QueryEnv{qeDistDir=(DistDirCabal SCV1 _), ..} Unit{uPackageDir=_} = do
return ()
reconfigureUnit
- QueryEnv{qeProjLoc=ProjLocV2File projfile, ..}
+ QueryEnv{qeProjLoc=ProjLocV2File projfile _projdir, ..}
Unit{uPackageDir, uImpl}
= do
_ <- qeCallProcess (Just uPackageDir) [] (cabalProgram qePrograms)
@@ -687,7 +686,7 @@ mkCompHelperEnv
ProjInfo{piCabalVersion}
= CompHelperEnv
{ cheCabalVer = CabalVersion piCabalVersion
- , cheProjDir = plV1Dir projloc
+ , cheProjDir = plCabalProjectDir projloc
, cheProjLocalCacheDir = distdir
, chePkgDb = Nothing
, chePlanJson = Nothing
@@ -697,14 +696,9 @@ mkCompHelperEnv
projloc
(DistDirCabal SCV2 distdir)
ProjInfo{piImpl=ProjInfoV2{piV2Plan=plan}}
- = case projloc of
- ProjLocV2Dir projdir ->
- let cheProjDir = projdir in
- CompHelperEnv {..}
- ProjLocV2File proj_file ->
- let cheProjDir = takeDirectory proj_file in
- CompHelperEnv {..}
+ = CompHelperEnv {..}
where
+ cheProjDir = plCabalProjectDir projloc
cheCabalVer = CabalVersion $ makeDataVersion pjCabalLibVersion
cheProjLocalCacheDir = distdir </> "cache"
chePkgDb = Nothing
diff --git a/lib/Distribution/Helper/Discover.hs b/lib/Distribution/Helper/Discover.hs
index 9e6a7ca..93346f5 100644
--- a/lib/Distribution/Helper/Discover.hs
+++ b/lib/Distribution/Helper/Discover.hs
@@ -55,7 +55,7 @@ findProjects :: FilePath -> IO [Ex ProjLoc]
findProjects dir = execWriterT $ do
let cabalProject = dir </> "cabal.project"
whenM (liftIO $ doesFileExist cabalProject) $
- tell [Ex $ ProjLocV2File cabalProject]
+ tell [Ex $ ProjLocV2File cabalProject dir]
let stackYaml = dir </> "stack.yaml"
whenM (liftIO $ doesFileExist stackYaml) $
tell [Ex $ ProjLocStackYaml stackYaml]
@@ -74,8 +74,8 @@ getDefaultDistDir (ProjLocV1CabalFile _cabal_file pkgdir) =
DistDirCabal SCV1 $ pkgdir </> "dist"
getDefaultDistDir (ProjLocV1Dir pkgdir) =
DistDirCabal SCV1 $ pkgdir </> "dist"
-getDefaultDistDir (ProjLocV2File cabal_project) =
- DistDirCabal SCV2 $ replaceFileName cabal_project "dist-newstyle"
+getDefaultDistDir (ProjLocV2File cabal_project projdir) =
+ DistDirCabal SCV2 $ projdir </> "dist-newstyle"
getDefaultDistDir (ProjLocV2Dir projdir) =
DistDirCabal SCV2 $ projdir </> "dist-newstyle"
getDefaultDistDir (ProjLocStackYaml _) =
diff --git a/src/CabalHelper/Compiletime/Types.hs b/src/CabalHelper/Compiletime/Types.hs
index b30e107..748b8d1 100644
--- a/src/CabalHelper/Compiletime/Types.hs
+++ b/src/CabalHelper/Compiletime/Types.hs
@@ -32,6 +32,7 @@ import Data.IORef
import Data.Version
import Data.Typeable
import GHC.Generics
+import System.FilePath (takeDirectory)
import System.Posix.Types
import CabalHelper.Compiletime.Types.RelativePath
import CabalHelper.Shared.InterfaceTypes
@@ -146,7 +147,7 @@ data ProjLoc (pt :: ProjType) where
-- configuration file then points to the packages that make up this
-- project. This corresponds to the @--cabal-project=PATH@ flag on the
-- @cabal@ command line.
- ProjLocV2File :: { plCabalProjectFile :: !FilePath } -> ProjLoc ('Cabal 'CV2)
+ ProjLocV2File :: { plCabalProjectFile :: !FilePath, plProjectDirV2 :: !FilePath } -> ProjLoc ('Cabal 'CV2)
-- | This is equivalent to 'ProjLocV2File' but using the default
-- @cabal.project@ file name.
@@ -164,6 +165,15 @@ plV1Dir :: ProjLoc ('Cabal 'CV1) -> FilePath
plV1Dir ProjLocV1CabalFile {plProjectDirV1} = plProjectDirV1
plV1Dir ProjLocV1Dir {plProjectDirV1} = plProjectDirV1
+plCabalProjectDir :: ProjLoc ('Cabal cpt) -> FilePath
+plCabalProjectDir ProjLocV1CabalFile {plProjectDirV1} = plProjectDirV1
+plCabalProjectDir ProjLocV1Dir {plProjectDirV1} = plProjectDirV1
+plCabalProjectDir ProjLocV2File {plProjectDirV2} = plProjectDirV2
+plCabalProjectDir ProjLocV2Dir {plProjectDirV2} = plProjectDirV2
+
+plStackProjectDir :: ProjLoc 'Stack -> FilePath
+plStackProjectDir ProjLocStackYaml {plStackYaml} = takeDirectory plStackYaml
+
projTypeOfProjLoc :: ProjLoc pt -> SProjType pt
projTypeOfProjLoc ProjLocV1CabalFile{} = SCabal SCV1
projTypeOfProjLoc ProjLocV1Dir{} = SCabal SCV1
diff --git a/tests/GhcSession.hs b/tests/GhcSession.hs
index 39680a6..a963ae4 100644
--- a/tests/GhcSession.hs
+++ b/tests/GhcSession.hs
@@ -465,7 +465,7 @@ newBuildProjSetup :: ProjSetup0
newBuildProjSetup = ProjSetupDescr "cabal-v2" $ Right $ Ex $ ProjSetupImpl
{ psiProjType = SCabal SCV2
, psiDistDir = \dir -> DistDirCabal SCV2 (dir </> "dist-newstyle")
- , psiProjLoc = \_cabal_file projdir -> ProjLocV2File $ projdir </> "cabal.project"
+ , psiProjLoc = \_cabal_file projdir -> ProjLocV2File (projdir </> "cabal.project") projdir
-- TODO: check if cabal.project is there and only use
-- V2File then, also remove addCabalProject below so we
-- cover both cases.