From 904de577261e7024373e7a42fd763184764238f9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 10 Oct 2023 13:15:59 -0400 Subject: Don't swallow namespace-parsing errors Previously, if there was a problem with the inputs and bild failed to determine the namespace, 'fromPath' would return 'Nothing' and then 'catMaybes' would drop the error-causing input altogether. In the one time that I had a bad input, this made debugging incredibly difficult. It's always a bad idea to swallow errors silently, so instead lets just kill the program if we have bad inputs. --- .envrc | 2 +- .vimrc | 6 +-- Biz/Bild.hs | 55 +++++++++++++++++++++---- Biz/Bild.nix | 27 ++++++------- Biz/Cloud/post-receive | 39 ------------------ Biz/Cloud/post-receive.bash | 39 ++++++++++++++++++ Biz/Dev/Dns.nix | 8 ---- Biz/Dev/Home.zone | 23 ----------- Biz/Dragons/env | 9 ----- Biz/Dragons/env.bash | 9 +++++ Biz/Ide/ftags | 21 ---------- Biz/Ide/ftags.bash | 21 ++++++++++ Biz/Ide/hoog | 17 -------- Biz/Ide/hoog.bash | 17 ++++++++ Biz/Ide/hooks/commit-msg | 2 - Biz/Ide/hooks/commit-msg.bash | 2 + Biz/Ide/hooks/post-checkout | 15 ------- Biz/Ide/hooks/post-checkout.bash | 15 +++++++ Biz/Ide/hooks/post-merge | 2 - Biz/Ide/hooks/post-merge.bash | 2 + Biz/Ide/hooks/pre-commit | 21 ---------- Biz/Ide/hooks/pre-commit.bash | 21 ++++++++++ Biz/Ide/hooks/pre-push | 58 --------------------------- Biz/Ide/hooks/pre-push.bash | 58 +++++++++++++++++++++++++++ Biz/Ide/mktags | 41 ------------------- Biz/Ide/mktags.bash | 41 +++++++++++++++++++ Biz/Ide/ns | 26 ------------ Biz/Ide/ns.bash | 26 ++++++++++++ Biz/Ide/push | 19 --------- Biz/Ide/push.bash | 19 +++++++++ Biz/Ide/repl | 87 ---------------------------------------- Biz/Ide/repl.bash | 87 ++++++++++++++++++++++++++++++++++++++++ Biz/Ide/run | 6 --- Biz/Ide/run.bash | 6 +++ Biz/Ide/ship | 23 ----------- Biz/Ide/ship.bash | 23 +++++++++++ Biz/Ide/tidy | 2 - Biz/Ide/tidy.bash | 2 + Biz/Ide/tips | 13 ------ Biz/Ide/tips.bash | 13 ++++++ Biz/Ide/version | 15 ------- Biz/Ide/version.bash | 15 +++++++ Biz/Namespace.hs | 17 +++++++- 43 files changed, 495 insertions(+), 475 deletions(-) delete mode 100755 Biz/Cloud/post-receive create mode 100755 Biz/Cloud/post-receive.bash delete mode 100644 Biz/Dev/Home.zone delete mode 100644 Biz/Dragons/env create mode 100644 Biz/Dragons/env.bash delete mode 100755 Biz/Ide/ftags create mode 100755 Biz/Ide/ftags.bash delete mode 100755 Biz/Ide/hoog create mode 100755 Biz/Ide/hoog.bash delete mode 100755 Biz/Ide/hooks/commit-msg create mode 100755 Biz/Ide/hooks/commit-msg.bash delete mode 100755 Biz/Ide/hooks/post-checkout create mode 100755 Biz/Ide/hooks/post-checkout.bash delete mode 100755 Biz/Ide/hooks/post-merge create mode 100755 Biz/Ide/hooks/post-merge.bash delete mode 100755 Biz/Ide/hooks/pre-commit create mode 100755 Biz/Ide/hooks/pre-commit.bash delete mode 100755 Biz/Ide/hooks/pre-push create mode 100755 Biz/Ide/hooks/pre-push.bash delete mode 100755 Biz/Ide/mktags create mode 100755 Biz/Ide/mktags.bash delete mode 100755 Biz/Ide/ns create mode 100755 Biz/Ide/ns.bash delete mode 100755 Biz/Ide/push create mode 100755 Biz/Ide/push.bash delete mode 100755 Biz/Ide/repl create mode 100755 Biz/Ide/repl.bash delete mode 100755 Biz/Ide/run create mode 100755 Biz/Ide/run.bash delete mode 100755 Biz/Ide/ship create mode 100755 Biz/Ide/ship.bash delete mode 100755 Biz/Ide/tidy create mode 100755 Biz/Ide/tidy.bash delete mode 100755 Biz/Ide/tips create mode 100755 Biz/Ide/tips.bash delete mode 100755 Biz/Ide/version create mode 100755 Biz/Ide/version.bash diff --git a/.envrc b/.envrc index fd99583..4193e77 100644 --- a/.envrc +++ b/.envrc @@ -41,4 +41,4 @@ # load local settings . ./.envrc.local ## - tips + tips.bash diff --git a/.vimrc b/.vimrc index 6a17fcf..c12316b 100644 --- a/.vimrc +++ b/.vimrc @@ -1,8 +1,8 @@ " requires: https://github.com/MarcWeber/vim-addon-local-vimrc augroup tags -au BufWritePost *.hs silent !$CODEROOT/Biz/Ide/mktags % -au BufWritePost *.hsc silent !$CODEROOT/Biz/Ide/mktags % -au BufWritePost *.lhs silent !$CODEROOT/Biz/Ide/mktags % +au BufWritePost *.hs silent !$CODEROOT/Biz/Ide/mktags.bash % +au BufWritePost *.hsc silent !$CODEROOT/Biz/Ide/mktags.bash % +au BufWritePost *.lhs silent !$CODEROOT/Biz/Ide/mktags.bash % augroup END set equalprg=ormolu diff --git a/Biz/Bild.hs b/Biz/Bild.hs index d8cdc6f..d178a83 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -10,6 +10,7 @@ -- | A specific-purpose build tool. -- -- : out bild +-- : run git -- -- == Design constraints -- @@ -157,7 +158,8 @@ main = Cli.Plan help move test_ pure |> Cli.main Test.group "Biz.Bild" [ test_bildBild, - test_bildExamples + test_bildExamples, + test_isGitIgnored ] test_bildBild :: Test.Tree @@ -196,11 +198,10 @@ move args = IO.hSetBuffering stdout IO.NoBuffering >> Env.getEnv "CODEROOT" +> \root -> Cli.getAllArgs args (Cli.argument "target") - |> filter (not <. Namespace.isCab) |> filterM Dir.doesFileExist + +> filterM (\x -> isGitIgnored x /> don't) +> traverse Dir.makeAbsolute - /> map (Namespace.fromPath root) - /> catMaybes + +> traverse (namespaceFromPathOrDie root) +> foldM analyze mempty /> Map.filter (namespace .> isBuildableNs) +> printOrBuild @@ -223,6 +224,11 @@ move args = Just n -> n printOrBuild :: Analysis -> IO [ExitCode] printOrBuild targets + | Map.null targets = + Log.wipe + >> Log.fail ["bild", "nothing to build"] + >> Log.br + >> exitWith (ExitFailure 1) | args `Cli.has` Cli.longOption "json" = Log.wipe >> putJSON targets >> pure [Exit.ExitSuccess] | otherwise = do @@ -233,6 +239,35 @@ move args = isLoud = args `Cli.has` Cli.longOption "loud" putJSON = Aeson.encode .> ByteString.Lazy.toStrict .> Char8.putStrLn +-- | Don't try to build stuff that isn't part of the git repo. +isGitIgnored :: FilePath -> IO Bool +isGitIgnored path = + Process.readProcessWithExitCode "git" ["check-ignore", path] "" + +> \case + (ExitSuccess, _, _) -> pure True + (ExitFailure _, _, _) -> pure False + +test_isGitIgnored :: Test.Tree +test_isGitIgnored = + Test.group + "isGitIgnored" + [ Test.unit "filters one" <| do + res <- isGitIgnored "_" + res @=? True, + Test.unit "filters many" <| do + traverse isGitIgnored ["Biz/Bild.hs", "__pycache__"] + +> (@=? [False, True]) + ] + +namespaceFromPathOrDie :: FilePath -> FilePath -> IO Namespace +namespaceFromPathOrDie root path = + Namespace.fromPath root path |> \case + Just x -> pure x + Nothing -> + Log.fail ["bild", str path, "could not get namespace"] + >> Log.br + >> exitWith (ExitFailure 1) + nixStore :: String nixStore = "/nix/store/00000000000000000000000000000000-" @@ -367,21 +402,24 @@ instance ToNixFlag Builder where -- | We can't build everything yet... isBuildableNs :: Namespace -> Bool isBuildableNs = \case + (Namespace _ Namespace.Bash) -> False (Namespace _ Namespace.C) -> True (Namespace _ Namespace.Css) -> False (Namespace _ Namespace.Hs) -> True + (Namespace _ Namespace.Html) -> False (Namespace _ Namespace.Json) -> False (Namespace _ Namespace.Keys) -> False (Namespace _ Namespace.Lisp) -> True (Namespace _ Namespace.Md) -> False + (Namespace path Namespace.Nix) + | path `elem` nixTargets -> True + | otherwise -> False (Namespace _ Namespace.None) -> False (Namespace _ Namespace.Py) -> True (Namespace _ Namespace.Sh) -> False (Namespace _ Namespace.Scm) -> True (Namespace _ Namespace.Rs) -> True - (Namespace path Namespace.Nix) - | path `elem` nixTargets -> True - | otherwise -> False + (Namespace _ Namespace.Toml) -> True where nixTargets = [ ["Biz", "Pie"], @@ -461,11 +499,14 @@ analyze hmap ns = case Map.lookup ns hmap of /> Text.lines case ext of -- basically we don't support building these + Namespace.Bash -> pure Nothing Namespace.Css -> pure Nothing Namespace.Json -> pure Nothing Namespace.Keys -> pure Nothing Namespace.Md -> pure Nothing Namespace.None -> pure Nothing + Namespace.Html -> pure Nothing + Namespace.Toml -> pure Nothing Namespace.Py -> contentLines |> Meta.detectAll "#" diff --git a/Biz/Bild.nix b/Biz/Bild.nix index 1e4bcf8..9647983 100644 --- a/Biz/Bild.nix +++ b/Biz/Bild.nix @@ -59,18 +59,6 @@ in nixpkgs // { bild = rec { ; }; - # this is needed to do builds without calling out to nix, remove this when I - # switch to all-nix builds - bildRuntimeDeps = with nixpkgs; [ - pkg-config - # this is just to get access to ghc-pkg in bild - (haskell.ghcWith (_: [])) - - # lisp deps - guile - (lisp.sbclWith (p: with p; [asdf alexandria])) # just enough to build Example.lisp - ]; - # a standard nix build for bild, for bootstrapping. this should be the only # hand-written builder we need bild = nixpkgs.stdenv.mkDerivation { @@ -78,7 +66,16 @@ in nixpkgs // { bild = rec { src = ../.; nativeBuildInputs = [ haskell.ghcPackageSetBild ]; buildInputs = [ nixpkgs.makeWrapper ]; - propagatedBuildInputs = bildRuntimeDeps; + propagatedBuildInputs = with nixpkgs; [ + pkg-config + git + # this is just to get access to ghc-pkg in bild + (haskell.ghcWith (_: [])) + + # lisp deps, remove this when i implement nix builds for lisp + guile + (lisp.sbclWith (p: with p; [asdf alexandria])) # just enough to build Example.lisp + ]; strictDeps = true; buildPhase = '' mkdir -p $out/bin $out/lib/ghc-${haskell.ghcPackageSetFull.version} @@ -95,7 +92,7 @@ in nixpkgs // { bild = rec { ''; installPhase = '' wrapProgram $out/bin/bild \ - --prefix PATH : ${lib.makeBinPath [ haskell.ghcPackageSetBild ]} \ + --prefix PATH : ${lib.makeBinPath [ haskell.ghcPackageSetBild pkgs.git ]} \ --set GHC_PACKAGE_PATH \ $out/lib/ghc-${haskell.ghcPackageSetFull.version}/package.conf.d ''; @@ -108,7 +105,7 @@ in nixpkgs // { bild = rec { USER = "nixbld"; HOSTNAME = "nix-sandbox"; # this is the default sandbox path where bild will be working: - CODEROOT = "/build/biz"; + CODEROOT = "/build/omni"; # we need to remove the $src root because bild expects paths relative to the # working directory: TARGET = "." + lib.strings.removePrefix (toString src) (toString target); diff --git a/Biz/Cloud/post-receive b/Biz/Cloud/post-receive deleted file mode 100755 index 4a67043..0000000 --- a/Biz/Cloud/post-receive +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# -# creates an archive of a git repo on push -# -# unfortunately the nixos gitolite module does not copy the 'commonHooks' -# properly, so we have to manually deploy this like so: -# -# scp Biz/Cloud/post-receive \ -# root@simatime.com:/srv/git/.gitolite/hooks/common/post-receive -# -# One time only: -# -# ssh root@simatime.com "sudo -u git gitolite setup -ho" -# -# Also on first-time setup, might need to manually check the permissions are -# correct on $webroot/archive or wherever else. -# -set -euo pipefail -while read oldrev newrev refname -do - if [[ -e ./git-daemon-export-ok ]] - then - repo=$(basename $PWD | sed 's/.git//g') - branch=$(git rev-parse --symbolic --abbrev-ref $refname) - webroot="/srv/www/simatime.com/" - outdir="$webroot/archive/$repo/$branch" - mkdir -p $outdir - echo " making: https://simatime.com/archive/$repo/$branch/$newrev.tar.gz" - git archive "$branch" --prefix "$repo-$branch/" --format tar \ - | gzip > "$outdir/$newrev.tar.gz" - echo " making: https://simatime.com/archive/$repo/$branch/$newrev.sha256" - hash=$(nix-prefetch-url --unpack file://$outdir/$newrev.tar.gz 2>/dev/null) - echo "$hash" > "$outdir/$newrev.sha256" - echo " commit: $newrev" - echo " sha256: $hash" - echo " in biz: deps update $repo --branch $branch --rev $newrev --attribute sha256=$hash" - chmod -R 755 "$webroot/archive" - fi -done diff --git a/Biz/Cloud/post-receive.bash b/Biz/Cloud/post-receive.bash new file mode 100755 index 0000000..4a67043 --- /dev/null +++ b/Biz/Cloud/post-receive.bash @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# creates an archive of a git repo on push +# +# unfortunately the nixos gitolite module does not copy the 'commonHooks' +# properly, so we have to manually deploy this like so: +# +# scp Biz/Cloud/post-receive \ +# root@simatime.com:/srv/git/.gitolite/hooks/common/post-receive +# +# One time only: +# +# ssh root@simatime.com "sudo -u git gitolite setup -ho" +# +# Also on first-time setup, might need to manually check the permissions are +# correct on $webroot/archive or wherever else. +# +set -euo pipefail +while read oldrev newrev refname +do + if [[ -e ./git-daemon-export-ok ]] + then + repo=$(basename $PWD | sed 's/.git//g') + branch=$(git rev-parse --symbolic --abbrev-ref $refname) + webroot="/srv/www/simatime.com/" + outdir="$webroot/archive/$repo/$branch" + mkdir -p $outdir + echo " making: https://simatime.com/archive/$repo/$branch/$newrev.tar.gz" + git archive "$branch" --prefix "$repo-$branch/" --format tar \ + | gzip > "$outdir/$newrev.tar.gz" + echo " making: https://simatime.com/archive/$repo/$branch/$newrev.sha256" + hash=$(nix-prefetch-url --unpack file://$outdir/$newrev.tar.gz 2>/dev/null) + echo "$hash" > "$outdir/$newrev.sha256" + echo " commit: $newrev" + echo " sha256: $hash" + echo " in biz: deps update $repo --branch $branch --rev $newrev --attribute sha256=$hash" + chmod -R 755 "$webroot/archive" + fi +done diff --git a/Biz/Dev/Dns.nix b/Biz/Dev/Dns.nix index 4720b39..0490ead 100644 --- a/Biz/Dev/Dns.nix +++ b/Biz/Dev/Dns.nix @@ -18,14 +18,6 @@ extraOptions = '' dnssec-validation auto; ''; - zones = [ - { - master = true; - name = "home"; - slaves = []; - file = ./Home.zone; - } - ]; }; #networking.extraHosts = '' diff --git a/Biz/Dev/Home.zone b/Biz/Dev/Home.zone deleted file mode 100644 index 86d4919..0000000 --- a/Biz/Dev/Home.zone +++ /dev/null @@ -1,23 +0,0 @@ -;$TTL 3D -;@ IN SOA home. hostmaster ( -; 1 ; serial -; 8H ; refresh -; 2H ; retry -; 4W ; expire -; 1D) ; min ttl -; IN NS ns.home. -;home. IN A 192.168.0.196 -;router IN A 192.168.0.196 -; -$TTL 1D -@ IN SOA ns.home. hostmaster ( - 3 ; Serial - 604800 ; Refresh - 86400 ; Retry - 2419200 ; Expire - 604800 ) ; Minimum -@ IN NS ns. ; Name Server for the domain -@ IN A 192.168.0.196 ; -example.com. IN A 192.168.0.1 ; test -router IN A 192.168.0.1 ; IP address for 'router' -lithium IN A 192.168.0.196 ; my dev server diff --git a/Biz/Dragons/env b/Biz/Dragons/env deleted file mode 100644 index 86a2f69..0000000 --- a/Biz/Dragons/env +++ /dev/null @@ -1,9 +0,0 @@ -# This is an example env file for Dragons.dev. Copy this to /run/dragons/env and -# fill in the values. -# -# These can be retrieved from https://github.com/settings/applications/1428824 -GITHUB_CLIENT_SECRET= -GITHUB_CLIENT_ID= -# -# This is just a UUID, can be grabbed from /proc/sys/kernel/random/uuid -GITHUB_CLIENT_STATE= diff --git a/Biz/Dragons/env.bash b/Biz/Dragons/env.bash new file mode 100644 index 0000000..86a2f69 --- /dev/null +++ b/Biz/Dragons/env.bash @@ -0,0 +1,9 @@ +# This is an example env file for Dragons.dev. Copy this to /run/dragons/env and +# fill in the values. +# +# These can be retrieved from https://github.com/settings/applications/1428824 +GITHUB_CLIENT_SECRET= +GITHUB_CLIENT_ID= +# +# This is just a UUID, can be grabbed from /proc/sys/kernel/random/uuid +GITHUB_CLIENT_STATE= diff --git a/Biz/Ide/ftags b/Biz/Ide/ftags deleted file mode 100755 index 02d78c5..0000000 --- a/Biz/Ide/ftags +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# search tags with fzf -# - set -euo pipefail - tags=${CODEROOT:?}/tags - tag_search=$( - awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' "$tags" \ - | cut -c1-80 \ - | fzf-tmux \ - --nth=1,2 \ - --preview-window=right \ - --bind="pgdn:preview-page-down" \ - --bind="pgup:preview-page-up" \ - --preview "rg --pretty --context 2 --word-regexp -F {+2}" - ) - ${EDITOR:-vim} \ - "$(cut -f3 <<< "$tag_search")" \ - -c "set nocst" \ - -c "silent tag $(cut -f2 <<< "$tag_search")" -## diff --git a/Biz/Ide/ftags.bash b/Biz/Ide/ftags.bash new file mode 100755 index 0000000..02d78c5 --- /dev/null +++ b/Biz/Ide/ftags.bash @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# search tags with fzf +# + set -euo pipefail + tags=${CODEROOT:?}/tags + tag_search=$( + awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' "$tags" \ + | cut -c1-80 \ + | fzf-tmux \ + --nth=1,2 \ + --preview-window=right \ + --bind="pgdn:preview-page-down" \ + --bind="pgup:preview-page-up" \ + --preview "rg --pretty --context 2 --word-regexp -F {+2}" + ) + ${EDITOR:-vim} \ + "$(cut -f3 <<< "$tag_search")" \ + -c "set nocst" \ + -c "silent tag $(cut -f2 <<< "$tag_search")" +## diff --git a/Biz/Ide/hoog b/Biz/Ide/hoog deleted file mode 100755 index 976f0d4..0000000 --- a/Biz/Ide/hoog +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# -# search hoogle with fzf -# - set -euo pipefail - HOOG="hoogle search --count=200" - export FZF_DEFAULT_COMMAND="$HOOG $*" - result=$(fzf-tmux \ - --preview-window=down \ - --preview "hoogle search --link --info {+2}" \ - --bind "change:reload:$HOOG {q} || true" \ - --ansi \ - | cut -d' ' -f 1,2 \ - | sed -e 's/ /./g' - ) - hoogle search --info "$result" -## diff --git a/Biz/Ide/hoog.bash b/Biz/Ide/hoog.bash new file mode 100755 index 0000000..976f0d4 --- /dev/null +++ b/Biz/Ide/hoog.bash @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# +# search hoogle with fzf +# + set -euo pipefail + HOOG="hoogle search --count=200" + export FZF_DEFAULT_COMMAND="$HOOG $*" + result=$(fzf-tmux \ + --preview-window=down \ + --preview "hoogle search --link --info {+2}" \ + --bind "change:reload:$HOOG {q} || true" \ + --ansi \ + | cut -d' ' -f 1,2 \ + | sed -e 's/ /./g' + ) + hoogle search --info "$result" +## diff --git a/Biz/Ide/hooks/commit-msg b/Biz/Ide/hooks/commit-msg deleted file mode 100755 index 64e400d..0000000 --- a/Biz/Ide/hooks/commit-msg +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/commit-msg.bash b/Biz/Ide/hooks/commit-msg.bash new file mode 100755 index 0000000..64e400d --- /dev/null +++ b/Biz/Ide/hooks/commit-msg.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/post-checkout b/Biz/Ide/hooks/post-checkout deleted file mode 100755 index 73488b0..0000000 --- a/Biz/Ide/hooks/post-checkout +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -e -mktags=${CODEROOT:?}/Biz/Ide/mktags -old=$1 -new=$2 -# filter out only the changed haskell files -changed=($(git diff --diff-filter=d --name-only $old $new -- '*.hs')) -if [[ ! -r tags ]] || [[ ! -r TAGS ]] -then - $mktags "$CODEROOT"/**/* -elif [[ ${#changed[@]} -gt 0 ]] -then - $mktags $changed -fi -direnv reload diff --git a/Biz/Ide/hooks/post-checkout.bash b/Biz/Ide/hooks/post-checkout.bash new file mode 100755 index 0000000..73488b0 --- /dev/null +++ b/Biz/Ide/hooks/post-checkout.bash @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -e +mktags=${CODEROOT:?}/Biz/Ide/mktags +old=$1 +new=$2 +# filter out only the changed haskell files +changed=($(git diff --diff-filter=d --name-only $old $new -- '*.hs')) +if [[ ! -r tags ]] || [[ ! -r TAGS ]] +then + $mktags "$CODEROOT"/**/* +elif [[ ${#changed[@]} -gt 0 ]] +then + $mktags $changed +fi +direnv reload diff --git a/Biz/Ide/hooks/post-merge b/Biz/Ide/hooks/post-merge deleted file mode 100755 index c21211f..0000000 --- a/Biz/Ide/hooks/post-merge +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD diff --git a/Biz/Ide/hooks/post-merge.bash b/Biz/Ide/hooks/post-merge.bash new file mode 100755 index 0000000..c21211f --- /dev/null +++ b/Biz/Ide/hooks/post-merge.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD diff --git a/Biz/Ide/hooks/pre-commit b/Biz/Ide/hooks/pre-commit deleted file mode 100755 index 2b4575c..0000000 --- a/Biz/Ide/hooks/pre-commit +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# - prevent frozen code from being checked in -# - guard against lint errors -## - set -e - changed=($(git diff-index --cached --name-only HEAD)) - for ns in ${changed[@]} - do - version=$(${CODEROOT:?}/Biz/Ide/version $ns) - if (( $version == -1 )); then - echo "info: version: $ns: deleted" - elif (( $version < 1 )); then - echo "fail: version: $ns: $version" - exit 1 - else - echo "info: version: $ns: $version" - fi - done - lint "${changed[@]}" -## diff --git a/Biz/Ide/hooks/pre-commit.bash b/Biz/Ide/hooks/pre-commit.bash new file mode 100755 index 0000000..2b4575c --- /dev/null +++ b/Biz/Ide/hooks/pre-commit.bash @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# - prevent frozen code from being checked in +# - guard against lint errors +## + set -e + changed=($(git diff-index --cached --name-only HEAD)) + for ns in ${changed[@]} + do + version=$(${CODEROOT:?}/Biz/Ide/version $ns) + if (( $version == -1 )); then + echo "info: version: $ns: deleted" + elif (( $version < 1 )); then + echo "fail: version: $ns: $version" + exit 1 + else + echo "info: version: $ns: $version" + fi + done + lint "${changed[@]}" +## diff --git a/Biz/Ide/hooks/pre-push b/Biz/Ide/hooks/pre-push deleted file mode 100755 index 0c313cb..0000000 --- a/Biz/Ide/hooks/pre-push +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash -# -# a simple ci that saves its results in a git note, formatted according to -# RFC-2822, more or less. -# -## - set -uo pipefail - [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; } -## - at=$(date -R) - user=$(git config --get user.name) - mail=$(git config --get user.email) -## - while read local_ref local_sha remote_ref remote_sha - do - if [[ $local_ref =~ notes ]]; then - exit 0 - fi - commit=$(git notes --ref=ci show $local_ref || true) - if [[ -n "$commit" ]] - then - lint_ok=$() - if grep -q "Lint-is: good" <<< $commit - then - exit 0 - fi - if grep -q "Test-is: good" <<< $commit - then - exit 0 - fi - fi - ## - if lint "${CODEROOT:?}"/**/* - then - lint_result="good" - else - lint_result="fail" - exit 1 - fi - ## - if bild --test "${CODEROOT:?}"/**/* - then - test_result="good" - else - test_result="fail" - exit 1 - fi - ## - read -r -d '' note < -Test-at: $at -EOF - ## - git notes --ref=ci append -m "$note" - done -## diff --git a/Biz/Ide/hooks/pre-push.bash b/Biz/Ide/hooks/pre-push.bash new file mode 100755 index 0000000..0c313cb --- /dev/null +++ b/Biz/Ide/hooks/pre-push.bash @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# a simple ci that saves its results in a git note, formatted according to +# RFC-2822, more or less. +# +## + set -uo pipefail + [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; } +## + at=$(date -R) + user=$(git config --get user.name) + mail=$(git config --get user.email) +## + while read local_ref local_sha remote_ref remote_sha + do + if [[ $local_ref =~ notes ]]; then + exit 0 + fi + commit=$(git notes --ref=ci show $local_ref || true) + if [[ -n "$commit" ]] + then + lint_ok=$() + if grep -q "Lint-is: good" <<< $commit + then + exit 0 + fi + if grep -q "Test-is: good" <<< $commit + then + exit 0 + fi + fi + ## + if lint "${CODEROOT:?}"/**/* + then + lint_result="good" + else + lint_result="fail" + exit 1 + fi + ## + if bild --test "${CODEROOT:?}"/**/* + then + test_result="good" + else + test_result="fail" + exit 1 + fi + ## + read -r -d '' note < +Test-at: $at +EOF + ## + git notes --ref=ci append -m "$note" + done +## diff --git a/Biz/Ide/mktags b/Biz/Ide/mktags deleted file mode 100755 index c83f319..0000000 --- a/Biz/Ide/mktags +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# -# script to generate tags automatically if there are none. -# - set -euo pipefail - files=$@ - vimtags=${CODEROOT:?}/tags - emacstags=${CODEROOT:?}/TAGS -# - if [[ ! -r $emacstags ]]; then - echo Generating emacs TAGS from scratch... - fast-tags -e -R ${CODEROOT:?} - ctags -e \ - --append=yes \ - --recurse=yes \ - --exclude="$CODEROOT/_/*" \ - ${CODEROOT:?} - else - fast-tags -e $files - ctags -e \ - --append=yes \ - --exclude="_/*" \ - $files - fi -# - if [[ ! -r $vimtags ]]; then - echo Generating vim tags from scratch... - fast-tags "${flags[@]}" -R ${CODEROOT:?} - ctags "${flags[@]}" \ - --append=yes \ - --recurse=yes \ - --exclude="${CODEROOT:?}/_/*" \ - ${CODEROOT:?} - else - fast-tags "${flags[@]}" $files - ctags "${flags[@]}" \ - --append=yes \ - --exclude="_/*" \ - $files - fi -## diff --git a/Biz/Ide/mktags.bash b/Biz/Ide/mktags.bash new file mode 100755 index 0000000..c83f319 --- /dev/null +++ b/Biz/Ide/mktags.bash @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# script to generate tags automatically if there are none. +# + set -euo pipefail + files=$@ + vimtags=${CODEROOT:?}/tags + emacstags=${CODEROOT:?}/TAGS +# + if [[ ! -r $emacstags ]]; then + echo Generating emacs TAGS from scratch... + fast-tags -e -R ${CODEROOT:?} + ctags -e \ + --append=yes \ + --recurse=yes \ + --exclude="$CODEROOT/_/*" \ + ${CODEROOT:?} + else + fast-tags -e $files + ctags -e \ + --append=yes \ + --exclude="_/*" \ + $files + fi +# + if [[ ! -r $vimtags ]]; then + echo Generating vim tags from scratch... + fast-tags "${flags[@]}" -R ${CODEROOT:?} + ctags "${flags[@]}" \ + --append=yes \ + --recurse=yes \ + --exclude="${CODEROOT:?}/_/*" \ + ${CODEROOT:?} + else + fast-tags "${flags[@]}" $files + ctags "${flags[@]}" \ + --append=yes \ + --exclude="_/*" \ + $files + fi +## diff --git a/Biz/Ide/ns b/Biz/Ide/ns deleted file mode 100755 index e988bfe..0000000 --- a/Biz/Ide/ns +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -fd --exclude=_ -t f . ${CODEROOT:?} | sed "s,${CODEROOT:?}/*,,g" \ - | fzf \ - --bind "alt-space:execute(bild {} && read -p [fin])" \ - --bind "alt-enter:execute(vim {})" \ - --bind "alt-l:execute(lint {} && read -p [fin])" \ - --bind "enter:execute(repl {})" \ - --bind "ctrl-space:execute(ship {} && read -p [fin])" \ - --bind "alt-t:execute(bild {} && run {} test && read -p [fin])" \ - --bind "ctrl-/:change-preview-window(90%|hidden|)" \ - --bind "alt-0:change-preview(bat -p --color=always {})" \ - --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" \ - --bind "alt-2:change-preview(git log --color=always {})" \ - --bind "alt-3:change-preview(git log --color=always -p {})" \ - --bind "alt-4:change-preview(git blame -c --date=short {})" \ - --bind "alt-5:change-preview(git log --pretty=short {} | git shortlog -nse)" \ - --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog)" \ - --bind "backward-eof:abort" \ - --bind "pgup:preview-page-up" \ - --bind "pgdn:preview-page-down" \ - --header="repl: enter | edit: alt-enter | bild: alt-space | test: alt-t | lint: alt-l | ship: ctrl-space" \ - --header-first \ - --preview-window="border-sharp,88" \ - --preview "bat -p --color=always {}" -### diff --git a/Biz/Ide/ns.bash b/Biz/Ide/ns.bash new file mode 100755 index 0000000..e988bfe --- /dev/null +++ b/Biz/Ide/ns.bash @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +fd --exclude=_ -t f . ${CODEROOT:?} | sed "s,${CODEROOT:?}/*,,g" \ + | fzf \ + --bind "alt-space:execute(bild {} && read -p [fin])" \ + --bind "alt-enter:execute(vim {})" \ + --bind "alt-l:execute(lint {} && read -p [fin])" \ + --bind "enter:execute(repl {})" \ + --bind "ctrl-space:execute(ship {} && read -p [fin])" \ + --bind "alt-t:execute(bild {} && run {} test && read -p [fin])" \ + --bind "ctrl-/:change-preview-window(90%|hidden|)" \ + --bind "alt-0:change-preview(bat -p --color=always {})" \ + --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" \ + --bind "alt-2:change-preview(git log --color=always {})" \ + --bind "alt-3:change-preview(git log --color=always -p {})" \ + --bind "alt-4:change-preview(git blame -c --date=short {})" \ + --bind "alt-5:change-preview(git log --pretty=short {} | git shortlog -nse)" \ + --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog)" \ + --bind "backward-eof:abort" \ + --bind "pgup:preview-page-up" \ + --bind "pgdn:preview-page-down" \ + --header="repl: enter | edit: alt-enter | bild: alt-space | test: alt-t | lint: alt-l | ship: ctrl-space" \ + --header-first \ + --preview-window="border-sharp,88" \ + --preview "bat -p --color=always {}" +### diff --git a/Biz/Ide/push b/Biz/Ide/push deleted file mode 100755 index 2238e06..0000000 --- a/Biz/Ide/push +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Eventually convert to haskell, see: -# - https://github.com/awakesecurity/nix-deploy/blob/master/src/Main.hs -# - http://www.haskellforall.com/2018/08/nixos-in-production.html -prefix=$(echo $PWD | sed -e "s|^${CODEROOT:?}/*||g") -if [[ "$prefix" == "" ]] -then - target="$1" -else - target="$prefix.$1" -fi -what=$(realpath "${CODEROOT:?}/_/nix/$target") -# hack: get the domain from the activation script. there does not seem -# to be a way to get it from nix-instantiate -where=$(rg -r '$2' -e '(domainname ")(.*)(")' "$what/activate") -nix copy --to ssh://root@$where $what -ssh root@$where $what/bin/switch-to-configuration switch -ssh root@$where nix-env --profile /nix/var/nix/profiles/system --set $what -printf "${GRN}good: push: $target${NC}\n" diff --git a/Biz/Ide/push.bash b/Biz/Ide/push.bash new file mode 100755 index 0000000..2238e06 --- /dev/null +++ b/Biz/Ide/push.bash @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Eventually convert to haskell, see: +# - https://github.com/awakesecurity/nix-deploy/blob/master/src/Main.hs +# - http://www.haskellforall.com/2018/08/nixos-in-production.html +prefix=$(echo $PWD | sed -e "s|^${CODEROOT:?}/*||g") +if [[ "$prefix" == "" ]] +then + target="$1" +else + target="$prefix.$1" +fi +what=$(realpath "${CODEROOT:?}/_/nix/$target") +# hack: get the domain from the activation script. there does not seem +# to be a way to get it from nix-instantiate +where=$(rg -r '$2' -e '(domainname ")(.*)(")' "$what/activate") +nix copy --to ssh://root@$where $what +ssh root@$where $what/bin/switch-to-configuration switch +ssh root@$where nix-env --profile /nix/var/nix/profiles/system --set $what +printf "${GRN}good: push: $target${NC}\n" diff --git a/Biz/Ide/repl b/Biz/Ide/repl deleted file mode 100755 index b10f0f0..0000000 --- a/Biz/Ide/repl +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env bash -### -### a simple complement to bild which only deals with launching repls -### -### > repl [opts] -### -### Starts a repl/shell for one or more targets. (Currently, all targets must -### have the same extension for this to work.) Repls started with this script -### should bind to `localhost:$PORT`. -### -### Options: -### --bash start bash instead of the target language repl -help() { - sed -rn 's/^### ?//;T;p' "$0" -} -if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then - help - exit 1 -fi -## - set -e - CMD= - if [[ "$1" == "--bash" ]]; then - CMD="bash" - shift - fi - targets=${@:?} - json=$(bild --json ${targets[@]}) - langdeps=$(jq --raw-output '.[].langdeps | join(" ")' <<< $json) - sysdeps=$(jq --raw-output '.[].sysdeps | join(" ")' <<< $json) - rundeps=$(jq --raw-output '.[].rundeps | join(" ")' <<< $json) - exts=$(jq --raw-output '.[].namespace.ext' <<< $json | sort | uniq) - packageSet=$(jq --raw-output '.[].packageSet' <<< $json) - module=$(jq --raw-output '.[].mainModule' <<< $json) - BILD="(import ${CODEROOT:?}/Biz/Bild.nix {})" - for lib in ${sysdeps[@]} - do - flags+=(--packages "$BILD.pkgs.${lib}") - flags+=(--packages "$BILD.pkgs.pkg-config") - done - for lib in ${rundeps[@]} - do - flags+=(--packages "$BILD.pkgs.${lib}") - done - case $exts in - C) - flags+=(--packages "$BILD.pkgs.gcc") - command="bash" - ;; - Hs) - if [ -z ${var+PORT} ]; then - echo "warn: repl: ghci does not support binding to a port" - fi - flags+=(--packages "$BILD.bild.haskell.ghcWith (h: with h; [$langdeps])") - command=${CMD:-"ghci -i${CODEROOT:?} -ghci-script ${CODEROOT:?}/.ghci ${targets[@]}"} - ;; - Scm) - for lib in ${langdeps[@]}; do - flags+=(--packages "$BILD.guile-${lib}") - done - flags+=(--packages "$BILD.guile") - command=${CMD:-"guile -L ${CODEROOT:?} -C ${CODEROOT:?}/_/int --r7rs --listen=${PORT:-37146}"} - ;; - Lisp) - flags+=(--packages "$BILD.bild.$packageSet (p: with p; [asdf swank $langdeps])") - command=${CMD:-"sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"} - ;; - Rs) - flags+=(--packages "$BILD.nixpkgs.rustc") - command=bash - ;; - Py) - langdeps="$langdeps mypy" - flags+=(--packages ruff) - flags+=(--packages "$BILD.bild.python.pythonWith (p: with p; [$langdeps])") - PYTHONPATH=$CODEROOT:$PYTHONPATH - pycommand="python -i $CODEROOT/Biz/Repl.py $module ${targets[@]}" - command=${CMD:-"$pycommand"} - ;; - *) - echo "unsupported targets: ${targets[@]}" - exit 1 - ;; - esac -## - nix-shell "${flags[@]}" --command "$command" -## diff --git a/Biz/Ide/repl.bash b/Biz/Ide/repl.bash new file mode 100755 index 0000000..b10f0f0 --- /dev/null +++ b/Biz/Ide/repl.bash @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +### +### a simple complement to bild which only deals with launching repls +### +### > repl [opts] +### +### Starts a repl/shell for one or more targets. (Currently, all targets must +### have the same extension for this to work.) Repls started with this script +### should bind to `localhost:$PORT`. +### +### Options: +### --bash start bash instead of the target language repl +help() { + sed -rn 's/^### ?//;T;p' "$0" +} +if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then + help + exit 1 +fi +## + set -e + CMD= + if [[ "$1" == "--bash" ]]; then + CMD="bash" + shift + fi + targets=${@:?} + json=$(bild --json ${targets[@]}) + langdeps=$(jq --raw-output '.[].langdeps | join(" ")' <<< $json) + sysdeps=$(jq --raw-output '.[].sysdeps | join(" ")' <<< $json) + rundeps=$(jq --raw-output '.[].rundeps | join(" ")' <<< $json) + exts=$(jq --raw-output '.[].namespace.ext' <<< $json | sort | uniq) + packageSet=$(jq --raw-output '.[].packageSet' <<< $json) + module=$(jq --raw-output '.[].mainModule' <<< $json) + BILD="(import ${CODEROOT:?}/Biz/Bild.nix {})" + for lib in ${sysdeps[@]} + do + flags+=(--packages "$BILD.pkgs.${lib}") + flags+=(--packages "$BILD.pkgs.pkg-config") + done + for lib in ${rundeps[@]} + do + flags+=(--packages "$BILD.pkgs.${lib}") + done + case $exts in + C) + flags+=(--packages "$BILD.pkgs.gcc") + command="bash" + ;; + Hs) + if [ -z ${var+PORT} ]; then + echo "warn: repl: ghci does not support binding to a port" + fi + flags+=(--packages "$BILD.bild.haskell.ghcWith (h: with h; [$langdeps])") + command=${CMD:-"ghci -i${CODEROOT:?} -ghci-script ${CODEROOT:?}/.ghci ${targets[@]}"} + ;; + Scm) + for lib in ${langdeps[@]}; do + flags+=(--packages "$BILD.guile-${lib}") + done + flags+=(--packages "$BILD.guile") + command=${CMD:-"guile -L ${CODEROOT:?} -C ${CODEROOT:?}/_/int --r7rs --listen=${PORT:-37146}"} + ;; + Lisp) + flags+=(--packages "$BILD.bild.$packageSet (p: with p; [asdf swank $langdeps])") + command=${CMD:-"sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"} + ;; + Rs) + flags+=(--packages "$BILD.nixpkgs.rustc") + command=bash + ;; + Py) + langdeps="$langdeps mypy" + flags+=(--packages ruff) + flags+=(--packages "$BILD.bild.python.pythonWith (p: with p; [$langdeps])") + PYTHONPATH=$CODEROOT:$PYTHONPATH + pycommand="python -i $CODEROOT/Biz/Repl.py $module ${targets[@]}" + command=${CMD:-"$pycommand"} + ;; + *) + echo "unsupported targets: ${targets[@]}" + exit 1 + ;; + esac +## + nix-shell "${flags[@]}" --command "$command" +## diff --git a/Biz/Ide/run b/Biz/Ide/run deleted file mode 100755 index f7b9d36..0000000 --- a/Biz/Ide/run +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -set -eu -target=$1 -shift -out=$(rg --only-matching ": out (\w*)" -r '$1' $target) -exec "${CODEROOT:?}/_/bin/$out" "$@" diff --git a/Biz/Ide/run.bash b/Biz/Ide/run.bash new file mode 100755 index 0000000..f7b9d36 --- /dev/null +++ b/Biz/Ide/run.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eu +target=$1 +shift +out=$(rg --only-matching ": out (\w*)" -r '$1' $target) +exec "${CODEROOT:?}/_/bin/$out" "$@" diff --git a/Biz/Ide/ship b/Biz/Ide/ship deleted file mode 100755 index 33197c8..0000000 --- a/Biz/Ide/ship +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# -# ship ... -# -# lint, bild, test, and push one or more targets. if no targets are supplied, -# ship everything we know how to ship -## - set -eu - stuff=(${@}) - if [[ ${#stuff[@]} -eq 0 ]] - then - stuff=$(fd -t l . "$CODEROOT/_" \ - | fzf --multi \ - | sed "s,$CODEROOT/_/nix/,,g" - ) - fi - lint ${stuff[@]} - bild --test ${stuff[@]} - for thing in ${stuff[@]} - do - push $thing - done -## diff --git a/Biz/Ide/ship.bash b/Biz/Ide/ship.bash new file mode 100755 index 0000000..33197c8 --- /dev/null +++ b/Biz/Ide/ship.bash @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# ship ... +# +# lint, bild, test, and push one or more targets. if no targets are supplied, +# ship everything we know how to ship +## + set -eu + stuff=(${@}) + if [[ ${#stuff[@]} -eq 0 ]] + then + stuff=$(fd -t l . "$CODEROOT/_" \ + | fzf --multi \ + | sed "s,$CODEROOT/_/nix/,,g" + ) + fi + lint ${stuff[@]} + bild --test ${stuff[@]} + for thing in ${stuff[@]} + do + push $thing + done +## diff --git a/Biz/Ide/tidy b/Biz/Ide/tidy deleted file mode 100755 index ec666ba..0000000 --- a/Biz/Ide/tidy +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -rm -f $CODEROOT/_/bin/* diff --git a/Biz/Ide/tidy.bash b/Biz/Ide/tidy.bash new file mode 100755 index 0000000..ec666ba --- /dev/null +++ b/Biz/Ide/tidy.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +rm -f $CODEROOT/_/bin/* diff --git a/Biz/Ide/tips b/Biz/Ide/tips deleted file mode 100755 index 21808eb..0000000 --- a/Biz/Ide/tips +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -echo "" -echo "bizdev" | figlet | lolcat -echo "" -echo " bild compile code" -echo " repl start a repl" -echo " deps manage dependencies with niv" -echo " tips show this message" -echo " lint auto-lint all changed files" -echo " push send a namespace to the cloud" -echo " ship lint, bild, and push one (or all) namespace(s)" -echo " tidy cleanup common working files" -echo "" diff --git a/Biz/Ide/tips.bash b/Biz/Ide/tips.bash new file mode 100755 index 0000000..ba458ac --- /dev/null +++ b/Biz/Ide/tips.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +echo "" +echo "bizdev" | figlet | lolcat +echo "" +echo " bild.bash compile code" +echo " repl.bash start a repl" +echo " deps.bash manage dependencies with niv" +echo " tips.bash show this message" +echo " lint.bash auto-lint all changed files" +echo " push.bash send a namespace to the cloud" +echo " ship.bash lint, bild, and push one (or all) namespace(s)" +echo " tidy.bash cleanup common working files" +echo "" diff --git a/Biz/Ide/version b/Biz/Ide/version deleted file mode 100755 index 5b017d9..0000000 --- a/Biz/Ide/version +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# -# simple implementation of kelvin versioning -## - ns=$1 - if [[ -e "$1" ]]; then - commits=$(git log --oneline --follow $ns | wc -l) - # gold melts at 1337 kelvin, so we start with this - # bc we are forging gold here - version=$(bc -l <<< "1337 - $commits") - echo $version - else - echo -1 # signal that file doesn't exist - fi -## diff --git a/Biz/Ide/version.bash b/Biz/Ide/version.bash new file mode 100755 index 0000000..5b017d9 --- /dev/null +++ b/Biz/Ide/version.bash @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# +# simple implementation of kelvin versioning +## + ns=$1 + if [[ -e "$1" ]]; then + commits=$(git log --oneline --follow $ns | wc -l) + # gold melts at 1337 kelvin, so we start with this + # bc we are forging gold here + version=$(bc -l <<< "1337 - $commits") + echo $version + else + echo -1 # signal that file doesn't exist + fi +## diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs index 48f6277..bd283a6 100644 --- a/Biz/Namespace.hs +++ b/Biz/Namespace.hs @@ -31,9 +31,11 @@ import qualified Data.Text as Text import qualified Text.Regex.Applicative as Regex data Ext - = C + = Bash + | C | Css | Hs + | Html | Json | Keys | Lisp @@ -44,6 +46,7 @@ data Ext | Rs | Scm | Sh + | Toml deriving (Eq, Show, Generic, Aeson.ToJSON, Ord) data Namespace = Namespace {path :: [String], ext :: Ext} @@ -65,9 +68,11 @@ toPath (Namespace parts ext) = toExt :: Ext -> String toExt = ("." <>) <. \case + Bash -> "bash" C -> "c" Css -> "css" Hs -> "hs" + Html -> "html" Json -> "json" Keys -> "pub" Lisp -> "lisp" @@ -78,6 +83,7 @@ toExt = Rs -> "rs" Scm -> "scm" Sh -> "sh" + Toml -> "toml" fromHaskellContent :: String -> Maybe Namespace fromHaskellContent c = case Regex.findFirstInfix haskellModule c of @@ -95,6 +101,7 @@ toModule (Namespace parts Py) = joinWith "." parts toModule (Namespace parts Scm) = "(" ++ joinWith " " parts ++ ")" toModule (Namespace parts Rs) = joinWith "::" parts toModule (Namespace parts C) = joinWith "/" parts <> ".c" +toModule (Namespace parts Nix) = joinWith "/" parts <> ".nix" toModule (Namespace {..}) = panic <| "toModule not implemented for " <> show ext toHaskellModule :: Namespace -> String @@ -115,7 +122,10 @@ dot = Regex.some <| Regex.sym '.' name :: Regex.RE Char String name = Regex.many (Regex.psym Char.isUpper) - <> Regex.many (Regex.psym (\c -> Char.isAlphaNum c || (c == '_'))) + <> ( Regex.many + <| Regex.psym + <| \c -> Char.isAlphaNum c || c == '_' || c == '-' + ) rePath :: Regex.RE Char [String] rePath = Regex.many (name <* Regex.string "/" <|> name) @@ -125,6 +135,7 @@ reExt = C <$ Regex.string "c" <|> Css <$ Regex.string "css" <|> Hs <$ Regex.string "hs" + <|> Html <$ Regex.string "html" <|> Json <$ Regex.string "json" <|> Keys <$ Regex.string "pub" <|> Lisp <$ Regex.string "lisp" @@ -134,6 +145,8 @@ reExt = <|> Rs <$ Regex.string "rs" <|> Scm <$ Regex.string "scm" <|> Sh <$ Regex.string "sh" + <|> Bash <$ Regex.string "bash" + <|> Toml <$ Regex.string "toml" -- | The cab dir is for temporary files and build outputs, not for source -- inputs. -- cgit v1.2.3