{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NoImplicitPrelude #-} -- | A general purpose build tool. -- -- - with a nix build, results are linked in _bild/nix/ -- - for a dev build, results are stored in _bild/dev/ 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 <> " " 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 _ _ [] = []