@@ -13,14 +13,15 @@ import Distribution.Helper (Package, projectPackages, pUnits,
13
13
unChModuleName , Ex (.. ), ProjLoc (.. ),
14
14
QueryEnv , mkQueryEnv , runQuery ,
15
15
Unit , unitInfo , uiComponents ,
16
- ChEntrypoint (.. ), uComponentName )
16
+ ChEntrypoint (.. ), uComponentName ,
17
+ UnitInfo (.. ))
17
18
import Distribution.Helper.Discover (findProjects , getDefaultDistDir )
18
19
import Data.Char (toLower )
19
20
import Data.Function ((&) )
20
- import Data.List (isPrefixOf , isInfixOf , sortOn , find , intercalate )
21
+ import Data.List (isPrefixOf , isInfixOf , sortOn , find )
21
22
import qualified Data.List.NonEmpty as NonEmpty
22
23
import Data.List.NonEmpty (NonEmpty )
23
- import qualified Data.Map as M
24
+ import qualified Data.Map as Map
24
25
import Data.Maybe (listToMaybe , mapMaybe , isJust )
25
26
import Data.Ord (Down (.. ))
26
27
import Data.String (IsString (.. ))
@@ -146,7 +147,7 @@ getProjectGhcLibDir :: Cradle -> IO (Maybe FilePath)
146
147
getProjectGhcLibDir crdl =
147
148
execProjectGhc crdl [" --print-libdir" ] >>= \ case
148
149
Nothing -> do
149
- logm " Could not obtain the libdir."
150
+ errorm " Could not obtain the libdir."
150
151
return Nothing
151
152
mlibdir -> return mlibdir
152
153
@@ -544,7 +545,7 @@ getComponent env unitCandidates fp = getComponent' [] [] unitCandidates >>=
544
545
(tried, failed, Nothing ) -> return (Left $ buildErrorMsg tried failed)
545
546
(_, _, Just comp) -> return (Right comp)
546
547
where
547
- getComponent' :: [Unit pt ] -> [Unit pt ] -> [Unit pt ] -> IO ([Unit pt ], [Unit pt ], Maybe ChComponentInfo )
548
+ getComponent' :: [UnitInfo ] -> [( Unit pt , IOException ) ] -> [Unit pt ] -> IO ([UnitInfo ], [( Unit pt , IOException ) ], Maybe ChComponentInfo )
548
549
getComponent' triedUnits failedUnits [] = return (triedUnits, failedUnits, Nothing )
549
550
getComponent' triedUnits failedUnits (unit : units) =
550
551
try (runQuery (unitInfo unit) env) >>= \ case
@@ -556,15 +557,15 @@ getComponent env unitCandidates fp = getComponent' [] [] unitCandidates >>=
556
557
++ fp
557
558
++ " \" in the unit: "
558
559
++ show unit
559
- getComponent' triedUnits (unit: failedUnits) units
560
+ getComponent' triedUnits (( unit, e) : failedUnits) units
560
561
Right ui -> do
561
- let components = M . elems (uiComponents ui)
562
+ let components = Map . elems (uiComponents ui)
562
563
debugm $ " Unit Info: " ++ show ui
563
564
case find (fp `partOfComponent` ) components of
564
- Nothing -> getComponent' (unit : triedUnits) failedUnits units
565
+ Nothing -> getComponent' (ui : triedUnits) failedUnits units
565
566
comp -> return (triedUnits, failedUnits, comp)
566
567
567
- buildErrorMsg :: [Unit pt ] -> [Unit pt ] -> [String ]
568
+ buildErrorMsg :: [UnitInfo ] -> [( Unit pt , IOException ) ] -> [String ]
568
569
buildErrorMsg triedUnits failedUnits =
569
570
[ " Could not obtain flags for: \" " ++ fp ++ " \" ."
570
571
, " "
@@ -573,20 +574,41 @@ getComponent env unitCandidates fp = getComponent' [] [] unitCandidates >>=
573
574
[
574
575
[ " This Module was not part of any component we are aware of."
575
576
, " "
576
- , " If you dont know how to expose a module, take a look at: "
577
+ , " If you dont know how to expose a module, take a look at:"
577
578
, " https://www.haskell.org/cabal/users-guide/developing-packages.html"
578
579
, " "
579
580
]
581
+ ++ concatMap ppShowUnitInfo triedUnits
580
582
| not (null triedUnits)
581
583
]
582
584
++ concat
583
585
[
584
586
[ " We could not build all components."
585
587
, " If one of these components exposes this Module, make sure they compile."
588
+ , " You can try to invoke the commands yourself."
589
+ , " The following commands failed:"
586
590
]
591
+ ++ concatMap (ppShowIOException . snd ) failedUnits
587
592
| not (null failedUnits)
588
593
]
589
594
595
+ ppShowUnitInfo :: UnitInfo -> [String ]
596
+ ppShowUnitInfo u =
597
+ u
598
+ & uiComponents
599
+ & Map. toList
600
+ & map
601
+ (\ (name, info) ->
602
+ " Component: " ++ show name ++ " with source directory: " ++ show (ciSourceDirs info)
603
+ )
604
+
605
+
606
+ ppShowIOException :: IOException -> [String ]
607
+ ppShowIOException e =
608
+ [ " "
609
+ , show e
610
+ ]
611
+
590
612
-- | Check whether the given FilePath is part of the Component.
591
613
-- A FilePath is part of the Component if and only if:
592
614
--
0 commit comments