From 2db87333d702d27ee45d8089ad4ad189bcb50cf2 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 11 Jan 2021 17:42:13 -0800 Subject: [PATCH] bin: switch scripts to "stack ghc" and "env -S" (#1453) Using stack's script command meant that the scripts needed to be compatible, and regularly tested, with a hledger release in stackage, rather than the latest hledger source. This created hassles for maintainers, contributors and sometimes for users. To simplify things overall, we now require script users to check out the hledger source tree and run the scripts (or, bin/compile.sh) from there once so they compile themselves. Some notes on alternative setups are included (in one of the scripts, and referenced by the others). This ensures that users and our CI tests are building scripts the same way. Current stack does not allow a stack options line to be used with the "stack ghc" command, unfortunately, so instead we are using env's -S flag, which hopefully has sufficiently wide support by now, and putting all arguments in the shebang line. This method will probably require complete explicit --package options, unlike "stack script", so more testing and tweaking is expected. Probably we're going to end up with some long shebang lines. This isn't pretty but seems like a possible way to keep things manageable. --- bin/hledger-balance-as-budget.hs | 4 ++-- bin/hledger-check-fancyassertions.hs | 23 +++++++++++++++++++++-- bin/hledger-check-tagfiles.hs | 4 ++-- bin/hledger-combine-balances.hs | 4 ++-- bin/hledger-print-location.hs | 8 +++++--- bin/hledger-smooth.hs | 6 ++++-- bin/hledger-swap-dates.hs | 4 ++-- bin/scripts.test | 14 +++++++------- 8 files changed, 45 insertions(+), 22 deletions(-) diff --git a/bin/hledger-balance-as-budget.hs b/bin/hledger-balance-as-budget.hs index cbd3699f3..77d49a138 100755 --- a/bin/hledger-balance-as-budget.hs +++ b/bin/hledger-balance-as-budget.hs @@ -1,5 +1,5 @@ -#!/usr/bin/env stack --- stack script --compile --resolver lts-16.25 +#!/usr/bin/env -S stack ghc --verbosity info --package hledger -- -O0 +-- See hledger-check-fancyassertions.hs -- {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} diff --git a/bin/hledger-check-fancyassertions.hs b/bin/hledger-check-fancyassertions.hs index 1e8ad995d..579e2ba5a 100755 --- a/bin/hledger-check-fancyassertions.hs +++ b/bin/hledger-check-fancyassertions.hs @@ -1,5 +1,24 @@ -#!/usr/bin/env stack --- stack script --compile --resolver lts-16.25 +#!/usr/bin/env -S stack ghc --verbosity info --package hledger-lib -- -O0 +-- Run this script once from inside the hledger source tree; it will +-- compile itself using the corresponding source version of hledger, +-- which is the version it is tested with. You can run the compiled +-- version from anywhere. It is compiled unoptimised, which takes less +-- time and probably won't be noticeable otherwise; if you care, you +-- can remove the "-O0" above. +-- +-- To run it interpreted, eg while tweaking it: replace "ghc" above +-- with "runghc", and run from inside the hledger source tree. +-- +-- To make it a standalone script that runs from anywhere and +-- recompiles itself when changed: replace "ghc" above with +-- "script --compile --resolver lts-16" (eg). +-- However this uses the hledger version from that stackage resolver, +-- so in this case you should check out the corresponding release-tagged +-- version of this script for compatibility (eg: git checkout 1.18.1). +-- +-- env -S and a multi-argument shebang line is used, rather than a stack +-- options line, because current stack won't run the ghc command that way. +-- Hopefully your env supports -S. {- ``` diff --git a/bin/hledger-check-tagfiles.hs b/bin/hledger-check-tagfiles.hs index a015aa1ca..d9051e00d 100755 --- a/bin/hledger-check-tagfiles.hs +++ b/bin/hledger-check-tagfiles.hs @@ -1,5 +1,5 @@ -#!/usr/bin/env stack --- stack script --compile --resolver lts-16.25 +#!/usr/bin/env -S stack ghc --verbosity info --package hledger -- -O0 +-- See hledger-check-fancyassertions.hs {- hledger-check-tagfiles stack script. diff --git a/bin/hledger-combine-balances.hs b/bin/hledger-combine-balances.hs index 084a26bc9..9255f2d67 100755 --- a/bin/hledger-combine-balances.hs +++ b/bin/hledger-combine-balances.hs @@ -1,5 +1,5 @@ -#!/usr/bin/env stack --- stack script --compile --resolver lts-16.25 +#!/usr/bin/env -S stack ghc --verbosity info --package hledger -- -O0 +-- See hledger-check-fancyassertions.hs {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} diff --git a/bin/hledger-print-location.hs b/bin/hledger-print-location.hs index f7a5437e9..44d8e5de3 100755 --- a/bin/hledger-print-location.hs +++ b/bin/hledger-print-location.hs @@ -1,6 +1,8 @@ -#!/usr/bin/env stack -{- stack script --compile --resolver lts-16.25 --} +#!/usr/bin/env -S stack ghc --verbosity info --package hledger -- -O0 +-- See hledger-check-fancyassertions.hs + +--package string-qq + {- Quick script that adds file/line number tags to print output. cf https://www.reddit.com/r/plaintextaccounting/comments/ddzn8o/finding_corresponding_journal_files_from_hledger/ diff --git a/bin/hledger-smooth.hs b/bin/hledger-smooth.hs index 40d69b200..10449a5d3 100755 --- a/bin/hledger-smooth.hs +++ b/bin/hledger-smooth.hs @@ -1,5 +1,7 @@ -#!/usr/bin/env stack --- stack script --compile --resolver lts-16.25 +#!/usr/bin/env -S stack ghc --verbosity info --package hledger -- -O0 +-- See hledger-check-fancyassertions.hs + +--package string-qq -- This is an unfinished prototype, see https://github.com/simonmichael/hledger/issues/1171 -- Requires a contemporaneous version of the hledger package. diff --git a/bin/hledger-swap-dates.hs b/bin/hledger-swap-dates.hs index c8fd88f41..cb81735cd 100755 --- a/bin/hledger-swap-dates.hs +++ b/bin/hledger-swap-dates.hs @@ -1,5 +1,5 @@ -#!/usr/bin/env stack --- stack script --compile --resolver lts-16.25 +#!/usr/bin/env -S stack ghc --verbosity info --package hledger -- -O0 +-- See hledger-check-fancyassertions.hs {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} {-# LANGUAGE NamedFieldPuns #-} diff --git a/bin/scripts.test b/bin/scripts.test index 54ca44b5b..b963fdcfd 100644 --- a/bin/scripts.test +++ b/bin/scripts.test @@ -3,10 +3,10 @@ # Check that they all (or at least these ones) still compile with this version of hledger. # stdout and exit code are ignored for cleaner failure output. # $ ./compile.sh >/dev/null -$ stack ghc -- hledger-balance-as-budget.hs >/dev/null || true -$ stack ghc -- hledger-check-fancyassertions.hs >/dev/null || true -$ stack ghc -- hledger-check-tagfiles.hs >/dev/null || true -$ stack ghc -- hledger-combine-balances.hs >/dev/null || true -$ stack ghc --package string-qq -- hledger-print-location.hs >/dev/null || true -$ stack ghc --package string-qq -- hledger-smooth.hs >/dev/null || true -$ stack ghc --package string-qq -- hledger-swap-dates.hs >/dev/null || true +$ ./hledger-balance-as-budget.hs >/dev/null || true +$ ./hledger-check-fancyassertions.hs >/dev/null || true +$ ./hledger-check-tagfiles.hs >/dev/null || true +$ ./hledger-combine-balances.hs >/dev/null || true +$ ./hledger-print-location.hs >/dev/null || true +$ ./hledger-smooth.hs >/dev/null || true +$ ./hledger-swap-dates.hs >/dev/null || true