-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetup.hs
87 lines (81 loc) · 2.01 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{- |
- Module : $Header$
- Description : The tempuhs web server Cabal setup file.
- Copyright : (c) plaimi 2015
- License : AGPL-3
-
- Maintainer : [email protected]
- -}
import Control.Exception
(
catch,
)
import Data.Text
(
pack,
toTitle,
unpack,
)
import Distribution.Simple
(
defaultMainWithHooks,
preBuild,
simpleUserHooks,
)
import System.Exit
(
ExitCode (ExitSuccess),
)
import System.IO.Error
(
isAlreadyExistsError,
ioeGetErrorString,
)
import System.Posix
(
createDirectory,
)
import System.Process
(
rawSystem,
)
import Text.Printf
(
printf,
)
import Plailude
main :: IO ()
-- | Generates data/src.tar.gz for us pre-building, so we can serve the source
-- code of the instance.
main = defaultMainWithHooks
$ simpleUserHooks
{ preBuild = \args buildFlags -> do
createDirectory "data" 0o755 `catch` \e ->
if' (isAlreadyExistsError e)
(return ())
(printf ("couldn't make the data directory: %s\n"
++ "please do it yourself. we need it!") $
unpack . toTitle . pack $ ioeGetErrorString e)
exitCode <- rawSystem "tar" $ tarOut ++ tarIn
putStrLn $ echoOut exitCode
preBuild simpleUserHooks args buildFlags
}
tarOut :: [String]
-- | The file generated by tar.
tarOut = ["cfz", "data/src.tar.gz"]
tarIn :: [String]
-- | The files passed to tar.
tarIn = ["Setup.hs"
,"tempuhs-server.cabal"
,"prop"
,"src"
,"src-exec"
,"test"
]
echoOut :: ExitCode -> String
-- | Make an output text to echo, depending on the passed in 'ExitCode'.
echoOut ExitSuccess = "'put src in data/src.tar.gz'"
echoOut _ = "'uh-oh! couldn't make a gzipped tarball of the src! "
++ "you need to put the src of your tempuhs instance in a "
++ "file \"data/src.tar.gz\" before building. this is to "
++ "comply with the GNU AGPLv3."