never executed always true always false
1 module Reanimate.Driver.Compile ( compile ) where
2
3 import Reanimate.Driver.Server (findOwnSource)
4 import System.Directory
5 import System.Exit
6 import System.FilePath
7 import System.Process
8 import System.IO
9
10 compile :: [String] -> IO ()
11 compile opts = do
12 mbSelf <- findOwnSource
13 case mbSelf of
14 Nothing -> do
15 hPutStrLn stderr
16 "Failed to find source code. Did you already compile the animations?\n\
17 \Try running again without the --compile flag."
18 exitFailure
19 Just self -> do
20 let selfDir = takeDirectory self
21 selfName = takeBaseName self
22 outDir = selfDir </> ".reanimate" </> selfName
23 target = outDir </> selfName
24 ghcOptions =
25 ["-rtsopts", "--make", "-threaded", "-O2"] ++
26 ["-odir", outDir, "-hidir", outDir] ++
27 [self, "-o", target]
28 createDirectoryIfMissing True outDir
29 withCurrentDirectory selfDir $ do
30 checkExitCode =<< rawSystem "stack" (["ghc", "--"] ++ ghcOptions)
31 checkExitCode =<< rawSystem target opts
32
33 checkExitCode :: ExitCode -> IO ()
34 checkExitCode ExitSuccess = return ()
35 checkExitCode (ExitFailure n) = exitWith (ExitFailure n)