on master help sign in
Avoid calling gcc to compile unless you have to (speed up iterations)
commit1affc8e388d8bddacc386203ba11790286c0cbc8 authorNeil Mitchell <ndmitchell@gmail.com> dateWed 3 Jan 2018, 21:54 (9 years ago) parente2e3b16
1 file changed+24−2
gen/Main.hs+24−2
gen/Main.hs+24−2
@@ -3,12 +3,17 @@ module Main(main) where
33
44import Lib
55import Parser
6−import Control.Monad
6+import Control.Monad.Extra
7+import System.Process.Extra
8+import System.Directory
9+import Data.Maybe
10+import System.IO.Extra
11+import System.FilePath
12+import System.Info.Extra
713
814
915main :: IO ()
1016main = do
11− writeFile "test.h" $ unlines $ compile html
1217 forM_ examples $ \(b, src) -> do
1318 putStrLn ""
1419 putStrLn src
@@ -16,7 +21,24 @@ main = do
1621 print res
1722 print (trail, err)
1823 putStrLn $ rerender src res
24+ writeFileChanged "test.h" $ unlines $ compile html
25+ buildRule ["test.h","test.c"] ["gen" <.> (if isWindows then "exe" else "")] $
26+ system_ "gcc test.c -o gen"
27+ system_ "gen"
1928
29+writeFileChanged :: FilePath -> String -> IO ()
30+writeFileChanged file new = do
31+ old <- ifM (doesFileExist file) (readFile' file) (return "")
32+ when (old /= new) $
33+ writeFile file new
34+
35+buildRule :: [FilePath] -> [FilePath] -> IO () -> IO ()
36+buildRule from to act = do
37+ let modTime x = ifM (doesFileExist x) (Just <$> getModificationTime x) (return Nothing)
38+ from <- mapM modTime from
39+ to <- mapM modTime to
40+ when (any isNothing (from ++ to) || maximum from >= minimum to)
41+ act
2042
2143examples :: [(Bool, String)]
2244examples =