Skip to content

Commit

Permalink
Do an early check for unbuildable deps, and give good error.
Browse files Browse the repository at this point in the history
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 #3978.

Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Oct 22, 2016
1 parent 211776b commit e80207c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import Distribution.Text
import qualified Distribution.Compat.Graph as Graph
import Distribution.Compat.Graph(IsNode(..))

import Text.PrettyPrint (text, (<+>))
import Text.PrettyPrint hiding ((<>))
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
Expand Down Expand Up @@ -1142,6 +1142,21 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
Map ComponentId FilePath),
ElaboratedConfiguredPackage)
buildComponent (cc_map, lc_map, exe_map) comp = do
-- Before we get too far, check if we depended on something
-- unbuildable. If we did, give a good error. (If we don't
-- check, the 'toConfiguredComponent' will assert fail, see #3978).
case unbuildable_external_lib_deps of
[] -> return ()
deps -> failProgress $
text "The package" <+> disp pkgid <+>
text "depends on unbuildable libraries:" <+>
hsep (punctuate comma (map (disp.solverSrcId) deps))
case unbuildable_external_exe_deps of
[] -> return ()
deps -> failProgress $
text "The package" <+> disp pkgid <+>
text "depends on unbuildable executables:" <+>
hsep (punctuate comma (map (disp.solverSrcId) deps))
infoProgress $ dispConfiguredComponent cc
let -- Use of invariant: DefUnitId indicates that if
-- there is no hash, it must have an empty
Expand Down Expand Up @@ -1270,6 +1285,11 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
external_cc_map = Map.fromList (map mkPkgNameMapping external_lib_dep_pkgs)
external_lc_map = Map.fromList (map mkShapeMapping external_lib_dep_pkgs)

unbuildable_external_lib_deps =
filter (null . elaborateLibSolverId mapDep) external_lib_dep_sids
unbuildable_external_exe_deps =
filter (null . elaborateExeSolverId mapDep) external_exe_dep_sids

mkPkgNameMapping :: ElaboratedPlanPackage
-> (PackageName, (ComponentId, PackageId))
mkPkgNameMapping dpkg =
Expand Down
9 changes: 9 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ Extra-Source-Files:
tests/IntegrationTests/new-build/T3460/sub-package-B/B.hs
tests/IntegrationTests/new-build/T3460/sub-package-B/Setup.hs
tests/IntegrationTests/new-build/T3460/sub-package-B/sub-package-B.cabal
tests/IntegrationTests/new-build/T3978.err
tests/IntegrationTests/new-build/T3978.sh
tests/IntegrationTests/new-build/T3978/cabal.project
tests/IntegrationTests/new-build/T3978/p/p.cabal
tests/IntegrationTests/new-build/T3978/q/q.cabal
tests/IntegrationTests/new-build/T4017.sh
tests/IntegrationTests/new-build/T4017/cabal.project
tests/IntegrationTests/new-build/T4017/p/p.cabal
tests/IntegrationTests/new-build/T4017/q/q.cabal
tests/IntegrationTests/new-build/executable/Main.hs
tests/IntegrationTests/new-build/executable/Setup.hs
tests/IntegrationTests/new-build/executable/Test.hs
Expand Down
1 change: 1 addition & 0 deletions cabal-install/tests/IntegrationTests/new-build/T3978.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RE:^cabal(\.exe)?: The package q-1.0 depends on unbuildable libraries: p-1.0
3 changes: 3 additions & 0 deletions cabal-install/tests/IntegrationTests/new-build/T3978.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ./common.sh
cd T3978
! cabal new-build q
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: p q
allow-older: p:base
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: p
version: 1.0
build-type: Simple
cabal-version: >= 1.10

library
buildable: False
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: q
version: 1.0
build-type: Simple
cabal-version: >= 1.10

library
build-depends: p

0 comments on commit e80207c

Please sign in to comment.