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-05-02 15:44:26 +0200
commit852dbc69d276e19add3917d17dff5541d84e29d4 (patch)
treeb01a16ee9a03fb491dfdf50a7bc717b76e95d445 /src/CabalHelper/Compiletime/Cabal.hs
parentf0741c61bd82ec0f94edcfa8d950f349eac86c33 (diff)
Fix Cabal version selection for 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. In cabal v2-build we have a similar problem. We used to assume that plan.json's cabal-lib-version is used uniformly across units but this is similarly untrue. To fix both of these we re-stage the cabal version query to after reconfiguring a unit, then we can just lookup the Cabal version in setup-config. Fixes #95
Diffstat (limited to 'src/CabalHelper/Compiletime/Cabal.hs')
-rw-r--r--src/CabalHelper/Compiletime/Cabal.hs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/CabalHelper/Compiletime/Cabal.hs b/src/CabalHelper/Compiletime/Cabal.hs
index aad004c..1ecf01f 100644
--- a/src/CabalHelper/Compiletime/Cabal.hs
+++ b/src/CabalHelper/Compiletime/Cabal.hs
@@ -31,6 +31,7 @@ import Data.Version
import System.Directory
import System.FilePath
import System.IO
+import Text.Printf
import Distribution.Verbosity (Verbosity, silent, normal, verbose, deafening)
@@ -223,9 +224,18 @@ complainIfNoCabalFile pkgdir Nothing =
bultinCabalVersion :: CabalVersion
bultinCabalVersion = CabalVersion $ 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