aboutsummaryrefslogtreecommitdiff
path: root/src/CabalHelper/Compiletime/Cabal.hs
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2020-01-11 07:46:33 +0100
committerDaniel Gröber <dxld@darkboxed.org>2020-01-11 07:51:18 +0100
commit04c2d34f1874bc198288d33c784bc26f89280ee2 (patch)
tree4ff59ed45a13022a3b2c5abc921740391302a414 /src/CabalHelper/Compiletime/Cabal.hs
parent1c0f2e8c403126acecfd6d6cccf2ad0b20f38929 (diff)
Fix Cabal version selection for Stack (esp. build-type:Custom)
Previously we would pick up Stack's Cabal version with ghc-pkg on the global package-db. This however ignores that Stack also supports custom Setup.hs with the Cabal version from the snapshot instead.
Diffstat (limited to 'src/CabalHelper/Compiletime/Cabal.hs')
-rw-r--r--src/CabalHelper/Compiletime/Cabal.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/CabalHelper/Compiletime/Cabal.hs b/src/CabalHelper/Compiletime/Cabal.hs
index b565152..88e53a7 100644
--- a/src/CabalHelper/Compiletime/Cabal.hs
+++ b/src/CabalHelper/Compiletime/Cabal.hs
@@ -268,9 +268,18 @@ complainIfNoCabalFile pkgdir Nothing =
bultinCabalVersion :: Version
bultinCabalVersion = parseVer VERSION_Cabal
-readSetupConfigHeader :: FilePath -> IO (Maybe UnitHeader)
+readSetupConfigHeader :: FilePath -> IO UnitHeader
readSetupConfigHeader file = bracket (openFile file ReadMode) hClose $ \h -> do
- parseSetupHeader <$> BS.hGetLine h
+ mhdr <- parseSetupHeader <$> BS.hGetLine h
+ case mhdr of
+ Just hdr@(UnitHeader _PkgId ("Cabal", _hdrCabalVersion) _compId) -> do
+ return hdr
+ Just UnitHeader {uhSetupId=(setup_name, _)} -> panicIO $
+ printf "Unknown Setup package-id in setup-config header '%s': '%s'"
+ (BS8.unpack setup_name) file
+ Nothing -> panicIO $
+ printf "Could not read '%s' header" file
+
parseSetupHeader :: BS.ByteString -> Maybe UnitHeader
parseSetupHeader header = case BS8.words header of