File: AptGetBuildDeps.hs

package info (click to toggle)
haskell-debian 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 480 kB
  • sloc: haskell: 3,874; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Main where

import Debian.Control  -- (Control(..),lookupP,parseControlFromFile)
import Debian.Relation
import System.Process
import System.Exit
import System.Environment

lookupBuildDeps :: FilePath -> IO [BinPkgName]
lookupBuildDeps fp =
    do control <- parseControlFromFile fp
       case control of
         (Left e) -> error (show e)
         (Right (Control [])) -> error "Empty control file"
         (Right (Control (p:_))) ->
             return $ ((lookupDepends "Build-Depends" p) ++
                       (lookupDepends "Build-Depends-Indep" p))

lookupDepends :: String -> Paragraph' String -> [BinPkgName]
lookupDepends key paragraph =
    case fieldValue key paragraph of
                Nothing -> [] -- (Left $ "could not find key " ++ key)
                (Just relationString) ->
                    case parseRelations relationString of
                      (Left e) -> error (show e)
                      (Right andRelations) ->
                          map pkgName (concatMap (take 1) andRelations)
    where
      pkgName :: Relation -> BinPkgName
      pkgName (Rel name _ _) = name


aptGetInstall :: [String] -> [BinPkgName] -> IO ExitCode
aptGetInstall options pkgnames =
    do (_,_,_,ph)
         <- createProcess $ proc "apt-get" $ ["install"] ++ options ++ map unBinPkgName pkgnames
       waitForProcess ph

main :: IO ()
main
  = do
    options <- getArgs
    lookupBuildDeps "debian/control" >>= aptGetInstall options >>= exitWith