diff options
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 54 |
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 _ _ [] = [] |