Skip to content

Commit 18e8227

Browse files
committed
Do an early check for unbuildable deps, and give good error.
When a library/executable is unbuildable, the solver may still return a reference to it. Handle this gracefully in ProjectPlanning with a nice error message, rather than an assert failure. Fixes haskell#3978. Signed-off-by: Edward Z. Yang <[email protected]>
1 parent 211776b commit 18e8227

File tree

7 files changed

+46
-1
lines changed

7 files changed

+46
-1
lines changed

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ import Distribution.Text
130130
import qualified Distribution.Compat.Graph as Graph
131131
import Distribution.Compat.Graph(IsNode(..))
132132

133-
import Text.PrettyPrint (text, (<+>))
133+
import Text.PrettyPrint hiding ((<>))
134134
import qualified Data.Map as Map
135135
import Data.Set (Set)
136136
import qualified Data.Set as Set
@@ -1142,6 +1142,21 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
11421142
Map ComponentId FilePath),
11431143
ElaboratedConfiguredPackage)
11441144
buildComponent (cc_map, lc_map, exe_map) comp = do
1145+
-- Before we get too far, check if we depended on something
1146+
-- unbuildable. If we did, give a good error. (If we don't
1147+
-- check, the 'toConfiguredComponent' will assert fail, see #3978).
1148+
case unbuildable_external_lib_deps of
1149+
[] -> return ()
1150+
deps -> failProgress $
1151+
text "The package" <+> disp pkgid <+>
1152+
text "depends on unbuildable libraries:" <+>
1153+
hsep (punctuate comma (map (disp.solverSrcId) deps))
1154+
case unbuildable_external_exe_deps of
1155+
[] -> return ()
1156+
deps -> failProgress $
1157+
text "The package" <+> disp pkgid <+>
1158+
text "depends on unbuildable executables:" <+>
1159+
hsep (punctuate comma (map (disp.solverSrcId) deps))
11451160
infoProgress $ dispConfiguredComponent cc
11461161
let -- Use of invariant: DefUnitId indicates that if
11471162
-- there is no hash, it must have an empty
@@ -1270,6 +1285,11 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
12701285
external_cc_map = Map.fromList (map mkPkgNameMapping external_lib_dep_pkgs)
12711286
external_lc_map = Map.fromList (map mkShapeMapping external_lib_dep_pkgs)
12721287

1288+
unbuildable_external_lib_deps =
1289+
filter (null . elaborateLibSolverId mapDep) external_lib_dep_sids
1290+
unbuildable_external_exe_deps =
1291+
filter (null . elaborateExeSolverId mapDep) external_exe_dep_sids
1292+
12731293
mkPkgNameMapping :: ElaboratedPlanPackage
12741294
-> (PackageName, (ComponentId, PackageId))
12751295
mkPkgNameMapping dpkg =

cabal-install/cabal-install.cabal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ Extra-Source-Files:
134134
tests/IntegrationTests/new-build/T3460/sub-package-B/B.hs
135135
tests/IntegrationTests/new-build/T3460/sub-package-B/Setup.hs
136136
tests/IntegrationTests/new-build/T3460/sub-package-B/sub-package-B.cabal
137+
tests/IntegrationTests/new-build/T3978.err
138+
tests/IntegrationTests/new-build/T3978.sh
139+
tests/IntegrationTests/new-build/T3978/cabal.project
140+
tests/IntegrationTests/new-build/T3978/p/p.cabal
141+
tests/IntegrationTests/new-build/T3978/q/q.cabal
137142
tests/IntegrationTests/new-build/executable/Main.hs
138143
tests/IntegrationTests/new-build/executable/Setup.hs
139144
tests/IntegrationTests/new-build/executable/Test.hs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RE:^cabal(\.exe)?: The package q-1.0 depends on unbuildable libraries: p-1.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ./common.sh
2+
cd T3978
3+
! cabal new-build q
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: p q
2+
allow-older: p:base
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: p
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.10
5+
6+
library
7+
buildable: False
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: q
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.10
5+
6+
library
7+
build-depends: p

0 commit comments

Comments
 (0)