{-# LANGUAGE CPP #-}
module Distribution.RPM.Build.Order
(dependencySort,
dependencySortRpmOpts,
dependencySortParallel,
dependencyLayers,
leafPackages,
independentPackages,
Components (..),
sortGraph,
depsPackages)
where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Data.List (intersperse)
import Data.Graph.Inductive.Query.DFS (topsort', components)
import Distribution.RPM.Build.Graph
dependencySort :: [FilePath] -> IO [FilePath]
dependencySort :: [FilePath] -> IO [FilePath]
dependencySort = [FilePath] -> [FilePath] -> IO [FilePath]
dependencySortRpmOpts []
dependencySortRpmOpts :: [String] -> [FilePath] -> IO [FilePath]
dependencySortRpmOpts :: [FilePath] -> [FilePath] -> IO [FilePath]
dependencySortRpmOpts [FilePath]
rpmopts [FilePath]
pkgs = do
forall (gr :: * -> * -> *) a b. Graph gr => gr a b -> [a]
topsort' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FilePath] -> [FilePath] -> IO PackageGraph
createGraphRpmOpts [FilePath]
rpmopts [FilePath]
pkgs
dependencySortParallel :: [FilePath] -> IO [[FilePath]]
dependencySortParallel :: [FilePath] -> IO [[FilePath]]
dependencySortParallel [FilePath]
pkgs = do
PackageGraph
graph <- [FilePath] -> IO PackageGraph
createGraph [FilePath]
pkgs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall (gr :: * -> * -> *) a b. Graph gr => gr a b -> [a]
topsort' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Gr a b -> [Node] -> Gr a b
subgraph' PackageGraph
graph) (forall (gr :: * -> * -> *) a b. Graph gr => gr a b -> [[Node]]
components PackageGraph
graph)
dependencyLayers :: [FilePath] -> IO [[FilePath]]
dependencyLayers :: [FilePath] -> IO [[FilePath]]
dependencyLayers [FilePath]
pkgs = do
PackageGraph
graph <- [FilePath] -> IO PackageGraph
createGraph [FilePath]
pkgs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ PackageGraph -> [[FilePath]]
packageLayers PackageGraph
graph
leafPackages :: [FilePath] -> IO [FilePath]
leafPackages :: [FilePath] -> IO [FilePath]
leafPackages [FilePath]
pkgs = do
PackageGraph
graph <- [FilePath] -> IO PackageGraph
createGraph [FilePath]
pkgs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ PackageGraph -> [FilePath]
packageLeaves PackageGraph
graph
independentPackages :: [FilePath] -> IO [FilePath]
independentPackages :: [FilePath] -> IO [FilePath]
independentPackages [FilePath]
pkgs = do
PackageGraph
graph <- [FilePath] -> IO PackageGraph
createGraph [FilePath]
pkgs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ PackageGraph -> [FilePath]
separatePackages PackageGraph
graph
sortGraph :: Components -> PackageGraph -> IO ()
sortGraph :: Components -> PackageGraph -> IO ()
sortGraph Components
opt PackageGraph
graph =
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (FilePath -> IO ()
putStrLn forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FilePath] -> FilePath
unwords) forall a b. (a -> b) -> a -> b
$
case Components
opt of
Components
Parallel -> forall a. a -> [a] -> [a]
intersperse [FilePath
"\n"]
Components
Combine -> forall a. a -> a
id
Components
Connected -> forall a. a -> [a] -> [a]
intersperse [FilePath
"\n"]
Components
Separate -> forall a. a -> a
id
forall a b. (a -> b) -> a -> b
$ Components -> PackageGraph -> [[FilePath]]
topsortGraph Components
opt PackageGraph
graph
depsPackages :: Bool
-> [String]
-> Bool
-> [String]
-> [String]
-> Bool
-> Bool
-> Maybe FilePath
-> [FilePath]
-> IO ()
depsPackages :: Bool
-> [FilePath]
-> Bool
-> [FilePath]
-> [FilePath]
-> Bool
-> Bool
-> Maybe FilePath
-> [FilePath]
-> IO ()
depsPackages Bool
rev [FilePath]
rpmopts Bool
verbose [FilePath]
excludedPkgs [FilePath]
ignoredBRs Bool
lenient Bool
parallel Maybe FilePath
mdir [FilePath]
pkgs =
Bool
-> [FilePath]
-> Bool
-> [FilePath]
-> [FilePath]
-> Bool
-> Maybe FilePath
-> [FilePath]
-> IO PackageGraph
depsGraph Bool
rev [FilePath]
rpmopts Bool
verbose [FilePath]
excludedPkgs [FilePath]
ignoredBRs Bool
lenient Maybe FilePath
mdir [FilePath]
pkgs forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Components -> PackageGraph -> IO ()
sortGraph (if Bool
parallel then Components
Parallel else Components
Combine)