From 6a6aa57afe94f8ffee3a648ca66aa16099714b94 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 25 Jul 2020 14:49:11 -0700 Subject: bild: port to haskell --- Biz/Bild.hs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Biz/Bild.hs (limited to 'Biz') 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/ +-- - 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 _ _ [] = [] -- cgit v1.2.3