Fix ifBuildable
[ghc-hetmet.git] / libraries / ifBuildable.hs
1 -- Returns exitcode 0 if the given package is buildable or is a boot package,
2 -- and 1 otherwise.
3
4 module Main (main) where
5
6 import Control.Monad
7 import System.Directory
8 import System.Environment
9 import System.Exit
10 import System.IO
11
12 main :: IO ()
13 main = do args <- getArgs
14           case args of
15               [packagesFile, package] ->
16                   doit packagesFile package
17               _ ->
18                   error "Syntax: ifBuildable <packages-file> <package>"
19
20 doit :: FilePath -> String -> IO ()
21 doit packagesFile package
22  = do setCurrentDirectory package
23       unbuildable <- doesFileExist "unbuildable"
24       if not unbuildable
25          then exitWith ExitSuccess
26          else do mustBeBuildables <- getMustBeBuildables packagesFile
27                  if package `elem` mustBeBuildables
28                      then exitWith ExitSuccess
29                      else do hPutStrLn stderr "Warning: Package is unbuildable"
30                              exitWith (ExitFailure 1)
31
32 getMustBeBuildables :: FilePath -> IO [String]
33 getMustBeBuildables packagesFile
34  = do xs <- readFile packagesFile
35       let nonCommentLines = filter (("#" /=) . take 1) $ lines xs
36           requiredLines = filter ((2 == ) . length) $ map words nonCommentLines
37           requiredLibraries = [ x | 'l':'i':'b':'r':'a':'r':'i':'e':'s':'/':x
38                                     <- map head requiredLines ]
39       return $ filter ("editline" /=) requiredLibraries
40