summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-07-25 14:49:11 -0700
committerBen Sima <ben@bsima.me>2020-07-25 14:49:11 -0700
commit6a6aa57afe94f8ffee3a648ca66aa16099714b94 (patch)
treeed4cee7997d9bf72e286d541abf380671ad785ce /Biz
parent3acaa1034b8d9da69acdc52d1fb8e03f50223488 (diff)
bild: port to haskell
Diffstat (limited to 'Biz')
-rw-r--r--Biz/Bild.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
new file mode 100644
index 0000000..565792e
--- /dev/null
+++ b/Biz/Bild.hs
@@ -0,0 +1,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 _ _ [] = []