From f0741c61bd82ec0f94edcfa8d950f349eac86c33 Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Sat, 2 May 2020 01:55:55 +0200 Subject: Ignore setup components from plan.json in readUnitInfo Cabal includes the Setup.hs executable as a component in plan.json, however there isn't a target to build it directly so we just ignore it for not when reading unit info. --- lib/Distribution/Helper.hs | 15 ++++++++++++++- src/CabalHelper/Compiletime/Program/CabalInstall.hs | 9 ++++++--- src/CabalHelper/Compiletime/Types.hs | 5 ++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/Distribution/Helper.hs b/lib/Distribution/Helper.hs index 3c5007d..428afd1 100644 --- a/lib/Distribution/Helper.hs +++ b/lib/Distribution/Helper.hs @@ -503,7 +503,7 @@ buildProjectTarget qe mu stage = do Just Unit{uImpl} -> concat [ if uiV2OnlyDependencies uImpl then ["--only-dependencies"] else [] - , uiV2Components uImpl + , map snd $ filter ((/= ChSetupHsName) . fst) $ uiV2Components uImpl ] case qeProjLoc of ProjLocV2File {plCabalProjectFile} -> @@ -630,6 +630,19 @@ readProjInfo qe pc pcm pi = withVerbosity $ do -- the global pkg-db. readUnitInfo :: Helper pt -> Unit pt -> UnitModTimes -> IO UnitInfo +readUnitInfo helper u@Unit{uImpl=ui@UnitImplV2{uiV2Components}} umt + | ChSetupHsName `elem` map fst uiV2Components = do + let unit' = u { + uImpl = ui + { uiV2Components = filter ((/= ChSetupHsName) . fst) uiV2Components + } + } + -- TODO: Add a synthetic UnitInfo for the setup executable. Cabal + -- doesn't allow building it via a target on the cmdline and it + -- doesn't really exist as far as setup-config is concerned but + -- plan.json has the dependency versions for custom-setup so we + -- should be able to represet that as a UnitInfo. + readUnitInfo helper unit' umt readUnitInfo helper unit@Unit {uUnitId=uiUnitId} uiModTimes = do res <- runHelper helper unit [ "package-id" diff --git a/src/CabalHelper/Compiletime/Program/CabalInstall.hs b/src/CabalHelper/Compiletime/Program/CabalInstall.hs index 9823c50..71866ae 100644 --- a/src/CabalHelper/Compiletime/Program/CabalInstall.hs +++ b/src/CabalHelper/Compiletime/Program/CabalInstall.hs @@ -300,10 +300,13 @@ planPackages plan = do | otherwise = ch_unit - unitTargets :: CP.Unit -> [String] + unitTargets :: CP.Unit -> [(ChComponentName, String)] unitTargets CP.Unit {uComps, uPId=CP.PkgId pkg_name _} = - map (Text.unpack . (((coerce pkg_name) <> ":") <>) . CP.dispCompNameTarget pkg_name) $ - Map.keys uComps + [ (cpCompNameToChComponentName comp, Text.unpack target) + | comp <- Map.keys uComps + , let comp_str = CP.dispCompNameTarget pkg_name comp + , let target = ((coerce pkg_name) <> ":") <> comp_str + ] mkUnit :: Package' () -> CP.Unit -> Unit ('Cabal 'CV2) mkUnit pkg u@CP.Unit diff --git a/src/CabalHelper/Compiletime/Types.hs b/src/CabalHelper/Compiletime/Types.hs index b96101a..bb36df8 100644 --- a/src/CabalHelper/Compiletime/Types.hs +++ b/src/CabalHelper/Compiletime/Types.hs @@ -348,8 +348,7 @@ data UnitImpl pt where UnitImplV1 :: UnitImpl ('Cabal 'CV1) UnitImplV2 :: - { uiV2ComponentNames :: ![ChComponentName] - , uiV2Components :: ![String] + { uiV2Components :: ![(ChComponentName, String)] , uiV2OnlyDependencies :: !Bool } -> UnitImpl ('Cabal 'CV2) @@ -366,7 +365,7 @@ deriving instance Show (UnitImpl pt) -- of helper invocations for clients that don't need to know the entire project -- structure. uComponentName :: Unit pt -> Maybe ChComponentName -uComponentName Unit { uImpl=UnitImplV2 { uiV2ComponentNames=[comp] } } = +uComponentName Unit { uImpl=UnitImplV2 { uiV2Components=[(comp, _)] } } = Just comp uComponentName _ = Nothing -- cgit v1.2.3