summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autonix-deps-kf5.cabal5
-rw-r--r--kf5-deps.hs15
-rw-r--r--src/Autonix/KF5.hs140
3 files changed, 51 insertions, 109 deletions
diff --git a/autonix-deps-kf5.cabal b/autonix-deps-kf5.cabal
index 08f415c..68956b8 100644
--- a/autonix-deps-kf5.cabal
+++ b/autonix-deps-kf5.cabal
@@ -1,5 +1,5 @@
name: autonix-deps-kf5
-version: 0.2.0.1
+version: 0.3.0.0
synopsis: Generate dependencies for KDE 5 Nix expressions
license: BSD3
license-file: LICENSE
@@ -23,7 +23,7 @@ library
exposed-modules:
Autonix.KF5
build-depends:
- autonix-deps ==0.2.*
+ autonix-deps ==0.3.*
, base >=4.7 && <5
, bytestring >=0.10
, conduit ==1.2.*
@@ -31,6 +31,7 @@ library
, filepath >=1.3
, lens >=4.0
, mtl >=2.1
+ , text >= 1.2
, transformers >=0.3
hs-source-dirs: src
default-language: Haskell2010
diff --git a/kf5-deps.hs b/kf5-deps.hs
index 40270d4..94f483a 100644
--- a/kf5-deps.hs
+++ b/kf5-deps.hs
@@ -2,19 +2,8 @@
module Main where
-import Control.Monad.State
-import Data.Monoid
-
-import Autonix.Analyze
-import Autonix.Args
-import Autonix.Deps
-import Autonix.Generate
+import Autonix
import Autonix.KF5
main :: IO ()
-main = withArgs $ \manifest -> flip evalStateT mempty $ do
- rename "ECM" "extra-cmake-modules"
- analyzePackages (analyzeFiles kf5Analyzers) manifest
- kf5PostAnalyze
- get >>= writeDeps
- get >>= writeRenames
+main = autonix kf5Analyzers
diff --git a/src/Autonix/KF5.hs b/src/Autonix/KF5.hs
index c23bd37..1811e6b 100644
--- a/src/Autonix/KF5.hs
+++ b/src/Autonix/KF5.hs
@@ -7,53 +7,35 @@ module Autonix.KF5 where
import Control.Lens
import Control.Monad.IO.Class
import Control.Monad.State
+import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Conduit
import Data.List (isPrefixOf)
-import qualified Data.Map as M
-import Data.Maybe (fromMaybe)
+import Data.Map (Map)
import Data.Monoid
import qualified Data.Set as S
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
import System.FilePath (takeBaseName, takeExtensions, takeFileName)
import Autonix.Analyze
import Autonix.CMake
-import Autonix.Deps
+import Autonix.Package (Package)
+import qualified Autonix.Package as Package
import Autonix.Regex
+import Autonix.Renames
printFilePaths :: MonadIO m => Analyzer m
-printFilePaths _ = awaitForever $ \(path, _) -> liftIO $ putStrLn path
+printFilePaths _ _ = awaitForever $ \(path, _) -> liftIO $ putStrLn path
-renameKF5Pkgs :: (MonadIO m, MonadState Deps m) => Analyzer m
-renameKF5Pkgs pkg = awaitForever $ \(path, contents) ->
- when (takeFileName path == "metainfo.yaml") $ do
- let regex = makeRegex "cmakename:[[:space:]]*([[:alnum:]]*)"
- matches = match regex contents
- case matches of
- ((_ : cmakeName : _) : _) -> rename cmakeName pkg
- _ -> return ()
-
-propagateKF5Deps :: (MonadIO m, MonadState Deps m) => Analyzer m
-propagateKF5Deps newPkg = awaitForever $ \(path, contents) ->
- when (".cmake" `isPrefixOf` takeExtensions path) $ do
- let base = takeBaseName $ takeBaseName path
- regex = makeRegex
- "find_dependency[[:space:]]*\\([[:space:]]*\
- \([^[:space:],$\\)]+)"
- case splitAt (length base - 6) base of
- (oldPkg, "Config") -> do
- let new = concatMap (take 1 . drop 1) $ match regex contents
- rename (B.pack oldPkg) newPkg
- at newPkg %=
- Just
- . (propagatedBuildInputs %~ S.union (S.fromList new))
- . fromMaybe mempty
- _ -> return ()
-
-findKF5Components :: (MonadIO m, MonadState Deps m) => Analyzer m
-findKF5Components pkg = awaitForever $ \(path, contents) ->
+findKF5Components :: (MonadIO m, MonadState (Map Text Package, Renames) m) => Analyzer m
+findKF5Components pkg _ = awaitForever $ \(path, contents) ->
when ("CMakeLists.txt" == takeFileName path) $ do
- let new = filter (not . cmakeReserved)
+ let new = S.fromList
+ $ map ("kf5" <>)
+ $ map (T.toLower . T.decodeUtf8)
+ $ filter (not . cmakeReserved)
$ filter (not . B.null)
$ concatMap B.words
$ concatMap (take 1 . drop 1)
@@ -61,12 +43,34 @@ findKF5Components pkg = awaitForever $ \(path, contents) ->
regex = makeRegex
"find_package[[:space:]]*\\([[:space:]]*KF5\
\[[:space:]]*([#\\.${}_[:alnum:][:space:]]+)\\)"
- ix pkg . buildInputs %= S.union (S.fromList $ map ("KF5" <>) new)
+ _1 . ix pkg . Package.buildInputs <>= new
-findQt5Components :: (MonadIO m, MonadState Deps m) => Analyzer m
-findQt5Components pkg = awaitForever $ \(path, contents) ->
+propagateKF5Deps :: (MonadIO m, MonadState (Map Text Package, Renames) m) => Analyzer m
+propagateKF5Deps pkg _ = awaitForever $ \(path, contents) ->
+ when (".cmake" `isPrefixOf` takeExtensions path) $ do
+ let base = T.pack $ takeBaseName $ takeBaseName path
+ regex = makeRegex
+ "find_dependency[[:space:]]*\\([[:space:]]*\
+ \([^[:space:],$\\)]+)"
+ case T.splitAt (T.length base - 6) base of
+ (upstream, "Config") -> do
+ let new = S.fromList
+ $ map (T.toLower . T.decodeUtf8)
+ $ filter (not . cmakeReserved)
+ $ filter (not . B.null)
+ $ concatMap (take 1 . drop 1)
+ $ match regex contents
+ _1 . ix pkg . Package.propagatedBuildInputs <>= new
+ _2 . at (T.toLower upstream) .= Just pkg
+ _ -> return ()
+
+findQt5Components :: (MonadIO m, MonadState (Map Text Package, Renames) m) => Analyzer m
+findQt5Components pkg _ = awaitForever $ \(path, contents) ->
when ("CMakeLists.txt" == takeFileName path) $ do
- let new = filter (not . cmakeReserved)
+ let new = S.fromList
+ $ map ("qt5" <>)
+ $ map (T.toLower . T.decodeUtf8)
+ $ filter (not . cmakeReserved)
$ filter (not . B.null)
$ concatMap B.words
$ concatMap (take 1 . drop 1)
@@ -74,7 +78,7 @@ findQt5Components pkg = awaitForever $ \(path, contents) ->
regex = makeRegex
"find_package[[:space:]]*\\([[:space:]]*Qt5\
\[[:space:]]*([#\\.${}_[:alnum:][:space:]]+)\\)"
- ix pkg . buildInputs %= S.union (S.fromList $ map ("Qt5" <>) new)
+ _1 . ix pkg . Package.buildInputs <>= new
cmakeReserved :: ByteString -> Bool
cmakeReserved bs = or $ map ($ bs)
@@ -86,67 +90,15 @@ cmakeReserved bs = or $ map ($ bs)
, (==) "COMPONENTS"
, (==) "REQUIRED"
, (==) "CONFIG"
+ , (==) "NO_MODULE"
+ , (==) "QUIET"
+ , (==) "CTest"
]
-kf5Analyzers :: (MonadIO m, MonadState Deps m) => [Analyzer m]
+kf5Analyzers :: (MonadIO m, MonadState (Map Text Package, Renames) m) => [Analyzer m]
kf5Analyzers =
[ findKF5Components
, findQt5Components
- , renameKF5Pkgs
, propagateKF5Deps
]
++ cmakeAnalyzers
-
-kf5PostAnalyze :: MonadState Deps m => m ()
-kf5PostAnalyze = do
- moveNativeInputs
- movePropagatedInputs
- moveUserEnvPkgs
-
-moveNativeInputs :: MonadState Deps m => m ()
-moveNativeInputs = deps %= M.map makeNative
- where
- makeNative = execState $ forM_ native $ \dep -> do
- hasDep <- use (buildInputs.to (S.member dep))
- when hasDep $ do
- buildInputs %= S.delete dep
- nativeBuildInputs %= S.insert dep
- hasPropDep <- use (propagatedBuildInputs.to (S.member dep))
- when hasPropDep $ do
- propagatedBuildInputs %= S.delete dep
- propagatedNativeBuildInputs %= S.insert dep
- native = [ "BISON"
- , "extra-cmake-modules"
- , "FLEX"
- , "kdoctools"
- , "ki18n"
- , "LibXslt"
- , "Perl"
- , "PythonInterp"
- ]
-
-movePropagatedInputs :: MonadState Deps m => m ()
-movePropagatedInputs = deps %= M.map propagate
- where
- propagate = execState $ forM_ propagated $ \dep -> do
- hasDep <- use (buildInputs.to (S.member dep))
- when hasDep $ do
- buildInputs %= S.delete dep
- propagatedBuildInputs %= S.insert dep
- hasNativeDep <- use (nativeBuildInputs.to (S.member dep))
- when hasNativeDep $ do
- nativeBuildInputs %= S.delete dep
- propagatedNativeBuildInputs %= S.insert dep
- propagated = [ "extra-cmake-modules" ]
-
-moveUserEnvPkgs :: MonadState Deps m => m ()
-moveUserEnvPkgs = deps %= M.map propagate
- where
- propagate = execState $ forM_ userEnv $ \dep -> do
- hasDep <- use (buildInputs.to (S.member dep))
- hasNativeDep <- use (buildInputs.to (S.member dep))
- hasPropDep <- use (buildInputs.to (S.member dep))
- hasPropNativeDep <- use (buildInputs.to (S.member dep))
- when (hasDep || hasNativeDep || hasPropDep || hasPropNativeDep)
- $ propagatedUserEnvPkgs %= S.insert dep
- userEnv = [ "SharedMimeInfo" ]