aboutsummaryrefslogtreecommitdiff
path: root/src/CabalHelper/Compiletime/Program
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2020-03-25 18:40:15 +0100
committerDaniel Gröber <dxld@darkboxed.org>2020-05-02 03:15:31 +0200
commit262231a8f28feb711a8b164c62d9b89bcc11df47 (patch)
tree8b9f2812eb5c0516823d81eec9fc0e5e2b13cd7c /src/CabalHelper/Compiletime/Program
parenta5cb011fccf6d06a229b83052150f4accabdac0d (diff)
Fix cabal projects using source-repository-package
Apparently we can get source-repo-packages in plan.json even when filtering for `"style": "local"`(`UnitTypeLocal`). It's possible the root cause here is a cabal bug as source-repository-package should really be treated more like a tarball than a local package. Regardless we simply filter units by actually checking for `uPkgSrc=Just LocalUnpackedPackage` instead of relying on "style". This fixes #99
Diffstat (limited to 'src/CabalHelper/Compiletime/Program')
-rw-r--r--src/CabalHelper/Compiletime/Program/CabalInstall.hs47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/CabalHelper/Compiletime/Program/CabalInstall.hs b/src/CabalHelper/Compiletime/Program/CabalInstall.hs
index 6af8e0f..d5ed15e 100644
--- a/src/CabalHelper/Compiletime/Program/CabalInstall.hs
+++ b/src/CabalHelper/Compiletime/Program/CabalInstall.hs
@@ -35,7 +35,6 @@ import System.FilePath
import Text.Printf
import Text.Read
-import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text as Text
@@ -50,7 +49,7 @@ import CabalHelper.Compiletime.Process
import CabalHelper.Shared.InterfaceTypes
( ChComponentName(..), ChLibraryName(..) )
import CabalHelper.Shared.Common
- ( parseVer, trim, appCacheDir, panicIO )
+ ( parseVer, trim, appCacheDir )
newtype CabalInstallVersion = CabalInstallVersion { cabalInstallVer :: Version }
@@ -250,32 +249,33 @@ cabalV2WithGHCProgOpts = concat
planPackages :: CP.PlanJson -> IO [Package ('Cabal 'CV2)]
planPackages plan = do
- fmap Map.elems $
- mapM mkPackage $
- groupByMap $ Map.elems $
- Map.filter ((==CP.UnitTypeLocal) . CP.uType) $
+ sequence $
+ Map.elems $
+ Map.mapWithKey mkPackage $
+ Map.mapMaybe packagesWithSourceDir $
+ groupByMap $
+ Map.elems $
CP.pjUnits plan
where
groupByMap = Map.fromListWith (<>) . map (CP.uPId &&& (:|[]))
- mkPackage :: NonEmpty CP.Unit -> IO (Package ('Cabal 'CV2))
- mkPackage units@(unit :| _) =
+ packagesWithSourceDir units@(unit :| _) =
case unit of
- CP.Unit
- { uPkgSrc=Just (CP.LocalUnpackedPackage pkgdir)
- } -> do
- cabal_file <- Cabal.complainIfNoCabalFile pkgdir =<< Cabal.findCabalFile pkgdir
- let pkg = Package
- { pPackageName =
- let CP.PkgId (CP.PkgName pkg_name) _ = CP.uPId unit
- in Text.unpack pkg_name
- , pSourceDir = pkgdir
- , pCabalFile = CabalFile cabal_file
- , pFlags = []
- , pUnits = fmap (\u -> fixBackpackUnit u $ mkUnit pkg { pUnits = () } u) units
- }
- return pkg
- _ -> panicIO "planPackages.mkPackage: Got non-unpacked package src!"
+ CP.Unit { uPkgSrc=Just (CP.LocalUnpackedPackage pkgdir) }
+ -> Just (pkgdir, units)
+ _ -> Nothing
+
+ mkPackage :: CP.PkgId -> (FilePath, NonEmpty CP.Unit) -> IO (Package ('Cabal 'CV2))
+ mkPackage (CP.PkgId (CP.PkgName pkg_name) _) (pkgdir, units) = do
+ cabal_file <- Cabal.complainIfNoCabalFile pkgdir =<< Cabal.findCabalFile pkgdir
+ let pkg = Package
+ { pPackageName = Text.unpack pkg_name
+ , pSourceDir = pkgdir
+ , pCabalFile = CabalFile cabal_file
+ , pFlags = []
+ , pUnits = fmap (\u -> fixBackpackUnit u $ mkUnit pkg { pUnits = () } u) units
+ }
+ return pkg
takeBackpackIndefUnitId :: CP.Unit -> Maybe CP.UnitId
takeBackpackIndefUnitId CP.Unit {uId=CP.UnitId uid}
@@ -307,7 +307,6 @@ planPackages plan = do
mkUnit pkg u@CP.Unit
{ uDistDir=Just distdirv1
, uComps=comps
- , uPId=CP.PkgId pkg_name _
, uId
} =
Unit