Skip to content

Commit

Permalink
Add flag infos to DependencyPlanFailures commercialhaskell#713
Browse files Browse the repository at this point in the history
  • Loading branch information
sjakobi committed Feb 6, 2016
1 parent 397047f commit 57e448d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ addPackageDeps treatAsDep package = do
case partitionEithers deps of
([], pairs) -> return $ Right $ mconcat pairs
(errs, _) -> return $ Left $ DependencyPlanFailures
(PackageIdentifier
(packageName package)
(packageVersion package))
package
(Map.fromList errs)
where
adrVersion (ADRToInstall task) = packageIdentifierVersion $ taskProvides task
Expand Down
8 changes: 0 additions & 8 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Stack.Package
,resolvePackageDescription
,packageToolDependencies
,packageDependencies
,packageIdentifier
,autogenDir
,checkCabalFileName
,printCabalFileWarning
Expand Down Expand Up @@ -88,18 +87,11 @@ import Safe (headDef, tailSafe)
import Stack.Build.Installed
import Stack.Constants
import Stack.Types
import qualified Stack.Types.PackageIdentifier
import qualified System.Directory as D
import System.FilePath (splitExtensions, replaceExtension)
import qualified System.FilePath as FilePath
import System.IO.Error

packageIdentifier :: Package -> Stack.Types.PackageIdentifier.PackageIdentifier
packageIdentifier pkg =
Stack.Types.PackageIdentifier.PackageIdentifier
(packageName pkg)
(packageVersion pkg)

-- | Read the raw, unresolved package information.
readPackageUnresolved :: (MonadIO m, MonadThrow m)
=> Path Abs File
Expand Down
13 changes: 10 additions & 3 deletions src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ instance Exception StackBuildException

data ConstructPlanException
= DependencyCycleDetected [PackageName]
| DependencyPlanFailures PackageIdentifier (Map PackageName (VersionRange, LatestApplicableVersion, BadDependency))
| DependencyPlanFailures Package (Map PackageName (VersionRange, LatestApplicableVersion, BadDependency))
| UnknownPackage PackageName -- TODO perhaps this constructor will be removed, and BadDependency will handle it all
-- ^ Recommend adding to extra-deps, give a helpful version number?
deriving (Typeable, Eq)
Expand All @@ -360,9 +360,10 @@ instance Show ConstructPlanException where
(DependencyCycleDetected pNames) ->
"While checking call stack,\n" ++
" dependency cycle detected in packages:" ++ indent (appendLines pNames)
(DependencyPlanFailures pIdent (Map.toList -> pDeps)) ->
(DependencyPlanFailures pkg (Map.toList -> pDeps)) ->
"Failure when adding dependencies:" ++ doubleIndent (appendDeps pDeps) ++ "\n" ++
" needed for package: " ++ packageIdentifierString pIdent
" needed for package " ++ packageIdentifierString (packageIdentifier pkg) ++
appendFlags (packageFlags pkg)
(UnknownPackage pName) ->
"While attempting to add dependency,\n" ++
" Could not find package " ++ show pName ++ " in known packages"
Expand All @@ -371,6 +372,12 @@ instance Show ConstructPlanException where
appendLines = foldr (\pName-> (++) ("\n" ++ show pName)) ""
indent = dropWhileEnd isSpace . unlines . fmap (\line -> " " ++ line) . lines
doubleIndent = indent . indent
appendFlags flags =
if Map.null flags
then ""
else " with flags:\n" ++
(doubleIndent . intercalate "\n" . map showFlag . Map.toList) flags
showFlag (name, bool) = show name ++ ": " ++ show bool
appendDeps = foldr (\dep-> (++) ("\n" ++ showDep dep)) ""
showDep (name, (range, mlatestApplicable, badDep)) = concat
[ show name
Expand Down
4 changes: 4 additions & 0 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ data Package =
}
deriving (Show,Typeable)

packageIdentifier :: Package -> PackageIdentifier
packageIdentifier pkg =
PackageIdentifier (packageName pkg) (packageVersion pkg)

-- | Files that the package depends on, relative to package directory.
-- Argument is the location of the .cabal file
newtype GetPackageOpts = GetPackageOpts
Expand Down

0 comments on commit 57e448d

Please sign in to comment.