FIX #1559, #1560. Rearrange the way we do ifBuildable...
[ghc-hetmet.git] / libraries / ifBuildable.hs
1 -- Returns exitcode 0 if the given package is buildable or is a core 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               [package] ->
16                   doit package
17               _ ->
18                   error "Syntax: ifBuildable <package>"
19
20 doit :: String -> IO ()
21 doit package
22  = do setCurrentDirectory package
23       unbuildable <- doesFileExist "unbuildable"
24       if not unbuildable
25          then exitWith ExitSuccess
26          else do mustBeBuildables <- getMustBeBuildablePackages
27                  if package `elem` mustBeBuildables
28                      then exitWith ExitSuccess
29                      else do hPutStrLn stderr "Warning: Package is unbuildable"
30                              exitWith (ExitFailure 1)
31
32 getMustBeBuildablePackages :: IO [String]
33 getMustBeBuildablePackages
34  = do xs <- readFile "../core-packages"
35       return $ filter ("readline" /=) $ lines xs