forked from GaloisInc/saw-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.hs
36 lines (28 loc) · 1.11 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Control.Exception
import Control.Monad (unless)
import Distribution.Simple
import Distribution.Simple.BuildPaths (autogenPackageModulesDir)
import Distribution.PackageDescription (emptyHookedBuildInfo, allBuildInfo)
import System.Directory (createDirectoryIfMissing, findExecutable)
import System.FilePath ((</>))
import System.Process (readProcess)
import System.Exit
main = defaultMainWithHooks myHooks
where myHooks = simpleUserHooks { buildHook = myBuild }
myBuild pd lbi uh flags = do
let dir = autogenPackageModulesDir lbi
createDirectoryIfMissing True dir
hasGit <- findExecutable "git"
let gitfailure :: SomeException -> IO String
gitfailure _e = return "<non-dev-build> "
desc <- case hasGit of
Just git -> readProcess "git" ["describe", "--always", "--dirty"] ""
`catch` gitfailure
Nothing -> return "<VCS-less build> "
writeFile (dir </> "GitRev.hs") $ unlines
[ "module GitRev where"
, "hash :: String"
, "hash = " ++ show (init desc)
]
unless (null $ allBuildInfo pd) $
(buildHook simpleUserHooks) pd lbi uh flags