only rebuild grammar when source has been modified
This commit is contained in:
parent
c25ca6c0cb
commit
e7160485b6
25
Setup.hs
25
Setup.hs
|
@ -3,16 +3,31 @@ import System.Process
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
|
||||||
libdir :: String
|
target :: String
|
||||||
libdir = "src"
|
target = "src/Hm"
|
||||||
|
|
||||||
|
source :: String
|
||||||
|
source = "hm.cf"
|
||||||
|
|
||||||
|
regenerateGrammar :: IO ()
|
||||||
|
regenerateGrammar = do
|
||||||
|
callProcess "bnfc" ["-d", "--text-token", "--functor", source]
|
||||||
|
removePathForcibly target
|
||||||
|
renameDirectory "Hm" target
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
(a:_) <- getArgs
|
(a:_) <- getArgs
|
||||||
if a == "build"
|
if a == "build"
|
||||||
then do
|
then do
|
||||||
callProcess "bnfc" ["-d", "--text-token", "--functor", "hm.cf"]
|
b <- doesDirectoryExist target
|
||||||
removePathForcibly (libdir <> "/Hm")
|
if not b
|
||||||
renameDirectory "Hm" (libdir <> "/Hm")
|
then regenerateGrammar
|
||||||
|
else do
|
||||||
|
sourceDate <- getModificationTime source
|
||||||
|
targetDate <- getModificationTime target
|
||||||
|
if sourceDate >= targetDate
|
||||||
|
then regenerateGrammar
|
||||||
|
else pure ()
|
||||||
else pure ()
|
else pure ()
|
||||||
defaultMain
|
defaultMain
|
||||||
|
|
1
hm.cabal
1
hm.cabal
|
@ -18,6 +18,7 @@ custom-setup
|
||||||
, Cabal >= 2.4
|
, Cabal >= 2.4
|
||||||
, process >= 1
|
, process >= 1
|
||||||
, directory >= 1
|
, directory >= 1
|
||||||
|
, time >= 1
|
||||||
|
|
||||||
library
|
library
|
||||||
ghc-options: -Werror=incomplete-patterns -Wall -fno-warn-name-shadowing
|
ghc-options: -Werror=incomplete-patterns -Wall -fno-warn-name-shadowing
|
||||||
|
|
Loading…
Reference in New Issue
Block a user