-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
55 lines (45 loc) · 1.64 KB
/
Main.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
import Development.Shake
( Rules, CmdOption(Cwd, Shell), (%>)
, phony, cmd, need, shakeArgs, shakeOptions, want
)
import Development.Shake.FilePath ((<.>), (</>))
main :: IO ()
main = shakeArgs shakeOptions $ do
want ["cabal-files"]
mapM_ formatRoot dhallRootImports
mapM_ formatPkg dhallPkgs
mapM_ hpack dhallPkgs
mapM_ cabal dhallCabal
phony "dhall-format" $ need $ ("dhall-format-" ++) <$> dhallPkgs ++ dhallRootImports
phony "hpack-dhall" $ need $ ("hpack-dhall-" ++) <$> dhallPkgs
phony "cabal-files" $ need $ (\(x, y) -> x </> y <.> "cabal") <$> dhallCabal
type Folder = String
type Pkg = String
-- | The names of the folders for dhall-format and hpack-dhall.
dhallPkgs :: [Folder]
dhallPkgs = fst <$> dhallCabal
-- | Pairs of package folder name used by dhall and the produced cabal file
-- name.
dhallCabal :: [(Folder, Pkg)]
dhallCabal =
[ ("build", "build-ghc-corroborate")
, ("ghc-corroborate", "ghc-corroborate")
]
dhallRootImports :: [String]
dhallRootImports = ["defaults"]
formatPkg :: Folder -> Rules ()
formatPkg folder =
phony ("dhall-format-" ++ folder)
$ cmd Shell ("dhall format " ++ (folder </> "package.dhall"))
formatRoot :: String -> Rules ()
formatRoot x =
phony ("dhall-format-" ++ x)
$ cmd Shell ("dhall format " ++ (x <.> ".dhall"))
hpack :: Folder -> Rules ()
hpack folder =
phony ("hpack-dhall-" ++ folder) $ do
need ["dhall-format-" ++ folder]
cmd (Cwd folder) Shell "dhall-hpack-cabal --package-dhall=package.dhall"
cabal :: (Folder, Pkg) -> Rules ()
cabal (folder, pkg) =
folder </> pkg <.> "cabal" %> \_ -> need ["hpack-dhall-" ++ folder]