diff --git a/ChangeLog.md b/ChangeLog.md index 79ac1e5..38b2784 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,7 @@ ## 0.14.5 * Add support for the `hide` field [yesodweb/wai#579](https://github.com/yesodweb/wai/issues/579) +* `list-revdeps` command [#28](https://github.com/fpco/stackage-curator/issues/28) ## 0.14.4.1 diff --git a/Stackage/Curator/RevDeps.hs b/Stackage/Curator/RevDeps.hs new file mode 100644 index 0000000..32a936a --- /dev/null +++ b/Stackage/Curator/RevDeps.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeFamilies #-} +module Stackage.Curator.RevDeps + ( listRevDeps + ) where + +import Stackage.Prelude +import Data.Yaml (decodeFileEither) +import Control.Monad.State.Strict (execState, get, put) + +listRevDeps :: FilePath + -> Bool -- ^ deep revdeps + -> PackageName -- ^ package to check + -> IO () +listRevDeps planFile deep pkg0 = do + BuildPlan {..} <- decodeFileEither planFile >>= either throwIO return + let go pkg = do + visited <- get + unless (pkg `member` visited) $ do + put $ insertSet pkg visited + case lookup pkg bpPackages of + Nothing -> return () + Just PackagePlan {..} -> mapM_ go ppUsers + let pkgs = execState (go pkg0) (asSet mempty) + mapM_ (putStrLn . unPackageName) pkgs diff --git a/app/stackage.hs b/app/stackage.hs index f494e9d..e4bf3e0 100644 --- a/app/stackage.hs +++ b/app/stackage.hs @@ -9,6 +9,7 @@ import Options.Applicative import Options.Applicative.Simple (simpleOptions, simpleVersion, addCommand) import Paths_stackage_curator (version) import Stackage.CompleteBuild +import Stackage.Curator.RevDeps import Stackage.Curator.UploadIndex import Stackage.DiffPlans import Stackage.InstallBuild @@ -73,6 +74,8 @@ main = do <*> pure (T.pack "package-index/")) addCommand "upload-docs" "Upload documentation to an S3 bucket" id (uploadDocs' <$> target <*> bundleFile) + addCommand "list-revdeps" "List reverse dependencies" id + (listRevDeps <$> planFile <*> deepRevDeps <*> revDepPackage) makeBundle' = makeBundle <$> planFile @@ -333,3 +336,12 @@ main = do switch (long "html" <> short 'h' <> help "Wrap the output in HTML