blob: 565792ed212dd82fefcb9bbbc4c2bdfe3ae192b3 (
plain)
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
|
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- | A general purpose build tool.
--
-- - with a nix build, results are linked in _bild/nix/<target>
-- - for a dev build, results are stored in _bild/dev/<target>
module Biz.Bild where
import Alpha
import qualified System.Directory as Dir
import qualified System.Environment as Env
import qualified System.Exit as Exit
import System.FilePath ((</>))
import qualified System.Process as Process
main :: IO ()
main = Env.getArgs /> head >>= \case
Nothing -> do
basename <- Env.getProgName
Exit.die <| "usage: " <> basename <> " <target>"
Just target -> nixBuild target
{-
TODO:
- parse target syntax
- write dev builder for ghc/ghcjs
-}
type Target = String
nixBuild :: Target -> IO ()
nixBuild target = do
root <- Env.getEnv "BIZ_ROOT"
cwd <- Dir.getCurrentDirectory
let qualifiedTarget = reps root "" cwd <> target
Process.callProcess
"nix-build"
[ "-o",
root </> "_bild/nix" </> qualifiedTarget,
root </> "default.nix",
"--attr",
qualifiedTarget
]
-- | Replace 'a' in 's' with 'b'.
reps :: String -> String -> String -> String
reps a b s@(x : xs) =
if isPrefixOf a s
then-- then, write 'b' and replace jumping 'a' substring
b ++ reps a b (drop (length a) s)
else-- then, write 'x' char and try to replace tail string
x : reps a b xs
reps _ _ [] = []
|