summaryrefslogtreecommitdiff
path: root/Biz/Bild.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-12-13 18:28:30 -0500
committerBen Sima <ben@bsima.me>2021-12-13 18:28:30 -0500
commit81245494a9e59122b0a747762a08031ce3dff6f3 (patch)
tree683cb7f884d75599077122d1d64e3c8b7807cbd6 /Biz/Bild.hs
parentbb386dd6f0127a92675312a8022cc7ac8aaa4cdc (diff)
Add --repl for Haskell programs
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r--Biz/Bild.hs61
1 files changed, 42 insertions, 19 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index 007bda8..17fb883 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -181,20 +181,21 @@ move args =
+> exitSummary
where
printOrBuild :: Map FilePath Target -> IO [ExitCode]
- printOrBuild analyses =
- if args `Cli.has` Cli.longOption "analyze"
- then
- analyses
- |> Map.elems
- |> putJSON
- >> pure [Exit.ExitSuccess]
- else do
- root <- Env.getEnv "BIZ_ROOT"
- createHier root
- analyses
- |> Map.toList
- |> map snd
- |> traverse (build isTest isLoud)
+ printOrBuild analyses
+ | args `Cli.has` Cli.longOption "json" =
+ analyses
+ |> Map.elems
+ |> putJSON
+ >> pure [Exit.ExitSuccess]
+ | args `Cli.has` Cli.longOption "repl" =
+ traverse (repl isLoud) (Map.elems analyses)
+ | otherwise = do
+ root <- Env.getEnv "BIZ_ROOT"
+ createHier root
+ analyses
+ |> Map.toList
+ |> map snd
+ |> traverse (build isTest isLoud)
isTest = args `Cli.has` Cli.longOption "test"
isLoud = args `Cli.has` Cli.longOption "loud"
putJSON = Aeson.encode .> ByteString.toStrict .> Char8.putStrLn
@@ -212,9 +213,10 @@ Usage:
bild [options] <target>...
Options:
+ --repl Start a repl for the target
--test Run tests on a target after building
--loud Show all output from compiler
- --analyze Only analyze and print as JSON, don't build
+ --json Only analyze and print as JSON, don't build
-h, --help Print this info
|]
@@ -238,7 +240,7 @@ data Compiler
| Guile
| NixBuild
| Copy
- deriving (Show, Generic, Aeson.ToJSON)
+ deriving (Eq, Show, Generic, Aeson.ToJSON)
data Target = Target
{ -- | Output name
@@ -463,9 +465,30 @@ test loud Target {..} = case compiler of
onFailure = Log.fail ["test", nschunk namespace] >> Log.br,
onSuccess = Log.pass ["test", nschunk namespace] >> Log.br
}
- _ -> do
- Log.warn ["test", nschunk namespace, "unavailable"] >> Log.br
- pure Exit.ExitSuccess
+ _ ->
+ Log.warn ["test", nschunk namespace, "unavailable"]
+ >> Log.br
+ >> pure Exit.ExitSuccess
+
+repl :: Bool -> Target -> IO Exit.ExitCode
+repl _ Target {..} =
+ case compiler of
+ c
+ | c `elem` [GhcExe, GhcLib] ->
+ [ ["--packages"],
+ ["haskellPackages." <> d | d <- Set.toList langdeps],
+ Set.toList sysdeps,
+ [ "--command",
+ "ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci " <> path
+ ]
+ ]
+ |> mconcat
+ |> Process.callProcess "nix-shell"
+ >> Exit.exitSuccess
+ _ ->
+ Log.fail ["repl", nschunk namespace, "not implemented"]
+ >> Log.br
+ >> Exit.exitFailure
build :: Bool -> Bool -> Target -> IO Exit.ExitCode
build andTest loud target@Target {..} = do