diff options
author | Ben Sima <ben@bsima.me> | 2020-07-25 14:49:11 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-07-25 14:49:11 -0700 |
commit | 6a6aa57afe94f8ffee3a648ca66aa16099714b94 (patch) | |
tree | ed4cee7997d9bf72e286d541abf380671ad785ce | |
parent | 3acaa1034b8d9da69acdc52d1fb8e03f50223488 (diff) |
bild: port to haskell
-rw-r--r-- | .envrc | 7 | ||||
-rw-r--r-- | Alpha.hs | 1 | ||||
-rw-r--r-- | Biz/Bild.hs | 54 | ||||
-rw-r--r-- | Hero/Part.hs | 0 | ||||
-rwxr-xr-x | bild | 25 | ||||
-rw-r--r-- | nix/build.nix | 44 |
6 files changed, 92 insertions, 39 deletions
@@ -1,16 +1,9 @@ PATH_add $PWD export BIZ_ROOT=$PWD -export HERO_PORT=3000 -export HERO_NODE=$BIZ_ROOT/_bild/Hero.Node/static -export HERO_KEEP=$BIZ_ROOT/_keep -export HERO_SKEY=$BIZ_ROOT/_skey - export GUILE_LOAD_PATH=$PWD export EDITOR=vim if type lorri &>/dev/null then eval "$(lorri direnv)" -else - use nix fi @@ -20,6 +20,7 @@ module Alpha ( -- * Re-export Protolude module X, + String, -- * Applying (<|), 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 _ _ [] = [] diff --git a/Hero/Part.hs b/Hero/Part.hs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Hero/Part.hs @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -set -exo pipefail -prefix=$(echo $PWD | sed -e "s|^$BIZ_ROOT/*||g" -e "s|/|.|g") -if [[ "$prefix" == "" ]] -then - # TODO: make this accept any number of build targets - target="$1" -else - target="$prefix.$1" -fi -log=$(mktemp) -nix-build \ - -o "$BIZ_ROOT/_bild/$target" \ - $BIZ_ROOT/default.nix \ - --attr "$target" \ - --show-trace \ - 2>&1 \ - | tee $log -if [[ ${PIPESTATUS[0]} != 0 ]] -then - o=$(gawk "match(\$0, /'(.*)'\sfailed/, a) {print a[1]}" $log \ - | head -n 1) - nix log $o -fi - diff --git a/nix/build.nix b/nix/build.nix index 7335159..6a12cf5 100644 --- a/nix/build.nix +++ b/nix/build.nix @@ -107,21 +107,51 @@ in { nixpkgs.python37Packages.pylint nixpkgs.wemux ]; + EXAMPLE = "hi"; shellHook = '' - echo "bizdev" | ${nixpkgs.figlet}/bin/figlet | ${nixpkgs.lolcat}/bin/lolcat - echo "(be sure to run 'nix-shell' to get the build functions)" - echo "-------------------------------------------------------" - echo "" + function help() { + echo "" + echo "bizdev" | ${nixpkgs.figlet}/bin/figlet | ${nixpkgs.lolcat}/bin/lolcat + echo "" + echo " bild compile code" + echo " deps manage dependencies with niv" + echo " ghci start ghci with correct options" + echo " help show this message" + echo " hero compile and start a dev server for herocomics.app" + echo " lint auto-lint all changed files" + echo " ./push TODO: convert to haskell" + echo " ./ship TODO: convert to haskell" + } - function repl() { - ghci -i$BIZ_ROOT -ghci-script "$BIZ_ROOT/.ghci" + function bild() { + runghc Biz.Bild $@ } function deps() { niv --sources-file $BIZ_ROOT/nix/sources.json $@ } - alias lint=$BIZ_ROOT/Biz/lint.py + function ghci() { + ghci -i$BIZ_ROOT -ghci-script "$BIZ_ROOT/.ghci" + } + + function hero() { + out="_bild/nix" + export HERO_PORT=3000 + export HERO_NODE=$BIZ_ROOT/$out/Hero.Node/static + export HERO_KEEP=$BIZ_ROOT/_keep + export HERO_SKEY=$BIZ_ROOT/_skey + b="runghc Biz.Bild" + rg --files \ + | entr -rcs \ + "$b Hero.Host && $b Hero.Node && $out/Hero.Host/bin/mmc" + } + + function lint() { + alias lint=$BIZ_ROOT/Biz/lint.py + } + + help ''; }; |