ifBuildable.hs 1.41 KB
Newer Older
1
-- Returns exitcode 0 if the given package is buildable or is a boot package,
2
-- and 1 otherwise.
Ian Lynagh's avatar
Ian Lynagh committed
3
4
5
6

module Main (main) where

import Control.Monad
7
import System.Directory
Ian Lynagh's avatar
Ian Lynagh committed
8
9
import System.Environment
import System.Exit
10
import System.IO
Ian Lynagh's avatar
Ian Lynagh committed
11
12

main :: IO ()
13
14
main = do args <- getArgs
          case args of
Ian Lynagh's avatar
Ian Lynagh committed
15
16
              [packagesFile, package] ->
                  doit packagesFile package
17
              _ ->
Ian Lynagh's avatar
Ian Lynagh committed
18
                  error "Syntax: ifBuildable <packages-file> <package>"
19

20
doit :: FilePath -> String -> IO ()
Ian Lynagh's avatar
Ian Lynagh committed
21
doit packagesFile package
22
23
 = do setCurrentDirectory package
      unbuildable <- doesFileExist "unbuildable"
24
25
      if not unbuildable
         then exitWith ExitSuccess
Ian Lynagh's avatar
Ian Lynagh committed
26
         else do mustBeBuildables <- getMustBeBuildables packagesFile
27
                 if package `elem` mustBeBuildables
28
29
30
                     then exitWith ExitSuccess
                     else do hPutStrLn stderr "Warning: Package is unbuildable"
                             exitWith (ExitFailure 1)
Ian Lynagh's avatar
Ian Lynagh committed
31

32
getMustBeBuildables :: FilePath -> IO [String]
Ian Lynagh's avatar
Ian Lynagh committed
33
34
35
getMustBeBuildables packagesFile
 = do xs <- readFile packagesFile
      let nonCommentLines = filter (("#" /=) . take 1) $ lines xs
Ian Lynagh's avatar
Ian Lynagh committed
36
          requiredLines = filter ((3 == ) . length) $ map words nonCommentLines
Ian Lynagh's avatar
Ian Lynagh committed
37
38
39
          requiredLibraries = [ x | 'l':'i':'b':'r':'a':'r':'i':'e':'s':'/':x
                                    <- map head requiredLines ]
      return $ filter ("editline" /=) requiredLibraries
40