Skip to content

Commit f48975f

Browse files
alt-romeserikd
authored andcommitted
cabal-install: justify why legacy-fallback is used
This commit makes it so that cabal-install can explain the reason why it used the legacy fallback, instead of building per-component.
1 parent 808ada2 commit f48975f

File tree

3 files changed

+68
-16
lines changed

3 files changed

+68
-16
lines changed

cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,13 @@ buildAndInstallUnpackedPackage
740740

741741
dispname :: String
742742
dispname = case elabPkgOrComp pkg of
743-
ElabPackage _ ->
743+
-- Packages built altogether, instead of per component
744+
ElabPackage ElaboratedPackage{pkgWhyNotPerComponent} ->
744745
prettyShow pkgid
745-
++ " (all, legacy fallback)"
746+
++ " (all, legacy fallback: "
747+
++ unwords (map whyNotPerComponent $ NE.toList pkgWhyNotPerComponent)
748+
++ ")"
749+
-- Packages built per component
746750
ElabComponent comp ->
747751
prettyShow pkgid
748752
++ " ("

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,13 +1613,13 @@ elaborateInstallPlan
16131613
buildComponent
16141614
(Map.empty, Map.empty, Map.empty)
16151615
(map fst src_comps)
1616-
let not_per_component_reasons = why_not_per_component src_comps
1617-
if null not_per_component_reasons
1618-
then return comps
1619-
else do
1620-
checkPerPackageOk comps not_per_component_reasons
1616+
let whyNotPerComp = why_not_per_component src_comps
1617+
case NE.nonEmpty whyNotPerComp of
1618+
Nothing -> return comps
1619+
Just notPerCompReasons -> do
1620+
checkPerPackageOk comps notPerCompReasons
16211621
return
1622-
[ elaborateSolverToPackage spkg g $
1622+
[ elaborateSolverToPackage notPerCompReasons spkg g $
16231623
comps ++ maybeToList setupComponent
16241624
]
16251625
Left cns ->
@@ -1633,7 +1633,6 @@ elaborateInstallPlan
16331633
why_not_per_component g =
16341634
cuz_buildtype ++ cuz_spec ++ cuz_length ++ cuz_flag
16351635
where
1636-
cuz reason = [text reason]
16371636
-- We have to disable per-component for now with
16381637
-- Configure-type scripts in order to prevent parallel
16391638
-- invocation of the same `./configure` script.
@@ -1646,28 +1645,29 @@ elaborateInstallPlan
16461645
-- Once you've implemented this, swap it for the code below.
16471646
cuz_buildtype =
16481647
case PD.buildType (elabPkgDescription elab0) of
1649-
PD.Configure -> cuz "build-type is Configure"
1650-
PD.Custom -> cuz "build-type is Custom"
1648+
PD.Configure -> [CuzBuildType CuzConfigureBuildType]
1649+
PD.Custom -> [CuzBuildType CuzCustomBuildType]
1650+
PD.Make -> [CuzBuildType CuzMakeBuildType]
16511651
_ -> []
16521652
-- cabal-format versions prior to 1.8 have different build-depends semantics
16531653
-- for now it's easier to just fallback to legacy-mode when specVersion < 1.8
16541654
-- see, https://github.com/haskell/cabal/issues/4121
16551655
cuz_spec
16561656
| PD.specVersion pd >= CabalSpecV1_8 = []
1657-
| otherwise = cuz "cabal-version is less than 1.8"
1657+
| otherwise = [CuzCabalSpecVersion]
16581658
-- In the odd corner case that a package has no components at all
16591659
-- then keep it as a whole package, since otherwise it turns into
16601660
-- 0 component graph nodes and effectively vanishes. We want to
16611661
-- keep it around at least for error reporting purposes.
16621662
cuz_length
16631663
| length g > 0 = []
1664-
| otherwise = cuz "there are no buildable components"
1664+
| otherwise = [CuzNoBuildableComponents]
16651665
-- For ease of testing, we let per-component builds be toggled
16661666
-- at the top level
16671667
cuz_flag
16681668
| fromFlagOrDefault True (projectConfigPerComponent sharedPackageConfig) =
16691669
[]
1670-
| otherwise = cuz "you passed --disable-per-component"
1670+
| otherwise = [CuzDisablePerComponent]
16711671

16721672
-- \| Sometimes a package may make use of features which are only
16731673
-- supported in per-package mode. If this is the case, we should
@@ -1679,7 +1679,7 @@ elaborateInstallPlan
16791679
dieProgress $
16801680
text "Internal libraries only supported with per-component builds."
16811681
$$ text "Per-component builds were disabled because"
1682-
<+> fsep (punctuate comma reasons)
1682+
<+> fsep (punctuate comma $ map (text . whyNotPerComponent) $ toList reasons)
16831683
-- TODO: Maybe exclude Backpack too
16841684

16851685
elab0 = elaborateSolverToCommon spkg
@@ -1974,11 +1974,13 @@ elaborateInstallPlan
19741974
<$> executables
19751975

19761976
elaborateSolverToPackage
1977-
:: SolverPackage UnresolvedPkgLoc
1977+
:: NE.NonEmpty NotPerComponentReason
1978+
-> SolverPackage UnresolvedPkgLoc
19781979
-> ComponentsGraph
19791980
-> [ElaboratedConfiguredPackage]
19801981
-> ElaboratedConfiguredPackage
19811982
elaborateSolverToPackage
1983+
pkgWhyNotPerComponent
19821984
pkg@( SolverPackage
19831985
(SourcePackage pkgid _gpd _srcloc _descOverride)
19841986
_flags

cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE DeriveGeneric #-}
33
{-# LANGUAGE FlexibleContexts #-}
44
{-# LANGUAGE FlexibleInstances #-}
5+
{-# LANGUAGE LambdaCase #-}
56
{-# LANGUAGE NamedFieldPuns #-}
67
{-# LANGUAGE RecordWildCards #-}
78
{-# LANGUAGE TypeFamilies #-}
@@ -42,6 +43,9 @@ module Distribution.Client.ProjectPlanning.Types
4243
, MemoryOrDisk (..)
4344
, isInplaceBuildStyle
4445
, CabalFileText
46+
, NotPerComponentReason (..)
47+
, NotPerComponentBuildType (..)
48+
, whyNotPerComponent
4549

4650
-- * Build targets
4751
, ComponentTarget (..)
@@ -117,6 +121,7 @@ import qualified Distribution.Solver.Types.ComponentDeps as CD
117121
import Distribution.Solver.Types.OptionalStanza
118122

119123
import qualified Data.ByteString.Lazy as LBS
124+
import qualified Data.List.NonEmpty as NE
120125
import qualified Data.Map as Map
121126
import qualified Data.Monoid as Mon
122127
import System.FilePath ((</>))
@@ -724,12 +729,53 @@ data ElaboratedPackage = ElaboratedPackage
724729
, pkgStanzasEnabled :: OptionalStanzaSet
725730
-- ^ Which optional stanzas (ie testsuites, benchmarks) will actually
726731
-- be enabled during the package configure step.
732+
, pkgWhyNotPerComponent :: NE.NonEmpty NotPerComponentReason
733+
-- ^ Why is this not a per-component build?
727734
}
728735
deriving (Eq, Show, Generic)
729736

730737
instance Binary ElaboratedPackage
731738
instance Structured ElaboratedPackage
732739

740+
-- | Why did we fall-back to a per-package build, instead of using
741+
-- a per-component build?
742+
data NotPerComponentReason
743+
= -- | The build-type does not support per-component builds.
744+
CuzBuildType !NotPerComponentBuildType
745+
| -- | The Cabal spec version is too old for per-component builds.
746+
CuzCabalSpecVersion
747+
| -- | There are no buildable components, so we fall-back to a per-package
748+
-- build for error-reporting purposes.
749+
CuzNoBuildableComponents
750+
| -- | The user passed @--disable-per-component@.
751+
CuzDisablePerComponent
752+
deriving (Eq, Show, Generic)
753+
754+
data NotPerComponentBuildType
755+
= CuzConfigureBuildType
756+
| CuzCustomBuildType
757+
| CuzMakeBuildType
758+
deriving (Eq, Show, Generic)
759+
760+
instance Binary NotPerComponentBuildType
761+
instance Structured NotPerComponentBuildType
762+
763+
instance Binary NotPerComponentReason
764+
instance Structured NotPerComponentReason
765+
766+
-- | Display the reason we had to fall-back to a per-package build instead
767+
-- of a per-component build.
768+
whyNotPerComponent :: NotPerComponentReason -> String
769+
whyNotPerComponent = \case
770+
CuzBuildType bt ->
771+
"build-type is " ++ case bt of
772+
CuzConfigureBuildType -> "Configure"
773+
CuzCustomBuildType -> "Custom"
774+
CuzMakeBuildType -> "Make"
775+
CuzCabalSpecVersion -> "cabal-version is less than 1.8"
776+
CuzNoBuildableComponents -> "there are no buildable components"
777+
CuzDisablePerComponent -> "you passed --disable-per-component"
778+
733779
-- | See 'elabOrderDependencies'. This gives the unflattened version,
734780
-- which can be useful in some circumstances.
735781
pkgOrderDependencies :: ElaboratedPackage -> ComponentDeps [UnitId]

0 commit comments

Comments
 (0)