{-# LANGUAGE CPP #-}
module Distribution.RPM.Build.Order
(dependencySort,
dependencySortRpmOpts,
dependencySortParallel,
dependencyLayers,
leafPackages,
independentPackages,
Components (..),
sortGraph)
where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Data.List (intercalate)
import Data.Graph.Inductive.Query.DFS (topsort', components)
import Distribution.RPM.Build.Graph
dependencySort :: [FilePath] -> IO [FilePath]
dependencySort = dependencySortRpmOpts []
dependencySortRpmOpts :: [String] -> [FilePath] -> IO [FilePath]
dependencySortRpmOpts rpmopts pkgs = do
topsort' <$> createGraphRpmOpts rpmopts pkgs
dependencySortParallel :: [FilePath] -> IO [[FilePath]]
dependencySortParallel pkgs = do
graph <- createGraph pkgs
return $ map (topsort' . subgraph' graph) (components graph)
dependencyLayers :: [FilePath] -> IO [[FilePath]]
dependencyLayers pkgs = do
graph <- createGraph pkgs
return $ packageLayers graph
leafPackages :: [FilePath] -> IO [FilePath]
leafPackages pkgs = do
graph <- createGraph pkgs
return $ packageLeaves graph
independentPackages :: [FilePath] -> IO [FilePath]
independentPackages pkgs = do
graph <- createGraph pkgs
return $ separatePackages graph
data Components = Parallel
| Combine
| Connected
| Separate
sortGraph :: Components -> PackageGraph -> IO ()
sortGraph opt graph =
putStrLn $
case opt of
Parallel ->
intercalate "\n\n" $ map (unwords . topsort' . subgraph' graph) (components graph)
Combine -> (unwords . topsort') graph
Connected ->
intercalate "\n\n" $ map (unwords . topsort' . subgraph' graph) $ filter ((>1) . length) (components graph)
Separate -> unlines $ separatePackages graph