aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--CabalHelper/Compile.hs71
-rw-r--r--cabal-helper.cabal55
-rw-r--r--tests/Spec.hs41
4 files changed, 109 insertions, 62 deletions
diff --git a/.travis.yml b/.travis.yml
index 10fb2bd..ae37669 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,7 +16,6 @@ cache:
directories:
- ~/.cabal
- ~/.ghc
- - ~/.ghc-mod
- ~/.stack
install:
@@ -25,7 +24,6 @@ install:
- echo $PATH
- which cabal
- cabal install -j --only-dependencies --enable-tests
- - git clone --depth=1 https://github.com/haskell/cabal.git /tmp/cabal
- if [ -n "$(ghc --version | awk '{ print $8 }' | sed -n '/^7.4/p')" ]; then cabal install Cabal --constraint "Cabal == 1.16.*"; fi
@@ -46,5 +44,3 @@ script:
- cabal build
- ./dist/build/cabal-helper-wrapper/cabal-helper-wrapper . dist "compiler-version" "entrypoints" "source-dirs" "ghc-options" "ghc-src-options" "ghc-pkg-options" "ghc-lang-options"
- ./dist/build/spec/spec
- # At least try to compile with Cabal HEAD
- - ghc -i -i/tmp/cabal/Cabal -i. CabalHelper/Main.hs -odir /tmp/cabal/Cabal -DCABAL_MAJOR=1 -DCABAL_MINOR=1000
diff --git a/CabalHelper/Compile.hs b/CabalHelper/Compile.hs
index 59bb48c..f84b2e8 100644
--- a/CabalHelper/Compile.hs
+++ b/CabalHelper/Compile.hs
@@ -51,7 +51,7 @@ data Compile = Compile {
compCabalHelperSourceDir :: FilePath,
compCabalSourceDir :: Maybe FilePath,
compPackageDb :: Maybe FilePath,
- compCabalVersion :: Version,
+ compCabalVersion :: Either String Version,
compPackageDeps :: [String]
}
@@ -111,7 +111,7 @@ compileHelper opts cabalVer projdir distdir = withHelperSources $ \chdir -> do
case db_exists of
False -> mzero
True -> do
- db <- liftIO $ getPrivateCabalPkgDb opts cabalVer
+ db <- liftIO $ getPrivateCabalPkgDb opts (showVersion cabalVer)
vLog opts $ logMsg ++ "private package-db in " ++ db
liftIO $ compileWithPkg chdir (Just db) cabalVer
@@ -143,10 +143,10 @@ compileHelper opts cabalVer projdir distdir = withHelperSources $ \chdir -> do
compileWithPkg chdir (Just db) cabalVer
compileWithCabalTree chdir ver srcDir =
- compile distdir opts $ Compile chdir (Just srcDir) Nothing ver []
+ compile distdir opts $ Compile chdir (Just srcDir) Nothing (Right ver) []
compileWithPkg chdir mdb ver =
- compile distdir opts $ Compile chdir Nothing mdb ver [cabalPkgId ver]
+ compile distdir opts $ Compile chdir Nothing mdb (Right ver) [cabalPkgId ver]
cabalPkgId v = "Cabal-" ++ showVersion v
@@ -167,7 +167,9 @@ compile distdir opts@Options {..} Compile {..} = do
vLog opts $ "outdir: " ++ outdir
vLog opts $ "exedir: " ++ exedir
- let Version (mj:mi:_) _ = compCabalVersion
+ let (mj, mi) = case compCabalVersion of
+ Left _commitid -> (1, 10000)
+ Right (Version (x:y:_) _) -> (x, y)
let ghc_opts =
concat [
[ "-outputdir", outdir
@@ -204,12 +206,15 @@ compile distdir opts@Options {..} Compile {..} = do
ExitSuccess -> Right exe
e@(ExitFailure _) -> Left e
-exePath :: Version -> IO FilePath
+exePath :: Either String Version -> IO FilePath
exePath compCabalVersion = do
exePath' compCabalVersion <$> appDataDir
-exePath' :: Version-> FilePath -> FilePath
-exePath' compCabalVersion outdir =
+exePath' :: Either String Version -> FilePath -> FilePath
+exePath' (Left commitid) outdir =
+ outdir </> "cabal-helper-" ++ showVersion version -- our ver
+ ++ "-Cabal-HEAD-" ++ commitid
+exePath' (Right compCabalVersion) outdir =
outdir </> "cabal-helper-" ++ showVersion version -- our ver
++ "-Cabal-" ++ showVersion compCabalVersion
@@ -255,12 +260,20 @@ installCabal opts ver = do
mpatch :: Maybe (FilePath -> IO ())
mpatch = snd <$> find ((ver`elem`) . fst) patchyCabalVersions
msrcdir <- sequenceA $ unpackPatchedCabal opts ver tmpdir <$> mpatch
- db <- createPkgDb opts ver
- cabalInstall opts db ver msrcdir
+ db <- createPkgDb opts (showVersion ver)
+ cabalInstall opts db (maybe (Right ver) Left msrcdir)
return db
-cabalInstall :: Options -> FilePath -> Version -> Maybe FilePath -> IO ()
-cabalInstall opts db ver msrcdir = do
+installCabalHEAD :: Options -> IO (FilePath, String)
+installCabalHEAD opts = do
+ withSystemTempDirectory "cabal-helper" $ \tmpdir -> do
+ (srcdir, commit) <- unpackCabalHEAD tmpdir
+ db <- createPkgDb opts commit
+ cabalInstall opts db (Left srcdir)
+ return (db, commit)
+
+cabalInstall :: Options -> FilePath -> Either FilePath Version -> IO ()
+cabalInstall opts db e_ver_msrcdir = do
cabalInstallVer <- cabalInstallVersion opts
cabal_opts <- return $ concat
[
@@ -277,12 +290,12 @@ cabalInstall opts db ver msrcdir = do
then [ "--with-ghc-pkg=" ++ ghcPkgProgram opts ]
else []
,
- case msrcdir of
- Nothing ->
+ case e_ver_msrcdir of
+ Right ver ->
[ "install", "Cabal"
, "--constraint", "Cabal == " ++ showVersion ver
]
- Just srcdir ->
+ Left srcdir ->
[ "install", srcdir ]
]
@@ -340,14 +353,26 @@ patchyCabalVersions = [
unpackPatchedCabal ::
Options -> Version -> FilePath -> (FilePath -> IO ()) -> IO FilePath
unpackPatchedCabal opts cabalVer tmpdir patch = do
+ dir <- unpackCabal opts cabalVer tmpdir
+ patch dir
+ return dir
+
+unpackCabal ::
+ Options -> Version -> FilePath -> IO FilePath
+unpackCabal opts cabalVer tmpdir = do
let cabal = "Cabal-" ++ showVersion cabalVer
dir = tmpdir </> cabal
-
callProcessStderr (Just tmpdir) (cabalProgram opts) [ "get", cabal ]
-
- patch dir
return dir
+unpackCabalHEAD :: FilePath -> IO (FilePath, String)
+unpackCabalHEAD tmpdir = do
+ let dir = tmpdir </> "cabal-head.git"
+ url = "https://github.com/haskell/cabal.git"
+ ExitSuccess <- rawSystem "git" [ "clone", "--depth=1", url, dir]
+ commit <- trim <$> readProcess "git" ["rev-parse", "HEAD"] ""
+ return (dir </> "Cabal", commit)
+
errorInstallCabal :: Version -> FilePath -> a
errorInstallCabal cabalVer _distdir = panic $ printf "\
\Installing Cabal version %s failed.\n\
@@ -385,7 +410,7 @@ errorInstallCabal cabalVer _distdir = panic $ printf "\
cachedExe :: Version -> IO (Maybe FilePath)
cachedExe compCabalVersion = do
- exe <- exePath compCabalVersion
+ exe <- exePath (Right compCabalVersion)
exists <- doesFileExist exe
return $ if exists then Just exe else Nothing
@@ -403,7 +428,7 @@ listCabalVersions' Options {..} mdb = do
cabalPkgDbExists :: Options -> Version -> IO Bool
cabalPkgDbExists opts ver = do
- db <- getPrivateCabalPkgDb opts ver
+ db <- getPrivateCabalPkgDb opts (showVersion ver)
dexists <- doesDirectoryExist db
case dexists of
False -> return False
@@ -427,18 +452,18 @@ cabalInstallVersion Options {..} = do
trim :: String -> String
trim = dropWhileEnd isSpace
-createPkgDb :: Options -> Version -> IO FilePath
+createPkgDb :: Options -> String -> IO FilePath
createPkgDb opts@Options {..} ver = do
db <- getPrivateCabalPkgDb opts ver
exists <- doesDirectoryExist db
when (not exists) $ callProcessStderr Nothing ghcPkgProgram ["init", db]
return db
-getPrivateCabalPkgDb :: Options -> Version -> IO FilePath
+getPrivateCabalPkgDb :: Options -> String -> IO FilePath
getPrivateCabalPkgDb opts ver = do
appdir <- appDataDir
ghcVer <- ghcVersion opts
- return $ appdir </> "Cabal-" ++ showVersion ver ++ "-db-" ++ showVersion ghcVer
+ return $ appdir </> "Cabal-" ++ ver ++ "-db-" ++ showVersion ghcVer
-- | Find @version: XXX@ delcaration in a cabal file
cabalFileVersion :: String -> Version
diff --git a/cabal-helper.cabal b/cabal-helper.cabal
index 58bac7b..4d18a71 100644
--- a/cabal-helper.cabal
+++ b/cabal-helper.cabal
@@ -49,7 +49,7 @@ library
default-language: Haskell2010
GHC-Options: -Wall
Build-Depends: base >= 4.5 && < 5
- , Cabal >= 1.14 && < 1.25
+ , Cabal >= 1.14 && < 1.26
, directory
, filepath
, transformers
@@ -73,7 +73,7 @@ Executable cabal-helper-wrapper
X-Install-Target: $libexecdir
Build-Depends: base >= 4.5 && < 5
, bytestring
- , Cabal >= 1.14 && < 1.25
+ , Cabal >= 1.14 && < 1.26
, directory
, filepath
, process
@@ -83,22 +83,6 @@ Executable cabal-helper-wrapper
, utf8-string
, ghc-prim
-Executable cabal-helper-main
- if flag(dev)
- Buildable: True
- else
- Buildable: False
- Default-Language: Haskell98
- Main-Is: CabalHelper/Main.hs
- Other-Modules:
- GHC-Options: -Wall -fno-warn-unused-imports -optP-DCABAL_MAJOR=1 -optP-DCABAL_MINOR=24 -optP-DCABAL_HELPER=1 -optP-DCABAL_HELPER_DEV=1
- Build-Depends: base
- , Cabal
- , containers
- , bytestring
- , filepath
- , directory
-
Test-Suite spec
Default-Language: Haskell2010
Type: exitcode-stdio-1.0
@@ -118,7 +102,7 @@ Test-Suite spec
, cabal-helper
, extra
, unix
- , Cabal >= 1.14 && < 1.25
+ , Cabal >= 1.14 && < 1.26
, directory
, filepath
, transformers
@@ -130,7 +114,32 @@ Test-Suite spec
, template-haskell
, temporary
-flag dev
- description: Build development components
- default: False
- manual: True \ No newline at end of file
+custom-setup
+ setup-depends: base,
+ Cabal,
+ filepath
+
+-- TODO: Use cabal_macros.h to replace -D flags by including it in
+-- CabalHelper.Data
+--
+-- Executable cabal-helper-main
+-- if flag(dev)
+-- Buildable: True
+-- else
+-- Buildable: False
+-- Default-Language: Haskell2010
+-- Default-Extensions: NondecreasingIndentation
+-- Main-Is: CabalHelper/Main.hs
+-- Other-Modules:
+-- GHC-Options: -Wall -fno-warn-unused-imports -optP-DCABAL_MAJOR=1 -optP-DCABAL_MINOR=25 -optP-DCABAL_HELPER=1 -optP-DCABAL_HELPER_DEV=1
+-- Build-Depends: base
+-- , Cabal
+-- , containers
+-- , bytestring
+-- , filepath
+-- , directory
+--
+-- flag dev
+-- description: Build development components
+-- default: False
+-- manual: True
diff --git a/tests/Spec.hs b/tests/Spec.hs
index ca09760..bade29c 100644
--- a/tests/Spec.hs
+++ b/tests/Spec.hs
@@ -14,6 +14,7 @@ import CabalHelper.Common
import CabalHelper.Compile
import CabalHelper.Types
+
main :: IO ()
main = do
flip (setEnv "HOME") True =<< fromMaybe "/tmp" <$> lookupEnv "TMPDIR"
@@ -21,8 +22,11 @@ main = do
writeAutogenFiles' $ defaultQueryEnv "." "./dist"
- let vers :: [(Version, [Version])]
- vers = map (parseVer *** map parseVer) [
+ let parseVer' "HEAD" = Left HEAD
+ parseVer' v = Right $ parseVer v
+
+ let vers :: [(Version, [Either HEAD Version])]
+ vers = map (parseVer *** map parseVer') [
("7.4", [ -- "1.14.0" -- not supported at runtime
]),
@@ -57,6 +61,7 @@ main = do
, "1.22.4.0"
, "1.22.5.0"
, "1.22.6.0"
+ , "HEAD"
]),
("8.0", [
])
@@ -64,7 +69,7 @@ main = do
ghcVer <- majorVer <$> ghcVersion defaultOptions
- let cabalVers = concat $ map snd $ dropWhile ((<ghcVer) . fst) vers
+ let cabalVers = reverse $ concat $ map snd $ dropWhile ((<ghcVer) . fst) vers
rvs <- mapM compilePrivatePkgDb cabalVers
@@ -75,16 +80,28 @@ main = do
isLeft' (Left _) = True
isLeft' (Right _) = False
-compilePrivatePkgDb :: Version -> IO (Either ExitCode FilePath)
-compilePrivatePkgDb cabalVer = do
+data HEAD = HEAD deriving (Show)
+
+compilePrivatePkgDb :: Either HEAD Version -> IO (Either ExitCode FilePath)
+compilePrivatePkgDb (Left HEAD) = do
+ _ <- rawSystem "rm" [ "-r", "/tmp/.ghc-mod" ]
+ (db, commit) <- installCabalHEAD defaultOptions { verbose = True } `E.catch`
+ \(SomeException ex) -> error $ "Inslling cabal HEAD failed: " ++ show ex
+ compileWithPkg "." (Just db) (Left commit)
+compilePrivatePkgDb (Right cabalVer) = do
_ <- rawSystem "rm" [ "-r", "/tmp/.ghc-mod" ]
- db <- installCabal defaultOptions cabalVer `E.catch`
- \(SomeException _) -> errorInstallCabal cabalVer "dist"
- compileWithPkg "." (Just db) cabalVer
+ db <- installCabal defaultOptions { verbose = True } cabalVer `E.catch`
+ \(SomeException _) -> errorInstallCabal cabalVer "dist"
+ compileWithPkg "." (Just db) (Right cabalVer)
-compileWithPkg :: FilePath -> Maybe FilePath -> Version -> IO (Either ExitCode FilePath)
+compileWithPkg :: FilePath
+ -> Maybe FilePath
+ -> Either String Version
+ -> IO (Either ExitCode FilePath)
compileWithPkg chdir mdb ver =
- compile "dist" defaultOptions $ Compile chdir Nothing mdb ver [cabalPkgId ver]
+ compile "dist" defaultOptions { verbose = True } $
+ Compile chdir Nothing mdb ver [cabalPkgId ver]
-cabalPkgId :: Version -> String
-cabalPkgId v = "Cabal-" ++ showVersion v
+cabalPkgId :: Either String Version -> String
+cabalPkgId (Left _commitid) = "Cabal"
+cabalPkgId (Right v) = "Cabal-" ++ showVersion v