-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSetup.hs
48 lines (30 loc) · 985 Bytes
/
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
36
37
38
39
40
41
42
43
44
45
46
47
-- Copyright 2018 - Andreas Westerwick <[email protected]>
-- SPDX-License-Identifier: GPL-3.0-or-later
{-# LANGUAGE TemplateHaskell #-}
import Control.Exception
import Control.Monad
import Data.FileEmbed
import Distribution.Simple
import System.IO
import System.Environment
import System.Process
status :: FilePath
status = $(strToExp =<< makeRelativeToProject ".status")
main :: IO ()
main = do
checkGitTree
defaultMain
checkGitTree :: IO ()
checkGitTree = do
writeFile status "cabal build"
git ["status", "--short"] $ \ files -> do
if null files
then git ["rev-parse", "HEAD"] $ \ commit -> do
unless (length (take 256 commit) < 4)
$ writeFile status $ take 256 commit
else writeFile status "dirty"
git :: [String] -> (String -> IO ()) -> IO ()
git xs sink = withCreateProcess
(proc "git" xs) { std_out = CreatePipe }
(\ _ (Just i) _ _ -> sink =<< hGetContents i)
`catch` \ (SomeException e) -> hPutStrLn stderr (show e)