summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-12-21 18:48:16 -0500
committerBen Sima <ben@bsima.me>2021-12-21 18:48:16 -0500
commit8e2eede487b24908c89d60bce272e4269135e4ec (patch)
treeb35467c72efe19b0d62e56abcc2aefe0840ccc42 /Biz
parentc28c544b933cfb3ef3152be922248e9bbe89811e (diff)
Extract repl program from bild
This is basically building on top of bild's analysis, which is great becuase it means that bild is becoming a useful tool rather than a monolithic do-everything job runner. The eventual goal is for the bild analysis to be much more useful, maybe even provide data to remote repls or language-server or whatever.
Diffstat (limited to 'Biz')
-rw-r--r--Biz/Bild.hs39
-rw-r--r--Biz/Bild.nix10
-rw-r--r--Biz/Bild/ShellHook.sh1
-rwxr-xr-xBiz/Ide/repl20
-rw-r--r--Biz/Test.hs5
5 files changed, 31 insertions, 44 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index 845daf1..ce97807 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -44,8 +44,6 @@
--
-- * flags modify the way to interact with the build, some ideas:
--
--- * -s = jump into a shell and/or repl
---
-- * -p = turn on profiling
--
-- * -t = limit build by type (file extension)
@@ -68,16 +66,6 @@
-- This will build the file at ./A/B.hs, which translates to something like
-- `ghc --make A.B`.
--
--- > bild -s <target>
---
--- Starts a repl/shell for target.
---
--- - if target.hs, load ghci
--- - if target.scm, load scheme repl
--- - if target.clj, load a clojure repl
--- - if target.nix, load nix-shell
--- - and so on.
---
-- > bild -p <target>
--
-- build target with profiling (if available)
@@ -187,8 +175,6 @@ move args =
|> 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
@@ -468,31 +454,6 @@ test loud Target {..} = case compiler of
>> Log.br
>> pure Exit.ExitSuccess
-repl :: Bool -> Target -> IO Exit.ExitCode
-repl _ Target {..} = do
- root <- Env.getEnv "BIZ_ROOT"
- case compiler of
- c
- | c `elem` [GhcExe, GhcLib] ->
- -- this is a complicated set of string joins which basically means to
- -- create a command like this:
- -- nix-shell -E "with import Biz/Bild.nix {}; mkGhcPackageSet (h: [h.pkg])"
- [ "--expr",
- "with import " <> root <> "/Biz/Bild.nix {};"
- <> "mkGhcPackageSet (h: ["
- <> joinWith " " ["h." <> d | d <- Set.toList langdeps]
- <> "])",
- -- Set.toList sysdeps,
- "--command",
- "ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci " <> path
- ]
- |> 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
root <- Env.getEnv "BIZ_ROOT"
diff --git a/Biz/Bild.nix b/Biz/Bild.nix
index eb4821d..baac934 100644
--- a/Biz/Bild.nix
+++ b/Biz/Bild.nix
@@ -18,11 +18,11 @@ let
haskellDeps = import ./Bild/Deps/Haskell.nix;
- mkGhcPackageSet = nixpkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle;
+ ghcWith = nixpkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle;
#mkGhcjsPackageSet = nixpkgs.haskell.packages.${ghcjsCompiler}.ghcWithPackages;
- ghcPackageSetFull = mkGhcPackageSet haskellDeps;
- ghcPackageSetBild = mkGhcPackageSet (hpkgs: with hpkgs; [
+ ghcPackageSetFull = ghcWith haskellDeps;
+ ghcPackageSetBild = ghcWith (hpkgs: with hpkgs; [
aeson async base bytestring conduit conduit-extra containers directory
docopt filepath process protolude rainbow regex-applicative split tasty
tasty-hunit tasty-quickcheck text
@@ -31,7 +31,7 @@ let
in rec {
inherit (nixpkgs) lib stdenv sources;
- inherit mkGhcPackageSet;
+ inherit ghcWith;
# a standard nix build for `bild` - this should be the only hand-written
# builder we need
@@ -90,7 +90,7 @@ in rec {
ghc = main:
let
data = analyze main;
- ghc = mkGhcPackageSet (hp: selectAttrs data.langdeps hp);
+ ghc = ghcWith (hp: selectAttrs data.langdeps hp);
module = lib.strings.concatStringsSep "." data.namespace.path;
in stdenv.mkDerivation {
name = module;
diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh
index 274ab4e..96c2e56 100644
--- a/Biz/Bild/ShellHook.sh
+++ b/Biz/Bild/ShellHook.sh
@@ -3,6 +3,7 @@ function help() {
echo "bizdev" | figlet | lolcat
echo ""
echo " bild compile code"
+ echo " repl start a repl"
echo " ci run all builds and tests"
echo " deps manage dependencies with niv"
echo " help show this message"
diff --git a/Biz/Ide/repl b/Biz/Ide/repl
new file mode 100755
index 0000000..79e7875
--- /dev/null
+++ b/Biz/Ide/repl
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+#
+# a simple complement to bild which only deals with launching repls
+#
+# > repl <target>
+#
+# Starts a repl/shell for target.
+#
+# - if target.hs, load ghci
+# - TODO: if target.scm, load scheme repl
+# - TODO: if target.nix, load nix-shell
+##
+ set -e
+ target=${1:?}
+ json=$(bild --json $1)
+ langdeps=$(jq --raw-output '.[].langdeps | join(" ")' <<< $json)
+ nix-shell \
+ --packages "(import $BIZ_ROOT/Biz/Bild.nix {}).ghcWith (h: with h; [$langdeps])" \
+ --command "ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci $target"
+##
diff --git a/Biz/Test.hs b/Biz/Test.hs
index 31a8831..b6c2816 100644
--- a/Biz/Test.hs
+++ b/Biz/Test.hs
@@ -4,6 +4,7 @@ module Biz.Test
( Tree,
run,
group,
+ none,
unit,
prop,
with,
@@ -97,3 +98,7 @@ infixl 2 @=?
a @?= b = a HUnit.@?= b
infixr 2 @?=
+
+-- | For usage in 'Biz.Cli.Plan' when you have no tests.
+none :: Tree
+none = group "none" []