From 04c2d34f1874bc198288d33c784bc26f89280ee2 Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Sat, 11 Jan 2020 07:46:33 +0100 Subject: 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. --- src/CabalHelper/Compiletime/Cabal.hs | 13 +++++++++++-- src/CabalHelper/Compiletime/Compile.hs | 12 ++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') 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 diff --git a/src/CabalHelper/Compiletime/Compile.hs b/src/CabalHelper/Compiletime/Compile.hs index d2886e8..a55ee93 100644 --- a/src/CabalHelper/Compiletime/Compile.hs +++ b/src/CabalHelper/Compiletime/Compile.hs @@ -90,7 +90,7 @@ data CompilationProductScope = CPSGlobal | CPSProject type CompHelperEnv = CompHelperEnv' CabalVersion data CompHelperEnv' cv = CompHelperEnv { cheCabalVer :: !cv - , chePkgDb :: !(Maybe PackageDbDir) + , chePkgDb :: ![PackageDbDir] -- ^ A package-db where we are guaranteed to find Cabal-`cheCabalVer`. , cheProjDir :: !FilePath , chePlanJson :: !(Maybe PlanJson) @@ -119,7 +119,7 @@ compileHelper' CompHelperEnv {..} = do CabalVersion cabalVerPlain -> do runMaybeT $ msum $ map (\f -> f ghcVer cabalVerPlain) $ case chePkgDb of - Nothing -> + [] -> [ compileWithCabalV2Inplace , compileWithCabalV2GhcEnv , compileCabalSource @@ -127,8 +127,8 @@ compileHelper' CompHelperEnv {..} = do , compileGlobal , compileWithCabalInPrivatePkgDb ] - Just db -> - [ ((.).(.)) liftIO (compilePkgDb db) + dbs -> + [ ((.).(.)) liftIO (compilePkgDbs dbs) ] appdir <- appCacheDir let cp@CompPaths {compExePath} = compPaths appdir cheProjLocalCacheDir comp @@ -148,11 +148,11 @@ compileHelper' CompHelperEnv {..} = do -- for relaxed deps: find (sameMajorVersionAs cheCabalVer) . reverse . sort - compilePkgDb db _ghcVer cabalVer = return $ + compilePkgDbs dbs _ghcVer cabalVer = return $ (,) (pure ()) CompileWithCabalPackage - { compPackageSource = GPSPackageDBs [db] + { compPackageSource = GPSPackageDBs dbs , compCabalVersion = CabalVersion cabalVer , compProductTarget = CPSProject } -- cgit v1.2.3