2016-02-21 13:21:41 +03:00
|
|
|
#!/usr/bin/env stack
|
2024-04-23 11:02:41 +03:00
|
|
|
{- stack script --resolver nightly-2024-04-22 --compile
|
2022-02-05 20:28:59 +03:00
|
|
|
--extra-include-dirs /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/ffi
|
2016-04-05 16:59:52 +03:00
|
|
|
--package base-prelude
|
|
|
|
--package directory
|
|
|
|
--package extra
|
2020-03-19 01:40:39 +03:00
|
|
|
--package process
|
2019-02-08 22:32:37 +03:00
|
|
|
--package regex
|
2016-04-05 16:59:52 +03:00
|
|
|
--package safe
|
|
|
|
--package shake
|
|
|
|
--package time
|
2019-11-29 18:48:03 +03:00
|
|
|
-}
|
2016-04-05 16:59:52 +03:00
|
|
|
{-
|
2020-03-19 02:22:18 +03:00
|
|
|
-- add this to see packages being installed instead of a long silence:
|
|
|
|
--verbosity=info
|
2016-10-28 21:15:10 +03:00
|
|
|
|
2023-12-09 13:15:17 +03:00
|
|
|
Heavy project scripts, with file dependencies, using https://shakebuild.com.
|
|
|
|
See also justfile, Makefile.
|
|
|
|
Also uses tools like:
|
2021-08-03 21:54:17 +03:00
|
|
|
- hpack (same version that's in current stack release)
|
2023-12-09 13:15:17 +03:00
|
|
|
- GNU date (on mac, get it with brew install coreutils)
|
|
|
|
- pandoc, groff, m4, makeinfo, sed, mv, cat, rm
|
2016-12-31 01:32:43 +03:00
|
|
|
|
2020-03-19 02:22:18 +03:00
|
|
|
Some things that may be useful when working on this:
|
|
|
|
- https://docs.haskellstack.org/en/stable/GUIDE/#script-interpreter
|
2020-03-19 01:40:39 +03:00
|
|
|
- watch Shake.hs for compile errors: make ghcid-shake
|
|
|
|
- load Shake.hs in GHCI: make ghci-shake
|
|
|
|
- rebuild things when files change with entr (file watcher), eg:
|
|
|
|
find hledger-lib hledger | entr ./Shake manuals
|
|
|
|
- view rule dependency graph:
|
|
|
|
./Shake --report, open report.html?mode=rule-graph&query=!name(/(doc%7Cimages%7Cjs%7Ccss%7Cfonts%7Ctime%7Capi%7Cui%7Ccsv)/)
|
2019-01-20 01:49:20 +03:00
|
|
|
|
2016-10-28 21:15:10 +03:00
|
|
|
-}
|
2016-04-05 16:59:52 +03:00
|
|
|
|
2019-02-01 04:36:52 +03:00
|
|
|
{-# LANGUAGE MultiWayIf #-}
|
2019-02-08 22:32:37 +03:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2019-02-01 04:36:52 +03:00
|
|
|
{-# LANGUAGE PackageImports #-}
|
2019-02-08 22:32:37 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
2019-02-01 04:36:52 +03:00
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
2016-10-29 20:51:43 +03:00
|
|
|
|
2016-04-05 16:59:52 +03:00
|
|
|
import Prelude ()
|
|
|
|
import "base-prelude" BasePrelude
|
2019-02-01 04:36:52 +03:00
|
|
|
import "base" Control.Exception as C
|
|
|
|
-- required packages, keep synced with Makefile -> SHAKEDEPS:
|
2018-03-31 04:43:28 +03:00
|
|
|
import "directory" System.Directory as S (getDirectoryContents)
|
2020-09-05 03:57:40 +03:00
|
|
|
import "extra" Data.List.Extra hiding (headDef, lastDef)
|
2019-02-08 22:32:37 +03:00
|
|
|
import "regex" Text.RE.TDFA.String
|
|
|
|
import "regex" Text.RE.Replace
|
2016-04-05 16:59:52 +03:00
|
|
|
import "safe" Safe
|
|
|
|
import "shake" Development.Shake
|
|
|
|
import "shake" Development.Shake.FilePath
|
|
|
|
import "time" Data.Time
|
2019-01-20 01:49:20 +03:00
|
|
|
-- import "hledger-lib" Hledger.Utils.Debug
|
2016-04-05 16:59:52 +03:00
|
|
|
|
2020-03-19 01:40:39 +03:00
|
|
|
usage =
|
|
|
|
let scriptname = "Shake" in replaceRe [re|/Shake|] ('/':scriptname) $
|
|
|
|
unlines
|
2019-02-01 21:19:12 +03:00
|
|
|
---------------------------------------79--------------------------------------
|
2023-12-09 13:15:17 +03:00
|
|
|
["Shake: heavy project scripting. See also: justfile, Makefile"
|
2020-03-19 01:40:39 +03:00
|
|
|
,"Usage:"
|
2020-09-05 03:09:07 +03:00
|
|
|
,"./Shake.hs [CMD [ARGS]] run CMD, compiling this script first if needed"
|
|
|
|
,"./Shake [CMD [ARGS]] run CMD, using the compiled version of this script"
|
2020-09-06 04:21:09 +03:00
|
|
|
,"./Shake [help] show this help"
|
2020-12-15 21:15:06 +03:00
|
|
|
,"./Shake cabalfiles [-c] update */*.cabal files from */package.yaml"
|
|
|
|
,"./Shake setversion [VER] [PKGS] [-c]"
|
|
|
|
," update versions in source files to */.version or VER"
|
|
|
|
," and update */*.cabal files"
|
|
|
|
,"./Shake cmdhelp [-c] update hledger CLI commands' help texts"
|
2021-03-18 17:21:51 +03:00
|
|
|
,"./Shake mandates update the date shown in some manual formats"
|
2020-12-15 21:15:06 +03:00
|
|
|
,"./Shake manuals [-c] update all packages' txt/man/info/web manuals"
|
2020-09-07 21:05:00 +03:00
|
|
|
-- ,"./Shake webmanuals update just the web manuals"
|
2020-12-15 21:15:06 +03:00
|
|
|
,"./Shake changelogs [-c] [-n/--dry-run]"
|
|
|
|
," update CHANGES.md files, adding new commits & headings"
|
2020-12-15 23:38:57 +03:00
|
|
|
,"./Shake docs [-c] update all program docs (CLI help, manuals, changelogs)"
|
2021-09-19 19:59:51 +03:00
|
|
|
,"./Shake site update (render) the website, in ./site"
|
2020-09-07 16:25:36 +03:00
|
|
|
,"./Shake build [PKGS] build hledger packages and their embedded docs"
|
2020-09-07 20:22:56 +03:00
|
|
|
,"./Shake clean remove generated texts, manuals"
|
|
|
|
,"./Shake Clean also remove object files, Shake's cache"
|
2020-09-05 03:09:07 +03:00
|
|
|
,"./Shake FILE build any individual file"
|
2020-12-15 21:15:06 +03:00
|
|
|
,"./Shake --help list shake build options (--color, --rebuild, etc."
|
|
|
|
," Keep shake option arguments adjacent to their flag.)"
|
|
|
|
,""
|
|
|
|
,"See comments in Shake.hs for more detailed descriptions."
|
|
|
|
,"Add -c/--commit to have commands commit their changes."
|
|
|
|
,"Add -V/-VV/-VVV to see more verbose output."
|
|
|
|
,"Add -B, with nothing immediately after it, to force rebuilding."
|
2016-10-28 21:15:10 +03:00
|
|
|
]
|
2020-12-15 19:52:56 +03:00
|
|
|
-- TODO
|
2020-12-15 21:15:06 +03:00
|
|
|
-- ,"./Shake releasebranch create a new release branch, bump master to next dev version (.99)"
|
|
|
|
-- ,"./Shake majorversion bump to the next major version project-wide, update affected files"
|
|
|
|
-- ,"./Shake minorversion PKGS bump one or more packages to their next minor version project-wide, update affected files"
|
2020-12-16 00:30:21 +03:00
|
|
|
-- ,"./Shake relnotes create draft release notes"
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2019-09-02 21:05:28 +03:00
|
|
|
-- groff = "groff -c" ++ " -Wall" -- see "groff" below
|
2020-12-23 03:59:01 +03:00
|
|
|
m4 = "m4 -P"
|
2023-04-07 03:03:24 +03:00
|
|
|
makeinfo = "makeinfo -cASCII_PUNCTUATION=1 --no-split --force --no-warn --no-validate" -- silence makeinfo warnings, comment these to see them
|
2020-01-06 18:07:19 +03:00
|
|
|
pandoc = "pandoc --strip-comments"
|
2019-02-05 22:54:10 +03:00
|
|
|
|
2020-12-15 23:30:54 +03:00
|
|
|
-- We should work with both BSD and GNU sed. Tips:
|
2019-02-05 22:54:10 +03:00
|
|
|
-- use [a-z] [0-9] instead of \w \d etc.
|
2020-12-15 23:30:54 +03:00
|
|
|
-- backslash-escape things like: { &
|
|
|
|
sed = "sed -E"
|
|
|
|
|
|
|
|
-- We should work with both BSD and GNU grep.
|
|
|
|
grep = "grep -E"
|
2019-01-20 02:16:08 +03:00
|
|
|
|
|
|
|
-- The kind of markdown used in our doc source files.
|
2021-06-17 22:43:40 +03:00
|
|
|
-- Note: without +hard_line_breaks here, paragraphs get refilled,
|
|
|
|
-- which is good for nice rendered info/man/text output, but so do
|
|
|
|
-- multiline arguments to m4 macros, which is bad eg when using
|
|
|
|
-- _info_ to add Info directives (cf #806). For such situations we
|
|
|
|
-- work around by calling the macro for each line of text, it
|
|
|
|
-- would be nice to find a way to avoid this.
|
2019-01-25 02:23:41 +03:00
|
|
|
fromsrcmd = "-f markdown-smart-tex_math_dollars"
|
2019-01-20 02:16:08 +03:00
|
|
|
|
2021-09-19 19:58:16 +03:00
|
|
|
-- The kind of org markup used in any org source files.
|
2021-09-28 01:15:09 +03:00
|
|
|
-- In pandoc 2.14, org reader enables smart dashes by default;
|
|
|
|
-- use #+OPTIONS: -:nil in the org file to disable it (-smart here has no effect).
|
|
|
|
-- We also write to markdown+strict, which would undo any smart dashes or quotes).
|
2021-09-26 02:13:00 +03:00
|
|
|
fromorg = "-f org-smart"
|
2021-09-19 19:58:16 +03:00
|
|
|
|
2019-01-20 02:16:08 +03:00
|
|
|
-- The kind of markdown we like to generate for the website.
|
2021-09-26 22:57:35 +03:00
|
|
|
--
|
2021-09-26 02:13:00 +03:00
|
|
|
-- This was configured for sphinx+recommonmark+sphinx-markdown-tables; it could be reviewed now that we use mdbook.
|
|
|
|
-- Trying to force the use of pipe_tables here, but sometimes it uses html instead.
|
2021-09-26 22:57:35 +03:00
|
|
|
--
|
|
|
|
-- --markdown-headings=atx requires pandoc 2.11.2+; with older pandoc use --atx-headers instead.
|
|
|
|
--
|
2021-09-28 01:15:09 +03:00
|
|
|
-- In pandoc 2.14, "If you are writing Markdown, then the smart extension has the
|
2021-09-26 22:57:35 +03:00
|
|
|
-- reverse effect: what would have been curly quotes comes out straight.".
|
2021-09-28 01:15:09 +03:00
|
|
|
-- So +smart here can fix unwanted smart typography that may have crept in,
|
|
|
|
-- eg from org docs (see above).
|
2021-09-26 22:57:35 +03:00
|
|
|
--
|
|
|
|
towebmd = "-t markdown+smart-fenced_divs-fenced_code_attributes-simple_tables-multiline_tables-grid_tables-raw_attribute --markdown-headings=atx"
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2018-12-03 20:21:05 +03:00
|
|
|
|
2016-02-21 13:21:41 +03:00
|
|
|
main = do
|
|
|
|
|
2020-09-07 19:51:25 +03:00
|
|
|
-- Gather some IO values used by rules.
|
2020-09-05 02:24:42 +03:00
|
|
|
|
2019-01-27 03:21:59 +03:00
|
|
|
-- hledger manual also includes the markdown files from here:
|
|
|
|
let commandsdir = "hledger/Hledger/Cli/Commands"
|
2019-03-04 22:37:40 +03:00
|
|
|
commandmds <-
|
|
|
|
filter (not . ("README." `isPrefixOf`) . takeFileName) . filter (".md" `isSuffixOf`) . map (commandsdir </>)
|
|
|
|
<$> S.getDirectoryContents commandsdir
|
2019-01-30 21:27:53 +03:00
|
|
|
let commandtxts = map (-<.> "txt") commandmds
|
2019-01-27 03:21:59 +03:00
|
|
|
|
2020-09-07 19:51:25 +03:00
|
|
|
-- Run the shake rule selected by the first command line argument.
|
|
|
|
-- Other arguments and some custom flags are set aside for the rule
|
|
|
|
-- to use if it wants.
|
2016-04-06 02:16:38 +03:00
|
|
|
|
2020-09-07 19:51:25 +03:00
|
|
|
-- Option arguments should be kept adjacent to their flag or this will go wrong.
|
|
|
|
(opts, args) <- partition ("-" `isPrefixOf`) <$> getArgs
|
2020-09-05 02:24:42 +03:00
|
|
|
let
|
2020-09-07 20:22:56 +03:00
|
|
|
ruleoptnames = [
|
|
|
|
"--commit", "-c"
|
|
|
|
,"--dry-run", "--dry", "-n"
|
|
|
|
]
|
2020-09-07 19:51:25 +03:00
|
|
|
(ruleopts, shakeopts) = partition (`elem` ruleoptnames) opts
|
2020-09-07 20:46:27 +03:00
|
|
|
commit = any (`elem` ruleopts) ["--commit", "-c"]
|
|
|
|
dryrun = any (`elem` ruleopts) ["--dry-run", "--dry", "-n"]
|
2020-09-07 19:51:25 +03:00
|
|
|
(shakearg, ruleargs) = splitAt 1 args
|
|
|
|
shakeargs = shakeopts ++ shakearg
|
|
|
|
-- print (opts,args,shakeopts,shakearg,shakeargs,ruleopts,ruleargs)
|
2020-12-15 21:15:06 +03:00
|
|
|
|
2020-09-07 19:51:25 +03:00
|
|
|
withArgs shakeargs $ shakeArgs shakeOptions{
|
|
|
|
shakeVerbosity=Quiet
|
|
|
|
-- ,shakeReport=[".shake.html"]
|
|
|
|
}
|
|
|
|
$ do
|
|
|
|
|
|
|
|
-- The rules.
|
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
want ["help"]
|
2019-01-20 01:49:20 +03:00
|
|
|
|
2020-09-07 20:22:56 +03:00
|
|
|
phony "help" $ liftIO $ putStr usage
|
2016-04-08 17:01:11 +03:00
|
|
|
|
2020-09-07 20:46:27 +03:00
|
|
|
-- NAMES, FILES, URIS, HELPERS
|
2017-01-26 17:40:50 +03:00
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
let
|
|
|
|
-- main package names, in standard build order
|
|
|
|
packages = [
|
|
|
|
"hledger-lib"
|
|
|
|
,"hledger"
|
|
|
|
,"hledger-ui"
|
|
|
|
,"hledger-web"
|
|
|
|
]
|
2020-09-05 03:57:40 +03:00
|
|
|
pkgdirs = packages
|
|
|
|
pkgandprojdirs = "" : pkgdirs
|
2020-09-07 21:05:00 +03:00
|
|
|
cabalfiles = [p </> p <.> "cabal" | p <- packages]
|
2020-09-06 04:01:47 +03:00
|
|
|
changelogs = map (</> "CHANGES.md") pkgandprojdirs
|
2020-12-15 20:24:02 +03:00
|
|
|
packagemanversionm4s = [p </> ".version.m4" | p <- packages]
|
|
|
|
packagemandatem4s = [p </> ".date.m4" | p <- packages]
|
2020-09-05 02:24:42 +03:00
|
|
|
|
|
|
|
-- doc files (or related targets) that should be generated
|
|
|
|
-- before building hledger packages.
|
|
|
|
-- [(PKG, [TARGETS])]
|
|
|
|
embeddedFiles = [
|
|
|
|
-- hledger embeds the plain text command help files and all packages' text/nroff/info manuals
|
|
|
|
("hledger", commandtxts ++ ["manuals"])
|
|
|
|
-- hledger-ui imports the hledger-ui manuals from hledger
|
|
|
|
,("hledger-ui", ["hledger"])
|
|
|
|
]
|
|
|
|
|
|
|
|
-- man page names (manual names plus a man section number), in suggested reading order
|
|
|
|
manpageNames = [
|
|
|
|
"hledger.1"
|
|
|
|
,"hledger-ui.1"
|
|
|
|
,"hledger-web.1"
|
|
|
|
]
|
|
|
|
|
|
|
|
-- basic manual names, without numbers
|
|
|
|
manualNames = map manpageNameToManualName manpageNames
|
|
|
|
|
|
|
|
-- main markdown+m4 source files for manuals (hledger/hledger.m4.md)
|
|
|
|
-- These may include additional files using m4.
|
|
|
|
m4manuals = [manualDir m </> m <.> "m4.md" | m <- manualNames]
|
|
|
|
|
|
|
|
-- manuals as plain text, ready for embedding as CLI help (hledger/hledger.txt)
|
|
|
|
txtmanuals = [manualDir m </> m <.> "txt" | m <- manualNames]
|
|
|
|
|
|
|
|
-- manuals as nroff, ready for man (hledger/hledger.1)
|
|
|
|
nroffmanuals = [manpageDir m </> m | m <- manpageNames]
|
|
|
|
|
|
|
|
-- manuals as info, ready for info (hledger/hledger.info)
|
|
|
|
infomanuals = [manualDir m </> m <.> "info" | m <- manualNames]
|
2021-06-28 10:24:51 +03:00
|
|
|
-- an Info directory entry for each package's info manual (hledger/dir-entry.texi)
|
|
|
|
infodirentries = [manualDir m </> "dir-entry.texi" | m <- manualNames]
|
|
|
|
-- a generated Info directory file for easily accessing/linking the dev version of all the info manuals
|
2021-08-03 11:12:04 +03:00
|
|
|
-- infodir = "dir"
|
2020-09-05 02:24:42 +03:00
|
|
|
|
2021-03-18 16:48:07 +03:00
|
|
|
-- manuals as sphinx-ready markdown, to be rendered as part of the website (hledger/hledger.md)
|
|
|
|
webmanuals = [manualDir m </> m <.> "md" | m <- manualNames]
|
2020-09-05 02:24:42 +03:00
|
|
|
|
|
|
|
-- -- old versions of the manuals rendered to html (site/_site/doc/1.14/hledger.html)
|
|
|
|
-- oldhtmlmanuals = map (normalise . ("site/_site/doc" </>) . (<.> "html")) $
|
|
|
|
-- [ v </> manpageNameToWebManualName p | v <- docversions, v>="1.0", p <- manpageNames ++ ["manual"] ] ++
|
|
|
|
-- [ v </> "manual" | v <- docversions, v <"1.0" ] -- before 1.0 there was only the combined manual
|
|
|
|
|
|
|
|
-- The directory in which to find this man page.
|
|
|
|
-- hledger.1 -> hledger/doc, hledger_journal.5 -> hledger-lib/doc
|
|
|
|
manpageDir m
|
|
|
|
| '_' `elem` m = "hledger-lib"
|
|
|
|
| otherwise = dropExtension m
|
|
|
|
|
|
|
|
-- The directory in which to find this manual.
|
|
|
|
-- hledger -> hledger, hledger_journal -> hledger-lib
|
|
|
|
manualDir m
|
|
|
|
| '_' `elem` m = "hledger-lib"
|
|
|
|
| otherwise = m
|
|
|
|
|
|
|
|
-- The web manual name (& URI "slug") corresponding to this man page.
|
|
|
|
-- hledger.1 -> hledger, hledger_journal.5 -> journal
|
|
|
|
manpageNameToWebManualName m | "hledger_" `isPrefixOf` m = dropExtension $ drop 8 m
|
|
|
|
| otherwise = dropExtension m
|
|
|
|
|
|
|
|
-- The man page corresponding to this web manual name.
|
|
|
|
-- hledger -> hledger.1, journal -> hledger_journal.5
|
|
|
|
webManualNameToManpageName u | "hledger" `isPrefixOf` u = u <.> "1"
|
|
|
|
| otherwise = "hledger_" ++ u <.> "5"
|
|
|
|
|
2020-09-07 20:46:27 +03:00
|
|
|
-- VERSION NUMBERS
|
|
|
|
|
2021-08-03 21:28:36 +03:00
|
|
|
-- Regenerate .cabal files from package.yaml files.
|
2020-12-15 21:15:06 +03:00
|
|
|
-- (used by "cabalfiles" and "setversion")
|
2021-08-03 21:28:36 +03:00
|
|
|
let gencabalfiles = do
|
2021-08-03 21:54:17 +03:00
|
|
|
|
2022-04-15 03:20:42 +03:00
|
|
|
-- Update cabal files with stack build.
|
|
|
|
-- stack 1.7+ no longer updates cabal files with --dry-run, we must do a full build.
|
|
|
|
-- stack can return zero exit code while failing to update cabal files so
|
|
|
|
-- we need to check for the error message (specifically) on stderr.
|
|
|
|
-- out <- fromStdouterr <$> -- (getting both stdout and stderr here just as an example)
|
|
|
|
-- (cmd (EchoStdout True) (EchoStderr True) Shell "stack build" :: Action (Stdouterr String))
|
|
|
|
-- when ("was generated with a newer version of hpack" `isInfixOf` out) $
|
|
|
|
-- liftIO $ putStr out >> exitFailure
|
|
|
|
|
|
|
|
-- Or update them with hpack directly.
|
|
|
|
-- It should be the same hpack version that's in current stack, to avoid commit conflicts.
|
|
|
|
forM_ pkgdirs $ \d -> cmd_ (Cwd d) Shell "hpack --no-hash"
|
|
|
|
|
2023-06-15 11:41:47 +03:00
|
|
|
when commit $ commitIfChanged ";cabal: update cabal files" cabalfiles
|
2020-12-15 21:15:06 +03:00
|
|
|
|
|
|
|
-- Update version strings in most "source" files to match what's in PKG/.version.
|
|
|
|
-- If a version number is provided as first argument, save that in PKG/.version files first.
|
2020-09-07 20:46:27 +03:00
|
|
|
-- If one or more subdirectories are provided as arguments, save/update only those.
|
2020-12-15 21:15:06 +03:00
|
|
|
-- Also regenerates .cabal files from package.yaml files.
|
2020-09-07 20:46:27 +03:00
|
|
|
-- See also CONTRIBUTING.md > Version numbers.
|
|
|
|
phony "setversion" $ do
|
|
|
|
let
|
|
|
|
(mver, dirargs) = (headMay ver', drop 1 ver' ++ dirs')
|
|
|
|
where (ver',dirs') = span isVersion ruleargs
|
|
|
|
(specifieddirs, specifiedpkgs) =
|
|
|
|
case dirargs of [] -> (pkgandprojdirs, pkgdirs)
|
|
|
|
ds -> (ds, ds)
|
|
|
|
-- if a version was provided, update .version files in the specified directories
|
|
|
|
let specifiedversionfiles = map (</> ".version") specifieddirs
|
|
|
|
case mver of
|
2020-12-15 21:15:06 +03:00
|
|
|
Just v -> liftIO $ forM_ specifiedversionfiles $ flip maybeWriteFile (v++"\n")
|
2020-09-07 20:46:27 +03:00
|
|
|
Nothing -> return ()
|
|
|
|
|
2020-12-15 20:24:02 +03:00
|
|
|
-- update "source" files depending on .version in the specified packages
|
2021-08-16 07:25:18 +03:00
|
|
|
let dependents = map (</> ".version.m4") specifiedpkgs
|
|
|
|
++ map (</> "package.yaml") specifiedpkgs
|
2020-09-07 20:46:27 +03:00
|
|
|
need dependents
|
|
|
|
|
|
|
|
-- and maybe commit them
|
|
|
|
when commit $ do
|
|
|
|
let msg = unwords [
|
2021-07-12 03:37:44 +03:00
|
|
|
";pkg: bump"
|
2020-09-07 22:19:16 +03:00
|
|
|
,case dirargs of
|
2020-09-07 20:46:27 +03:00
|
|
|
[] -> "version"
|
2020-09-07 22:19:16 +03:00
|
|
|
ds -> intercalate ", " ds ++ " version"
|
2020-09-07 20:46:27 +03:00
|
|
|
,case mver of
|
|
|
|
Nothing -> ""
|
|
|
|
Just v -> "to " ++ v
|
|
|
|
]
|
2023-06-15 11:41:47 +03:00
|
|
|
commitIfChanged msg $ specifiedversionfiles ++ dependents
|
2020-09-07 20:46:27 +03:00
|
|
|
|
2021-08-03 21:28:36 +03:00
|
|
|
gencabalfiles
|
2020-12-15 21:15:06 +03:00
|
|
|
|
2020-12-15 20:24:02 +03:00
|
|
|
-- PKG/.version.m4 <- PKG/.version, just updates the _version_ macro
|
|
|
|
"hledger*/.version.m4" %> \out -> do
|
2020-09-07 20:46:27 +03:00
|
|
|
let versionfile = takeDirectory out </> ".version"
|
|
|
|
need [versionfile]
|
|
|
|
version <- ((head . words) <$>) $ liftIO $ readFile versionfile
|
2020-12-07 22:37:39 +03:00
|
|
|
cmd_ Shell sed "-i -e" ("'s/(_version_}}, *)\\{\\{[^}]+/\\1{{"++version++"/;'") out
|
|
|
|
|
|
|
|
-- PKG/package.yaml <- PKG/.version, just updates version strings
|
2020-09-07 20:46:27 +03:00
|
|
|
"hledger*/package.yaml" %> \out -> do
|
|
|
|
let versionfile = takeDirectory out </> ".version"
|
|
|
|
need [versionfile]
|
|
|
|
version <- ((head . words) <$>) $ liftIO $ readFile versionfile
|
|
|
|
let ma:jor:_ = splitOn "." version
|
2021-08-16 07:25:18 +03:00
|
|
|
nextmajorversion = intercalate "." [ma, show $ read jor+1]
|
2020-09-07 20:46:27 +03:00
|
|
|
|
|
|
|
-- One simple task: update some strings in a small text file.
|
|
|
|
-- Several ugly solutions:
|
|
|
|
--
|
|
|
|
-- 1. use haskell list utils. Tedious.
|
|
|
|
-- old <- liftIO $ readFileStrictly out
|
|
|
|
-- let isversionline s = "version" `isPrefixOf` (dropWhile isSpace $ takeWhile (not.(`elem` " :")) s)
|
|
|
|
-- (before, _:after) = break isversionline $ lines old
|
|
|
|
-- -- oldversion = words versionline !! 1
|
|
|
|
-- new = unlines $ before ++ ["version: "++version] ++ after
|
|
|
|
-- liftIO $ writeFile out new
|
|
|
|
--
|
|
|
|
-- 2. use regular expressions in haskell. Haskell has no portable,
|
|
|
|
-- featureful, replacing, backreference-supporting regex lib yet.
|
|
|
|
--
|
|
|
|
-- 3. use sed. Have to assume non-GNU sed, eg on mac.
|
|
|
|
|
|
|
|
-- Things to update in package.yaml:
|
|
|
|
--
|
|
|
|
-- version: VER
|
|
|
|
cmd_ Shell sed "-i -e" ("'s/(^version *:).*/\\1 "++version++"/'") out
|
|
|
|
--
|
|
|
|
-- -DVERSION="VER"
|
|
|
|
cmd_ Shell sed "-i -e" ("'s/(-DVERSION=)\"[^\"]+/\\1\""++version++"/'") out
|
|
|
|
--
|
|
|
|
-- this package's dependencies on other hledger packages (typically hledger-lib, hledger)
|
|
|
|
--
|
|
|
|
-- This one is a bit tricky, and we do it with these limitations:
|
|
|
|
-- a. We handle bounds in one of these forms (allowing extra whitespace):
|
|
|
|
-- ==A
|
|
|
|
-- >A
|
|
|
|
-- >=A
|
|
|
|
-- >A && <B
|
|
|
|
-- >=A && <B
|
|
|
|
-- b. We set
|
|
|
|
-- the new lower bound to: this package's new version, V
|
|
|
|
-- the new upper bound if any, to: the next major version after V
|
|
|
|
-- both of which may not be what's desired.
|
|
|
|
-- c. We convert > bounds to >= bounds.
|
|
|
|
--
|
|
|
|
-- hledger[-PKG] ==LOWER
|
|
|
|
let versionre = "([0-9]+\\.)*[0-9]+" -- 2 or 3 part version number regexp
|
|
|
|
cmd_ Shell sed "-i -e" ("'s/(hledger(-[a-z]+)?) *== *"++versionre++" *$/\\1 == "++version++"/'") out
|
|
|
|
--
|
|
|
|
-- hledger[-PKG] >[=]LOWER
|
|
|
|
cmd_ Shell sed "-i -e" ("'s/(hledger(-[a-z]+)?) *>=? *"++versionre++" *$/\\1 >= "++version++"/'") out
|
|
|
|
--
|
|
|
|
-- hledger[-PKG] >[=]LOWER && <UPPER
|
|
|
|
let
|
|
|
|
pat = "(hledger(-[a-z]+)?) *>=? *"++versionre++" *&& *< *"++versionre++" *$"
|
|
|
|
rpl = "\\1 >="++version++" \\&\\& <"++nextmajorversion -- This was a beast. These ampersands must be backslash-escaped.
|
|
|
|
arg = "'s/"++pat++"/"++rpl++"/'"
|
|
|
|
cmd_ Shell sed "-i -e" arg out
|
|
|
|
|
2020-12-15 23:30:54 +03:00
|
|
|
let pkg = takeDirectory out
|
|
|
|
when (pkg /= "hledger-lib") $ liftIO $ do
|
2020-12-15 23:41:33 +03:00
|
|
|
putStrLn $ out++": hledger bounds are (improve if needed):"
|
2020-12-15 23:30:54 +03:00
|
|
|
cmd_ Shell grep "'^ *- +hledger.*[<>=]'" out
|
|
|
|
" || [[ $? == 1 ]]" -- ignore no matches, https://unix.stackexchange.com/a/427598
|
2020-09-07 20:46:27 +03:00
|
|
|
|
2021-08-03 21:28:36 +03:00
|
|
|
phony "cabalfiles" $ gencabalfiles
|
2020-12-15 21:15:06 +03:00
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
-- MANUALS
|
|
|
|
|
|
|
|
-- Generate the manuals in plain text, nroff, info, and markdown formats.
|
2020-09-07 21:05:00 +03:00
|
|
|
phony "manuals" $ do
|
|
|
|
need $ concat [
|
|
|
|
nroffmanuals
|
|
|
|
,infomanuals
|
2021-08-03 11:12:04 +03:00
|
|
|
-- ,[infodir]
|
2020-09-07 21:05:00 +03:00
|
|
|
,txtmanuals
|
|
|
|
,webmanuals
|
|
|
|
]
|
2023-06-15 11:41:47 +03:00
|
|
|
when commit $
|
|
|
|
commitIfChanged ";doc: update manuals" $
|
|
|
|
concat [packagemandatem4s, nroffmanuals, infomanuals, infodirentries, txtmanuals] -- infodir
|
2019-02-01 04:36:52 +03:00
|
|
|
|
2021-03-18 17:21:51 +03:00
|
|
|
-- Update the dates to show in man pages, to the current month and year.
|
|
|
|
-- Currently must be run manually when needed.
|
|
|
|
-- Dates are stored in PKG/.date.m4, and are committed along with manuals by Shake manuals -c.
|
|
|
|
phony "mandates" $ do
|
|
|
|
date <- chomp . fromStdout <$> (cmd Shell "date +'%B %Y'" :: Action (Stdout String))
|
|
|
|
forM_ packagemandatem4s $ \f -> do
|
|
|
|
cmd_ Shell ["perl","-pi","-e","'s/(.*)\\{\\{.*}}(.*)$/\\1\\{\\{"++date++"}}\\2/'",f]
|
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
-- Generate nroff man pages suitable for man output, from the .m4.md source.
|
2020-12-15 20:24:02 +03:00
|
|
|
-- Also updates the _monthyear_ macro to current month and year in hledger*/.date.m4.
|
2020-09-05 02:24:42 +03:00
|
|
|
phony "nroffmanuals" $ need nroffmanuals
|
|
|
|
nroffmanuals |%> \out -> do -- hledger/hledger.1
|
|
|
|
let src = manpageNameToManualName out <.> "m4.md"
|
|
|
|
commonm4 = "doc/common.m4"
|
2020-12-23 03:59:01 +03:00
|
|
|
commandsm4 = "hledger/Hledger/Cli/Commands/commands.m4"
|
2020-09-05 02:24:42 +03:00
|
|
|
dir = takeDirectory out
|
2020-12-21 04:10:51 +03:00
|
|
|
pkg = dir
|
2020-12-15 20:24:02 +03:00
|
|
|
packagemanversionm4 = dir </> ".version.m4"
|
|
|
|
packagemandatem4 = dir </> ".date.m4"
|
2020-09-05 02:24:42 +03:00
|
|
|
tmpl = "doc/manpage.nroff"
|
2020-12-21 04:10:51 +03:00
|
|
|
pkgversion <- liftIO $ readFile $ dir </> ".version"
|
|
|
|
-- mandate <- formatTime defaultTimeLocale "%B %Y" <$> liftIO getCurrentDay -- XXX not using this.. compare with .date.m4
|
2020-12-23 03:59:01 +03:00
|
|
|
-- assume any other .m4.md files in dir are included by this one XXX not true in hledger-lib
|
|
|
|
subfiles <- liftIO $ filter (/= src) . filter (".m4.md" `isSuffixOf`) . map (dir </>) <$> S.getDirectoryContents dir
|
|
|
|
need $ [src, commonm4, commandsm4, packagemanversionm4, packagemandatem4, tmpl] ++ subfiles
|
2020-09-05 02:24:42 +03:00
|
|
|
when (dir=="hledger") $ need commandmds
|
|
|
|
cmd Shell
|
2021-06-17 21:28:19 +03:00
|
|
|
m4 "-DMANFORMAT -I" dir commonm4 commandsm4 packagemanversionm4 packagemandatem4 src "|"
|
2020-09-05 02:24:42 +03:00
|
|
|
pandoc fromsrcmd "-s" "--template" tmpl
|
2020-12-21 04:10:51 +03:00
|
|
|
("-V footer='"++pkg++"-"++pkgversion++"'")
|
2020-09-05 02:24:42 +03:00
|
|
|
"--lua-filter tools/pandoc-drop-html-blocks.lua"
|
|
|
|
"--lua-filter tools/pandoc-drop-html-inlines.lua"
|
|
|
|
"--lua-filter tools/pandoc-drop-links.lua"
|
|
|
|
"-o" out
|
|
|
|
|
|
|
|
-- Generate plain text manuals suitable for embedding in
|
|
|
|
-- executables and viewing with a pager, from the man pages.
|
2020-12-21 04:58:23 +03:00
|
|
|
-- (Depends on the nroffmanuals.)
|
2020-09-05 02:24:42 +03:00
|
|
|
phony "txtmanuals" $ need txtmanuals
|
|
|
|
txtmanuals |%> \out -> do -- hledger/hledger.txt
|
|
|
|
let src = manualNameToManpageName $ dropExtension out
|
|
|
|
need [src]
|
|
|
|
-- cmd Shell groff "-t -e -mandoc -Tascii" src "| col -b >" out -- http://www.tldp.org/HOWTO/Man-Page/q10.html
|
|
|
|
-- Workaround: groff 1.22.4 always calls grotty in a way that adds ANSI/SGR escape codes.
|
|
|
|
-- (groff -c is supposed to switch those to backspaces, which we could
|
|
|
|
-- remove with col -b, but it doesn't as can be seen with groff -V.)
|
|
|
|
-- To get plain text, we run groff's lower-level commands (from -V) and add -cbuo.
|
|
|
|
-- -Wall silences most troff warnings, remove to see them
|
|
|
|
cmd Shell "tbl" src "| eqn -Tascii | troff -Wall -mandoc -Tascii | grotty -cbuo >" out
|
|
|
|
|
|
|
|
-- Generate Info manuals suitable for viewing with info, from the .m4.md source.
|
|
|
|
infomanuals |%> \out -> do -- hledger/hledger.info
|
|
|
|
let src = out -<.> "m4.md"
|
|
|
|
commonm4 = "doc/common.m4"
|
2020-12-23 03:59:01 +03:00
|
|
|
commandsm4 = "hledger/Hledger/Cli/Commands/commands.m4"
|
2020-09-05 02:24:42 +03:00
|
|
|
dir = takeDirectory out
|
2020-12-15 20:24:02 +03:00
|
|
|
packagemanversionm4 = dir </> ".version.m4"
|
2020-12-25 04:25:11 +03:00
|
|
|
packagemandatem4 = dir </> ".date.m4"
|
2021-06-28 10:24:51 +03:00
|
|
|
direntry = dir </> "dir-entry.texi"
|
2020-12-23 03:59:01 +03:00
|
|
|
-- assume any other .m4.md files in dir are included by this one XXX not true in hledger-lib
|
|
|
|
subfiles <- liftIO $ filter (/= src) . filter (".m4.md" `isSuffixOf`) . map (dir </>) <$> S.getDirectoryContents dir
|
2021-06-28 10:24:51 +03:00
|
|
|
need $ [src, commonm4, commandsm4, packagemanversionm4, packagemandatem4, direntry] ++ subfiles
|
2020-09-05 02:24:42 +03:00
|
|
|
when (dir=="hledger") $ need commandmds
|
2021-06-28 05:23:46 +03:00
|
|
|
cmd_ Shell
|
2021-06-28 10:24:51 +03:00
|
|
|
"( cat" direntry ";"
|
2021-06-17 21:28:19 +03:00
|
|
|
m4 "-DINFOFORMAT -I" dir commonm4 commandsm4 packagemanversionm4 packagemandatem4 src "|"
|
2020-12-19 07:58:17 +03:00
|
|
|
-- sed "-e 's/^#(#+)/\\1/'" "|"
|
2020-09-05 02:24:42 +03:00
|
|
|
pandoc fromsrcmd
|
|
|
|
"--lua-filter tools/pandoc-drop-html-blocks.lua"
|
|
|
|
"--lua-filter tools/pandoc-drop-html-inlines.lua"
|
|
|
|
"--lua-filter tools/pandoc-drop-links.lua"
|
2020-12-20 22:03:21 +03:00
|
|
|
-- add "standalone" headers ? sounds good for setting text encoding,
|
|
|
|
-- but messes up quotes ('a' becomes ^Xa^Y)
|
|
|
|
-- "-s"
|
2021-06-28 10:24:51 +03:00
|
|
|
"-t texinfo ) |"
|
2020-12-19 07:58:17 +03:00
|
|
|
makeinfo "-o" out
|
2021-06-28 05:23:46 +03:00
|
|
|
|
2021-08-03 11:12:04 +03:00
|
|
|
-- XXX This generates ./dir, for previewing latest dev manuals in Info's directory.
|
|
|
|
-- For that we need subdirectory paths like "hledger: (hledger/hledger)",
|
|
|
|
-- but this generates "hledger: (hledger)". Don't regenerate dir for now.
|
|
|
|
--
|
2021-06-28 08:31:15 +03:00
|
|
|
-- Generate an Info dir file which can be included with info -d
|
|
|
|
-- or INFOPATH to add hledger menu items in Info's Directory.
|
2021-08-03 11:12:04 +03:00
|
|
|
-- infodir %> \out -> do
|
|
|
|
-- need infomanuals
|
|
|
|
-- forM_ infomanuals $ \info -> cmd_ Shell "install-info" info out
|
2020-09-05 02:24:42 +03:00
|
|
|
|
2021-08-03 11:21:06 +03:00
|
|
|
phony "infomanuals" $ need $ infomanuals -- ++ [infodir]
|
2020-09-05 02:24:42 +03:00
|
|
|
|
|
|
|
-- WEBSITE MARKDOWN SOURCE
|
|
|
|
|
|
|
|
-- Generate the individual web manuals' markdown source, using m4
|
|
|
|
-- and pandoc to tweak content.
|
|
|
|
phony "webmanuals" $ need webmanuals
|
2021-03-18 16:48:07 +03:00
|
|
|
webmanuals |%> \out -> do -- hledger/hledger.md, hledger/hledger-ui.md ..
|
2020-09-05 02:24:42 +03:00
|
|
|
let
|
|
|
|
dir = takeDirectory out -- hledger, hledger-lib
|
|
|
|
manpage = webManualNameToManpageName $ dropExtension $ dropExtension $ takeFileName out -- hledger, journal
|
|
|
|
manual = manpageNameToManualName manpage -- hledger, hledger_journal
|
|
|
|
src = dir </> manual <.> "m4.md"
|
|
|
|
commonm4 = "doc/common.m4"
|
2020-12-23 03:59:01 +03:00
|
|
|
commandsm4 = "hledger/Hledger/Cli/Commands/commands.m4"
|
2020-12-15 20:24:02 +03:00
|
|
|
packageversionm4 = dir </> ".version.m4"
|
2020-12-25 04:25:11 +03:00
|
|
|
packagemandatem4 = dir </> ".date.m4"
|
2020-09-05 02:24:42 +03:00
|
|
|
heading = let h = manual
|
|
|
|
in if "hledger_" `isPrefixOf` h
|
|
|
|
then drop 8 h ++ " format"
|
|
|
|
else h
|
2020-12-23 03:59:01 +03:00
|
|
|
-- assume any other .m4.md files in dir are included by this one XXX not true in hledger-lib
|
2020-09-05 02:24:42 +03:00
|
|
|
subfiles <- liftIO $ filter (/= src) . filter (".m4.md" `isSuffixOf`) . map (dir </>) <$> S.getDirectoryContents dir
|
2020-12-25 04:25:11 +03:00
|
|
|
let deps = [src, commonm4, commandsm4, packageversionm4, packagemandatem4] ++ subfiles
|
2020-09-05 02:24:42 +03:00
|
|
|
need deps
|
|
|
|
when (manual=="hledger") $ need commandmds
|
|
|
|
-- add the web page's heading.
|
|
|
|
-- XXX Might be nice to do this atomically with the below, so
|
|
|
|
-- make avoid any double refresh when watch docs with entr/livereload.
|
|
|
|
-- But cmd Shell doesn't handle arguments containing spaces properly.
|
|
|
|
liftIO $ writeFile out $ unlines [
|
|
|
|
"<!-- " ++ "Generated by \"Shake webmanuals\" from " ++ unwords deps ++ " -->"
|
2021-03-21 19:01:33 +03:00
|
|
|
,"<div class=\"docversions\"></div>"
|
2021-03-19 18:21:28 +03:00
|
|
|
,""
|
2020-09-05 02:24:42 +03:00
|
|
|
,"# " ++ heading
|
|
|
|
,""
|
2021-07-29 11:20:49 +03:00
|
|
|
,"<div class=\"pagetoc manual\">"
|
2022-06-20 15:00:02 +03:00
|
|
|
,""
|
2021-07-29 11:20:49 +03:00
|
|
|
,"<!-- toc -->"
|
|
|
|
,"</div>"
|
|
|
|
,""
|
2020-09-05 02:24:42 +03:00
|
|
|
]
|
|
|
|
cmd Shell
|
2021-06-17 21:28:19 +03:00
|
|
|
m4 "-DWEBFORMAT -I" dir commonm4 commandsm4 packageversionm4 packagemandatem4 src "|"
|
2020-09-05 02:24:42 +03:00
|
|
|
pandoc fromsrcmd towebmd
|
|
|
|
"--lua-filter tools/pandoc-demote-headers.lua"
|
|
|
|
">>" out
|
|
|
|
|
|
|
|
-- This rule, for updating the live hledger.org site, gets called by:
|
|
|
|
-- 1. github-post-receive (github webhook handler), when something is pushed
|
|
|
|
-- to the main repo on Github. Config:
|
|
|
|
-- /etc/supervisord.conf -> [program:github-post-receive]
|
|
|
|
-- /etc/github-post-receive.conf
|
|
|
|
-- 2. cron, nightly. Config: /etc/crontab
|
|
|
|
-- 3. manually (make site).
|
|
|
|
-- phony "hledgerorg" $ do
|
|
|
|
-- -- XXX ideally we would ensure here that output is logged in site.log,
|
|
|
|
-- -- but I don't know how to do that for the Shake rules.
|
|
|
|
-- -- Instead we'll do the logging in "make site".
|
|
|
|
-- cmd_ Shell
|
2020-09-06 04:21:09 +03:00
|
|
|
--
|
2020-09-05 02:24:42 +03:00
|
|
|
-- -- print timestamp. On mac, use brew-installed GNU date.
|
|
|
|
-- "PATH=\"/usr/local/opt/coreutils/libexec/gnubin:$PATH\" date --rfc-3339=seconds"
|
|
|
|
-- -- pull latest code and site repos - sometimes already done by webhook, not always
|
|
|
|
-- "&& printf 'code repo: ' && git pull"
|
|
|
|
-- "&& printf 'site repo: ' && git -C site pull"
|
2020-09-06 04:21:09 +03:00
|
|
|
--
|
2020-09-05 02:24:42 +03:00
|
|
|
-- -- Shake.hs might have been updated, but we won't execute the
|
|
|
|
-- -- new one, too insecure. Continue with this one.
|
2020-09-06 04:21:09 +03:00
|
|
|
--
|
|
|
|
-- Help:
|
|
|
|
-- ,"./Shake hledgerorg update the hledger.org website (when run on prod)"
|
2020-09-05 02:24:42 +03:00
|
|
|
|
|
|
|
-- HLEDGER PACKAGES/EXECUTABLES
|
|
|
|
|
2020-09-07 16:25:36 +03:00
|
|
|
-- build [PKGS]
|
|
|
|
-- Build some or all hledger packages, after generating any doc
|
2020-09-05 02:24:42 +03:00
|
|
|
-- files they embed or import.
|
2020-12-15 21:15:06 +03:00
|
|
|
-- This may also update .cabal files from package.yaml files, and/or install haskell deps.
|
2020-09-07 16:25:36 +03:00
|
|
|
phony "build" $ do
|
|
|
|
let
|
|
|
|
pkgs | null args = packages
|
|
|
|
| otherwise = args
|
|
|
|
sequence_ [ do
|
|
|
|
need $ fromMaybe [] $ lookup pkg embeddedFiles
|
|
|
|
cmd Shell "stack build " pkg :: Action ()
|
|
|
|
| pkg <- pkgs
|
|
|
|
]
|
2020-09-05 02:24:42 +03:00
|
|
|
|
2020-09-07 16:37:50 +03:00
|
|
|
-- regenerate Hledger/Cli/Commands/*.txt from the .md source files for CLI help
|
2020-12-15 19:52:56 +03:00
|
|
|
phony "cmdhelp" $ do
|
2020-09-07 21:05:00 +03:00
|
|
|
need commandtxts
|
2023-06-15 11:41:47 +03:00
|
|
|
when commit $ commitIfChanged ";doc: update command help" commandtxts
|
2020-09-05 02:24:42 +03:00
|
|
|
|
|
|
|
commandtxts |%> \out -> do
|
|
|
|
let src = out -<.> "md"
|
|
|
|
need [src]
|
|
|
|
cmd Shell
|
|
|
|
pandoc fromsrcmd src "--lua-filter" "tools/pandoc-dedent-code-blocks.lua" "-t plain" ">" out
|
|
|
|
|
|
|
|
-- CHANGELOGS
|
2019-02-01 04:36:52 +03:00
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
let
|
|
|
|
-- git log showing short commit hashes
|
|
|
|
gitlog = "git log --abbrev-commit"
|
|
|
|
|
|
|
|
-- git log formats suitable for changelogs/release notes
|
|
|
|
-- %s=subject, %an=author name, %n=newline if needed, %w=width/indent1/indent2, %b=body, %h=hash
|
2020-12-16 00:04:36 +03:00
|
|
|
changelogGitFormat = "--pretty=format:'- %s (%an)%n%w(0,2,2)%b\n'"
|
2020-09-05 02:24:42 +03:00
|
|
|
-- changelogVerboseGitFormat = "--pretty=format:'- %s (%an)%n%w(0,2,2)%b%h' --stat"
|
|
|
|
|
|
|
|
-- Format a git log message, with one of the formats above, as a changelog item
|
|
|
|
changelogCleanupCmd = unwords [
|
|
|
|
sed
|
|
|
|
,"-e 's/^( )*\\* /\1- /'" -- ensure bullet lists in descriptions use hyphens not stars
|
|
|
|
,"-e 's/ \\(Simon Michael\\)//'" -- strip maintainer's author name
|
|
|
|
,"-e 's/^- (doc: *)?(updated? *)?changelogs?( *updates?)?$//'" -- strip some variants of "updated changelog"
|
|
|
|
,"-e 's/^ +\\[ci skip\\] *$//'" -- strip [ci skip] lines
|
|
|
|
,"-e 's/^ +$//'" -- replace lines containing only spaces with empty lines
|
|
|
|
-- ,"-e 's/\r//'" -- strip windows carriage returns (XXX \r untested. IDEA doesn't like a real ^M here)
|
|
|
|
,"-e '/./,/^$/!d'" -- replace consecutive newlines with one
|
|
|
|
]
|
|
|
|
|
|
|
|
-- Things to exclude when doing git log for project-wide changelog.
|
|
|
|
-- git exclude pathspecs, https://git-scm.com/docs/gitglossary.html#gitglossary-aiddefpathspecapathspec
|
|
|
|
projectChangelogExcludeDirs = unwords [
|
|
|
|
":!hledger-lib"
|
|
|
|
,":!hledger"
|
|
|
|
,":!hledger-ui"
|
|
|
|
,":!hledger-web"
|
|
|
|
,":!tests"
|
|
|
|
]
|
|
|
|
|
|
|
|
-- update all changelogs with latest commits
|
2020-09-07 21:05:00 +03:00
|
|
|
phony "changelogs" $ do
|
|
|
|
need changelogs
|
2023-06-15 11:41:47 +03:00
|
|
|
when commit $ commitIfChanged ";doc: update changelogs" changelogs
|
2020-09-05 02:24:42 +03:00
|
|
|
|
2020-09-06 04:01:47 +03:00
|
|
|
-- [PKG/]CHANGES.md
|
|
|
|
-- Add any new non-boring commits to the specified changelog, in
|
|
|
|
-- an idempotent way, minimising manual toil, as follows. We look at:
|
|
|
|
--
|
|
|
|
-- - the changelog's topmost markdown heading, which can be a
|
|
|
|
-- dev heading (first word is a git revision like 4fffe6e7) or
|
|
|
|
-- a release heading (first word is a release version & tag
|
2020-12-16 00:30:21 +03:00
|
|
|
-- like 1.18.1, second word is a date like 2020-06-21) or a
|
|
|
|
-- package release heading (hledger-ui-1.18.1).
|
2020-09-06 04:01:47 +03:00
|
|
|
--
|
|
|
|
-- - the package version, in the adjacent .version file, which
|
|
|
|
-- can be a dev version like 1.18.99 (first two digits of last
|
|
|
|
-- part are 97, 98 or 99) or a release version like 1.18.1
|
|
|
|
-- (any other cabal-style version).
|
|
|
|
--
|
|
|
|
-- The old changelog heading is removed if it was a dev heading;
|
|
|
|
-- new commits in PKG not prefixed with semicolon are added;
|
2020-12-15 21:15:06 +03:00
|
|
|
-- and a suitable new heading is added: a release heading if
|
|
|
|
-- the package version looks like a release version, otherwise
|
|
|
|
-- a dev heading with the current HEAD revision.
|
2020-09-06 04:01:47 +03:00
|
|
|
--
|
2020-12-16 00:04:36 +03:00
|
|
|
-- With -n/--dry-run, print new content to stdout instead of
|
2020-09-07 20:22:56 +03:00
|
|
|
-- updating the changelog.
|
2020-09-06 04:01:47 +03:00
|
|
|
--
|
2021-08-16 08:21:49 +03:00
|
|
|
phonys (\out -> if out `notElem` changelogs
|
|
|
|
then Nothing
|
|
|
|
else Just $ do
|
2020-12-16 00:30:21 +03:00
|
|
|
tags <- lines . fromStdout <$> (cmd Shell "git tag" :: Action (Stdout String))
|
2020-09-06 04:01:47 +03:00
|
|
|
oldlines <- liftIO $ lines <$> readFileStrictly out
|
|
|
|
let
|
2020-12-16 00:30:21 +03:00
|
|
|
dir = takeDirectory out
|
|
|
|
mpkg | dir=="." = Nothing
|
|
|
|
| otherwise = Just dir
|
2020-09-06 04:01:47 +03:00
|
|
|
(preamble, oldheading:rest) = span isnotheading oldlines
|
|
|
|
where isnotheading = not . ("#" `isPrefixOf`)
|
2020-12-16 00:30:21 +03:00
|
|
|
-- changelog version: a hash or the last release version of this package (or the project)
|
2020-09-06 04:01:47 +03:00
|
|
|
changelogversion = headDef err $ drop 1 $ words oldheading
|
|
|
|
where err = error $ "could not parse changelog heading: "++oldheading
|
2020-12-16 00:30:21 +03:00
|
|
|
-- prepend the package name if we are in a package (not the top-level project directory)
|
|
|
|
maybePrependPackage s = maybe s (++("-"++s)) mpkg
|
|
|
|
toTag = maybePrependPackage
|
|
|
|
isOldRelease rev = isReleaseVersion rev && toTag rev `elem` tags
|
2021-08-16 07:09:17 +03:00
|
|
|
isNewRelease rev = isReleaseVersion rev && toTag rev `notElem` tags
|
2020-12-16 00:30:21 +03:00
|
|
|
-- git revision corresponding to the changelog version:
|
|
|
|
-- a hash (a3f19c15), package release tag (hledger-ui-1.20), or project release tag (1.20)
|
|
|
|
lastrev
|
|
|
|
| isOldRelease changelogversion = toTag changelogversion -- package release tag
|
2020-12-24 01:56:57 +03:00
|
|
|
| isNewRelease changelogversion =
|
|
|
|
trace (out ++ "'s version \""++changelogversion++"\" is not yet tagged, can't list changes")
|
|
|
|
"HEAD"
|
2020-12-16 00:30:21 +03:00
|
|
|
| otherwise = changelogversion
|
|
|
|
|
|
|
|
-- interesting commit messages between lastrev and HEAD, cleaned up
|
|
|
|
let
|
|
|
|
interestingpaths = fromMaybe projectChangelogExcludeDirs mpkg
|
2021-07-21 11:39:46 +03:00
|
|
|
-- interestingmessages = "--invert-grep --grep '^;'" -- ignore commits beginning with ;
|
|
|
|
-- TODO: update for new commit conventions. ; now means skip CI,
|
|
|
|
-- feat:/imp:/fix: means release notes, pkg:/lib: means changelogs, etc.
|
|
|
|
interestingmessages = ""
|
2020-12-16 00:30:21 +03:00
|
|
|
newitems <- fromStdout <$>
|
|
|
|
(cmd Shell gitlog changelogGitFormat (lastrev++"..") interestingmessages "--" interestingpaths
|
|
|
|
"|" changelogCleanupCmd :: Action (Stdout String))
|
2020-09-06 04:01:47 +03:00
|
|
|
|
2020-12-16 00:30:21 +03:00
|
|
|
-- git revision of current HEAD
|
|
|
|
headrev <- unwords . words . fromStdout <$>
|
|
|
|
(cmd Shell gitlog "-1 --pretty=%h -- " interestingpaths :: Action (Stdout String))
|
|
|
|
-- package version: the version number currently configured for this package (or the project)
|
2020-09-06 04:01:47 +03:00
|
|
|
packageversion <-
|
|
|
|
let versionfile = dir </> ".version"
|
|
|
|
err = error $ "could not parse a version in "++versionfile
|
2020-12-16 00:30:21 +03:00
|
|
|
in liftIO $ headDef err . words <$> readFileStrictly versionfile
|
2020-09-06 04:01:47 +03:00
|
|
|
date <- liftIO getCurrentDay
|
2020-09-05 02:24:42 +03:00
|
|
|
let
|
2020-12-16 00:30:21 +03:00
|
|
|
-- the new changelog heading will be a final (dated, versioned) heading if
|
|
|
|
-- the configured package version is a new release version (non-dev & non-tagged)
|
2020-09-06 04:01:47 +03:00
|
|
|
(newrev, newheading)
|
2020-12-16 00:30:21 +03:00
|
|
|
| isNewRelease packageversion = (toTag packageversion, unwords [packageversion, show date])
|
|
|
|
| otherwise = (headrev, headrev)
|
2020-12-24 01:45:53 +03:00
|
|
|
newcontent = "# "++newheading++"\n" ++ newitems
|
|
|
|
newchangelog =
|
|
|
|
unlines preamble
|
|
|
|
++ newcontent
|
|
|
|
++ (if isCommitHash changelogversion then "" else oldheading)
|
|
|
|
++ unlines rest
|
2020-09-06 04:01:47 +03:00
|
|
|
|
|
|
|
liftIO $ if
|
2020-09-07 20:31:16 +03:00
|
|
|
| lastrev == newrev -> pure () -- putStrLn $ out ++ ": up to date"
|
2020-09-06 04:01:47 +03:00
|
|
|
| dryrun -> putStr $ out ++ ":\n" ++ newcontent
|
|
|
|
| otherwise -> do
|
|
|
|
writeFile out newchangelog
|
|
|
|
putStrLn $ out ++ ": updated to " ++ newrev
|
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
)
|
|
|
|
|
2020-12-15 23:38:57 +03:00
|
|
|
-- Update all program-specific docs, eg after setversion.
|
|
|
|
phony "docs" $ need [
|
|
|
|
"cmdhelp"
|
2020-09-07 20:31:16 +03:00
|
|
|
,"manuals"
|
|
|
|
,"changelogs"
|
|
|
|
]
|
|
|
|
|
2021-09-19 19:59:51 +03:00
|
|
|
-- Update (render) the website, which should be checked out as ./site
|
|
|
|
phony "site" $ do
|
|
|
|
need [
|
|
|
|
"webmanuals"
|
2021-09-19 21:04:38 +03:00
|
|
|
,"orgfiles"
|
2021-09-19 19:59:51 +03:00
|
|
|
]
|
|
|
|
cmd_ "make -C site build"
|
|
|
|
|
2021-09-19 21:04:38 +03:00
|
|
|
phony "orgfiles" $
|
|
|
|
need [
|
2023-04-13 19:44:06 +03:00
|
|
|
-- "doc/BACKLOG.md"
|
2021-09-19 21:04:38 +03:00
|
|
|
]
|
|
|
|
|
2021-09-19 20:30:44 +03:00
|
|
|
-- These org files are converted to markdown for the website.
|
2023-04-13 19:44:06 +03:00
|
|
|
[ -- "doc/BACKLOG.md"
|
2021-09-19 20:30:44 +03:00
|
|
|
] |%> \out -> do
|
2022-12-04 22:22:05 +03:00
|
|
|
let src = out -<.> "org"
|
2021-09-19 21:04:38 +03:00
|
|
|
need [src]
|
2021-09-28 00:49:25 +03:00
|
|
|
-- replace the generated top heading with our own so we can insert the TOC after it
|
2022-12-04 22:22:05 +03:00
|
|
|
let heading = dropExtension out
|
2021-09-28 00:49:25 +03:00
|
|
|
mdlines <- drop 1 . lines . fromStdout <$> (cmd Shell pandoc fromorg towebmd src :: Action (Stdout String))
|
|
|
|
liftIO $ writeFile out $ unlines $ [
|
2021-09-19 19:58:16 +03:00
|
|
|
"<!-- " ++ "Generated by \"Shake " ++ out ++ " from " ++ src ++ " -->"
|
2021-09-28 00:49:25 +03:00
|
|
|
,""
|
|
|
|
,"# " ++ heading
|
|
|
|
,""
|
2021-09-19 19:58:16 +03:00
|
|
|
,"<div class=\"pagetoc\">"
|
2022-06-20 15:00:02 +03:00
|
|
|
,""
|
2021-09-19 19:58:16 +03:00
|
|
|
,"<!-- toc -->"
|
|
|
|
,"</div>"
|
|
|
|
,""
|
2021-09-28 00:49:25 +03:00
|
|
|
] ++ mdlines
|
|
|
|
|
|
|
|
-- XXX try to style backlog items as unnumbered or nested-numbered list items
|
|
|
|
{-
|
|
|
|
<style>
|
|
|
|
main>ol {
|
|
|
|
list-style: none;
|
|
|
|
padding-inline-start: 1em;
|
|
|
|
counter-reset: item;
|
|
|
|
}
|
|
|
|
/* XXX when there are subitems, pandoc wraps all in a <p>,
|
|
|
|
* which forces a line break after the :before text
|
|
|
|
*/
|
|
|
|
main>ol>li:before {
|
|
|
|
content: counters(item, ".") ". ";
|
|
|
|
counter-increment: item;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
main>ol>li {
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
-}
|
2021-09-19 19:58:16 +03:00
|
|
|
|
2020-12-15 23:38:57 +03:00
|
|
|
-- MISC
|
|
|
|
|
2020-09-05 02:24:42 +03:00
|
|
|
-- Generate the web manuals based on the current checkout and save
|
|
|
|
-- them as the specified versioned snapshot in site/doc/VER/ .
|
|
|
|
-- .snapshot is a dummy file.
|
|
|
|
-- "site/doc/*/.snapshot" %> \out -> do
|
|
|
|
-- need webmanuals
|
|
|
|
-- let snapshot = takeDirectory out
|
|
|
|
-- cmd_ Shell "mkdir -p" snapshot
|
|
|
|
-- forM_ webmanuals $ \f -> -- site/hledger.md, site/journal.md
|
|
|
|
-- cmd_ Shell "cp" f (snapshot </> takeFileName f)
|
|
|
|
-- cmd_ Shell "cp -r site/images" snapshot
|
|
|
|
-- cmd_ Shell "touch" out
|
2020-09-06 04:21:09 +03:00
|
|
|
-- Help:
|
|
|
|
-- ,"./Shake site/doc/VERSION/.snapshot save current web manuals as this snapshot"
|
2020-09-05 02:24:42 +03:00
|
|
|
|
|
|
|
-- Cleanup.
|
|
|
|
|
|
|
|
phony "clean" $ do
|
|
|
|
putNormal "Cleaning object files in tools"
|
|
|
|
removeFilesAfter "tools" ["*.o","*.p_o","*.hi"]
|
|
|
|
|
|
|
|
phony "Clean" $ do
|
|
|
|
need ["clean"]
|
|
|
|
putNormal "Cleaning shake build cache"
|
|
|
|
removeFilesAfter ".shake" ["//*"]
|
|
|
|
|
2023-06-15 11:41:47 +03:00
|
|
|
-- Git commit the given files with the given message if they have changes,
|
|
|
|
-- otherwise print a no change message and continue.
|
|
|
|
commitIfChanged msg files = do
|
|
|
|
diffs <- (/=ExitSuccess) . fromExit <$> cmd Shell "git diff --no-ext-diff --quiet --exit-code --" files
|
|
|
|
if diffs
|
|
|
|
then cmd Shell ("git commit -m '"++msg++"' --") files
|
|
|
|
else liftIO $ putStrLn $ "nothing to commit (\"" ++ msg ++ "\")"
|
2019-01-20 00:14:33 +03:00
|
|
|
|
2019-01-20 01:49:20 +03:00
|
|
|
-- Convert numbered man page names to manual names.
|
|
|
|
-- hledger.1 -> hledger, hledger_journal.5 -> hledger_journal
|
|
|
|
manpageNameToManualName = dropNumericSuffix
|
|
|
|
where
|
|
|
|
dropNumericSuffix s = reverse $
|
|
|
|
case reverse s of
|
|
|
|
c : '.' : cs | isDigit c -> cs
|
|
|
|
cs -> cs
|
|
|
|
|
|
|
|
-- Convert manual names to numbered man page names.
|
|
|
|
-- hledger -> hledger.1, hledger_journal -> hledger_journal.5
|
|
|
|
manualNameToManpageName s
|
|
|
|
| '_' `elem` s = s <.> "5"
|
|
|
|
| otherwise = s <.> "1"
|
|
|
|
|
2019-01-20 00:14:33 +03:00
|
|
|
dropDirectory2 = dropDirectory1 . dropDirectory1
|
|
|
|
|
2019-02-01 04:36:52 +03:00
|
|
|
readFileStrictly :: FilePath -> IO String
|
|
|
|
readFileStrictly f = readFile f >>= \s -> C.evaluate (length s) >> return s
|
|
|
|
|
2020-12-15 21:15:06 +03:00
|
|
|
-- Write new content to a file, only if it's different.
|
|
|
|
maybeWriteFile :: FilePath -> String -> IO ()
|
|
|
|
maybeWriteFile f new = do
|
|
|
|
old <- readFileStrictly f
|
|
|
|
when (old /= new) $ writeFile f new
|
|
|
|
|
2019-02-05 18:31:06 +03:00
|
|
|
-- | Get the current local date.
|
|
|
|
getCurrentDay :: IO Day
|
2021-08-16 07:49:40 +03:00
|
|
|
getCurrentDay = localDay . zonedTimeToLocalTime <$> getZonedTime
|
2019-02-08 22:32:37 +03:00
|
|
|
|
2020-03-19 01:40:39 +03:00
|
|
|
-- | Replace each occurrence of a regular expression by this string.
|
|
|
|
replaceRe :: RE -> String -> String -> String
|
|
|
|
replaceRe re repl = replaceBy re (\_ _ _ -> Just repl)
|
|
|
|
|
|
|
|
-- | Replace each occurrence of a regular expression, by transforming
|
|
|
|
-- each matched text with the given function.
|
|
|
|
replaceBy :: RE -> (Match String -> RELocation -> Capture String -> Maybe String) -> String -> String
|
2019-02-08 22:32:37 +03:00
|
|
|
replaceBy re f src = replaceAllCaptures TOP f $ src *=~ re
|
2020-09-05 03:57:40 +03:00
|
|
|
|
|
|
|
-- | Does this string look like a valid cabal package version ?
|
2021-08-03 22:51:15 +03:00
|
|
|
isVersion s = not (null s) && all (`elem` "0123456789.") s && '.' `elem` s
|
2020-09-06 04:01:47 +03:00
|
|
|
|
|
|
|
-- | Does this string look like a hledger development version ?
|
|
|
|
-- Ie a version where the first two digits of the last part are the
|
|
|
|
-- special values 97, 98 or 99, indicating alpha/beta/rc or whatever.
|
|
|
|
isDevVersion s = isVersion s && lastpart >= "97"
|
|
|
|
where lastpart = lastDef "" $ splitOn "." s
|
|
|
|
|
|
|
|
-- | Does this string look like a hledger release version ?
|
|
|
|
-- Ie a cabal package version that's not a hledger development version.
|
|
|
|
isReleaseVersion s = isVersion s && not (isDevVersion s)
|
|
|
|
|
|
|
|
-- | Does this string look like a git commit hash ?
|
|
|
|
-- Ie a sequence of 7 or more numbers or letters.
|
|
|
|
isCommitHash s = length s > 6 && all isAlphaNum s
|
2021-03-18 17:21:51 +03:00
|
|
|
|
|
|
|
-- | Remove all trailing newlines/carriage returns.
|
|
|
|
chomp :: String -> String
|
|
|
|
chomp = reverse . dropWhile (`elem` "\r\n") . reverse
|
|
|
|
|