Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report all missing packages #264

Merged
merged 8 commits into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
Bugfixes:
- Report all missing packages together (#223)

## [0.8.4] - 2019-06-11

Expand Down
38 changes: 24 additions & 14 deletions src/Spago/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,19 @@ getProjectDeps Config{..} = getTransitiveDeps packageSet dependencies
getTransitiveDeps :: Spago m => PackageSet -> [PackageName] -> m [(PackageName, Package)]
getTransitiveDeps PackageSet{..} deps = do
echoDebug "Getting transitive deps"
Map.toList . fold <$> traverse (go Set.empty) deps
let (packageMap, notFoundErrors, cycleErrors) = foldMap (go Set.empty Set.empty Set.empty) deps

handleErrors (Map.toList packageMap) (Set.toList notFoundErrors) (Set.toList cycleErrors)

where
go seen dep
| dep `Set.member` seen =
die $ "Cycle in package dependencies at package " <> packageName dep
| otherwise =
case Map.lookup dep packagesDB of
Nothing ->
die $ pkgNotFoundMsg dep
Just info@Package{..} -> do
m <- fold <$> traverse (go (Set.insert dep seen)) dependencies
pure (Map.insert dep info m)
handleErrors packageMap notFoundErrors cycleErrors
| not (null cycleErrors) = die $ "The following packages have circular dependencies:\n" <> (Text.intercalate "\n" . fmap pkgCycleMsg) cycleErrors
| not (null notFoundErrors) = die $ "The following packages do not exist in your package set:\n" <> (Text.intercalate "\n" . fmap pkgNotFoundMsg) notFoundErrors
| otherwise = pure packageMap

pkgCycleMsg (CycleError pkg) = " - " <> packageName pkg

pkgNotFoundMsg pkg =
"Package `" <> packageName pkg <> "` does not exist in package set" <> extraHelp
pkgNotFoundMsg (NotFoundError pkg) = " - " <> packageName pkg <> extraHelp
where
extraHelp = case suggestedPkg of
Just pkg' | Map.member pkg' packagesDB ->
Expand All @@ -118,11 +116,23 @@ getTransitiveDeps PackageSet{..} deps = do
", and nor does `" <> packageName pkg' <> "`"
Nothing ->
""

suggestedPkg = do
sansPrefix <- Text.stripPrefix "purescript-" (packageName pkg)
Just (PackageName sansPrefix)

go seen notFoundErrors cycleErrors dep
| dep `Set.member` seen =
(packagesDB, notFoundErrors, Set.insert (CycleError dep) cycleErrors)
| otherwise = case Map.lookup dep packagesDB of
Nothing ->
(packagesDB , Set.insert (NotFoundError dep) notFoundErrors, cycleErrors)
Just info@Package{..} -> do
let (m, notFoundErrors', cycleErrors') = foldMap (go (Set.insert dep seen) notFoundErrors cycleErrors) dependencies
(Map.insert dep info m, notFoundErrors', cycleErrors')

newtype NotFoundError a = NotFoundError a deriving (Eq, Ord)
newtype CycleError a = CycleError a deriving (Eq, Ord)


getReverseDeps :: PackageSet -> PackageName -> IO [(PackageName, Package)]
getReverseDeps packageSet@PackageSet{..} dep = do
Expand Down
2 changes: 1 addition & 1 deletion test/SpagoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec = around_ setup $ do

writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }"
spago ["init"] >>= shouldBeSuccess
spago ["install", "foobar"] >>= shouldBeFailureOutput "missing-dependencies.txt"
spago ["install", "foo", "bar"] >>= shouldBeFailureOutput "missing-dependencies.txt"
mv "spago.dhall" "spago-install-failure.dhall"
checkFixture "spago-install-failure.dhall"

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/circular-dependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
spago: Cycle in package dependencies at package a
spago: The following packages have circular dependencies:
- a
- b
4 changes: 3 additions & 1 deletion test/fixtures/missing-dependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
spago: Package `foobar` does not exist in package set
spago: The following packages do not exist in your package set:
- bar
- foo