+ let pkgs = allPackagesInStack db_stack
+
+ checkPackage p = do
+ (_,es) <- runValidate $ checkPackageConfig p db_stack False True
+ if null es
+ then return []
+ else do
+ when (not simple_output) $ do
+ reportError ("There are problems in package " ++ display (package p) ++ ":")
+ reportValidateErrors es " " Nothing
+ return ()
+ return [p]
+
+ broken_pkgs <- concat `fmap` mapM checkPackage pkgs
+
+ let filterOut pkgs1 pkgs2 = filter not_in pkgs2
+ where not_in p = package p `notElem` all_ps
+ all_ps = map package pkgs1
+
+ let not_broken_pkgs = filterOut broken_pkgs pkgs
+ (_, trans_broken_pkgs) = closure [] not_broken_pkgs
+ all_broken_pkgs = broken_pkgs ++ trans_broken_pkgs
+
+ when (not (null all_broken_pkgs)) $ do
+ if simple_output
+ then simplePackageList my_flags all_broken_pkgs
+ else do
+ reportError ("\nThe following packages are broken, either because they have a problem\n"++
+ "listed above, or because they depend on a broken package.")
+ mapM_ (hPutStrLn stderr . display . package) all_broken_pkgs
+
+ when (not (null all_broken_pkgs)) $ exitWith (ExitFailure 1)
+
+
+closure :: [InstalledPackageInfo] -> [InstalledPackageInfo]
+ -> ([InstalledPackageInfo], [InstalledPackageInfo])
+closure pkgs db_stack = go pkgs db_stack