forked from avh4/elm-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
34 lines (26 loc) · 1.22 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
import Distribution.Simple
import Distribution.Simple.BuildPaths (autogenModulesDir)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo)
import Distribution.Simple.Setup (BuildFlags)
import Distribution.PackageDescription (PackageDescription, emptyHookedBuildInfo)
import System.Directory (createDirectoryIfMissing)
import System.FilePath ((</>))
import System.Process (readProcess)
main = defaultMainWithHooks $ simpleUserHooks { buildHook = myBuildHook }
myBuildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
myBuildHook packageDescription buildInfo userHooks buildFlags =
do
createDirectoryIfMissing True (autogenModulesDir buildInfo)
writeCustomFile (autogenModulesDir buildInfo </> "Build_elm_format.hs")
buildHook simpleUserHooks packageDescription buildInfo userHooks buildFlags
writeCustomFile :: FilePath -> IO ()
writeCustomFile filepath = do
putStrLn $ "Generating " ++ filepath ++ "..."
desc <- readProcess "git" ["describe", "--abbrev=8", "--always"] ""
now <- readProcess "date" ["+%s"] ""
writeFile filepath $ unlines
[ "module Build_elm_format where"
, ""
, "gitDescribe :: String"
, "gitDescribe = " ++ show (init desc)
]