Skip to content

Commit

Permalink
sort: add --chain (#25) and --layers
Browse files Browse the repository at this point in the history
  • Loading branch information
juhp committed Mar 17, 2022
1 parent 908743a commit 5661ba7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
27 changes: 20 additions & 7 deletions src/Cmd/Sort.hs
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
module Cmd.Sort (
sortCmd,
RpmWith(..),
graphCmd
graphCmd,
SortDisplay(..)
)
where

import Control.Monad.Extra
import Data.List (intercalate)
import Distribution.RPM.Build.Graph
import Distribution.RPM.Build.Order (dependencySortRpmOpts,
dependencySortParallel)
dependencySortParallel,
dependencyLayers)

import Branches
import Git
import Package

data RpmWith = RpmWith String | RpmWithout String

sortCmd :: Bool -> Maybe RpmWith -> (Maybe Branch,[String]) -> IO ()
data SortDisplay = SortParallel | SortChain | SortLayers | SortPlain

sortCmd :: SortDisplay -> Maybe RpmWith -> (Maybe Branch,[String]) -> IO ()
sortCmd _ _ (_,[]) = return ()
sortCmd parallel mrpmwith (mbr, pkgs) = do
sortCmd displaymode mrpmwith (mbr, pkgs) = do
withPackagesMaybeBranchNoHeadergit ExactlyOne noop (mbr, pkgs)
let rpmopts = maybe [] toRpmOption mrpmwith
if parallel
case displaymode of
-- reverse because rpmbuild-order reverses the order of independent pkgs?
then dependencySortParallel (reverse pkgs) >>= mapM_ (putStrLn . unwords)
else dependencySortRpmOpts rpmopts (reverse pkgs) >>= putStrLn . unwords
SortParallel ->
dependencySortParallel (reverse pkgs) >>= mapM_ (putStrLn . unwords)
SortChain ->
dependencyLayers pkgs >>=
putStrLn . intercalate " : " . map unwords
SortLayers ->
dependencyLayers pkgs >>=
mapM_ (putStrLn . unwords)
SortPlain ->
dependencySortRpmOpts rpmopts (reverse pkgs) >>= putStrLn . unwords

noop :: Package -> AnyBranch -> IO ()
noop _pkg br =
Expand Down
8 changes: 7 additions & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ main = do
<*> maybeBranchPackages False
, Subcommand "sort" "Sort packages in build dependency order" $
sortCmd
<$> switchWith 'p' "parallel" "Group dependent packages on separate lines"
<$> sortDisplayOpt
<*> optional rpmWithOpt
<*> maybeBranchPackages True
, Subcommand "prep" "Prep sources" $
Expand Down Expand Up @@ -485,3 +485,9 @@ main = do
flagWith' NoCleanBefore 'c' "no-clean" "Do not clean chroot before building"
<|> flagWith' NoCleanAfter 'C' "no-clean-after" "Do not clean chroot after building"
<|> flagWith' NoCleanAll 'A' "no-clean-all" "Do not clean chroot before or after building"

sortDisplayOpt :: Parser SortDisplay
sortDisplayOpt =
flagWith' SortParallel 'p' "parallel" "Group dependent packages on separate lines"
<|> flagWith' SortChain 'c' "chain" "chain-build output"
<|> flagWith SortPlain SortLayers 'l' "layers" "output parallel layers"

0 comments on commit 5661ba7

Please sign in to comment.