tools: move setversion to shake, use PKG/.version, set upper bounds

./Shake setversion will now propagate the version number in each
package's .version file, to all the places in that package where it's
needed (ie the defs.m4 file and multiple places in the package.yaml
file. Also it now updates upper bounds on other hledger packages
to the next major version. (The new lower/upper bounds may not always
be what's desired, manual review required.)

[ci skip]
This commit is contained in:
Simon Michael 2019-02-04 18:47:27 -08:00
parent bde46f7bd0
commit 18ffa65168
7 changed files with 98 additions and 41 deletions

View File

@ -162,19 +162,12 @@ DOCSOURCEFILES:= \
$(MANUALSOURCEFILES) \
$(COMMANDHELPFILES) \
# files which should be updated when the version changes
VERSIONSENSITIVEFILES=\
$(HPACKFILES) \
doc/common.m4 \
# # file(s) which require recompilation for a build to have an up-to-date version string
# VERSIONSOURCEFILE=hledger/Hledger/Cli/Version.hs
# master file defining the current release/build version
VERSIONFILE=.version
# two or three-part version string, whatever's in VERSION
VERSION=$(shell cat $(VERSIONFILE))
# Two or three-part version string, set as program version in builds made by this makefile.
# We use hledger CLI's current version (XXX for all packages, which isn't quite right).
VERSION=$(shell cat hledger/.version)
# the number of commits since the last tag
PATCHLEVEL=$(shell git describe --tags --match 'hledger-[0-9]*' --long | awk -F- '{print $$3}')
@ -721,32 +714,6 @@ setdate: $(call def-help,setdate, set date in manuals to current month and year
updatedate: setdate $(call def-help,updatedate, set date in manuals to current month and year and commit )
git commit -m "bump manual date to $(MONTHYEAR)" doc/common.m4
# Updating version numbers. See VERSIONSENSITIVEFILES etc. defined
# above, and CONTRIBUTING.md > Version numbers.
showversions:
@grep 'version *:' */package.yaml
# updateversion: setdate setversion $(call def-help,updateversion, update manual date and update version strings & (lower) bounds from $(VERSIONFILE) and commit )
# @read -p "please review changes then press enter to commit $(VERSIONFILE) $(VERSIONSENSITIVEFILES)"
# git commit -m "bump version strings & bounds to $(VERSION)" $(VERSIONFILE) $(VERSIONSENSITIVEFILES)
setversion: $(VERSIONSENSITIVEFILES) #$(call def-help,setversion, update version strings & bounds from $(VERSIONFILE) (might need -B) )
@echo "if this is a new major version, please manually update upper bounds in */package.yaml before generating cabal files"
# update a package yaml file's version, -DVERSION, and hledger lower bounds (upper bounds must be changed manually)
%/package.yaml: $(VERSIONFILE)
perl -pe "s/(^version *: *).*/\$${1}'$(VERSION)'/" -i $@ # version: 'A'
perl -pe "s/(-DVERSION=\")[^\"]+/\$${1}$(VERSION)/" -i $@ # -DVERSION="A"
perl -pe "s/(hledger(-\w+)?) *== *((\d+\.)*\d+) *$$/\$$1 ==$(VERSION)/" -i $@ # hledgerX == A
perl -pe "s/(hledger(-\w+)?) *>=? *((\d+\.)*\d+) *$$/\$$1 >=$(VERSION)/" -i $@ # hledgerX >= A
perl -pe "s/(hledger(-\w+)?) *>=? *((\d+\.)*\d+) *&& *< *((\d+\.)*\d+) *$$/\$$1 >=$(VERSION) && <\$$5/" -i $@ # hledgerX >= A && < B
# update version string used in generated docs
doc/common.m4: $(VERSIONFILE)
perl -pe "s/^(m4_define\({{_version_}}, *{{)((\d+\.)*\d+)(}}\)m4_dnl *)$$/\$${1}$(VERSION)\$${4}/" -i $@
@echo "please manually check/update _docversionlinks_ in doc/common.m4"
# (re)generate a cabal file from its package.yaml definition
# XXX to avoid warnings, this hpack should be the same version as stack's built-in hpack
#%.cabal: $$(dir $$@)package.yaml
@ -775,10 +742,6 @@ updateembeddeddocs: genmanuals gencommandhelp $(call def-help,updatemanuals, reg
git commit -m "update embedded docs" hledger*/hledger*.{1,5,info,txt} hledger/Hledger/Cli/Commands/*.txt
tagrelease: \
$(call def-help,tagrelease, commit a release tag based on $(VERSIONFILE) for each package )
for p in $(PACKAGES); do git tag -f $$p-$(VERSION); done
# hackageupload-dry: \
# $(call def-help,hackageupload-dry,\
# upload all packages to hackage; dry run\

View File

@ -24,6 +24,7 @@ auto-installs the packages above. Also, some rules require:
- m4
- makeinfo
- pandoc
- sed
Usage: see below. Also:
@ -68,6 +69,7 @@ usage = unlines
,"./Shake all build all the above"
,""
,"./Shake FILE build any individual file"
,"./Shake setversion update all packages from PKG/.version"
,"./Shake changelogs update the changelogs with any new commits"
,"./Shake [PKG/]CHANGES.md[-dry] update or preview this changelog"
,"./Shake site/doc/VERSION/.snapshot save current web manuals as this snapshot"
@ -83,6 +85,7 @@ usage = unlines
groff = "groff"
makeinfo = "makeinfo"
pandoc = "pandoc"
sed = "sed -E" -- assume only the features of BSD sed
-- The kind of markdown used in our doc source files.
fromsrcmd = "-f markdown-smart-tex_math_dollars"
@ -400,7 +403,7 @@ main = do
-- Format a git log message, with one of the formats above, as a changelog item
changelogCleanupCmd = unwords [
"sed -E"
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"
@ -471,6 +474,90 @@ main = do
else writeFile out newfile
)
-- VERSION NUMBERS
-- Given the desired version string saved in PKG/.version, update
-- it everywhere needed in the package. See also CONTRIBUTING.md >
-- Version numbers.
let inAllPackages f = map (</> f) packages
phony "setversion" $ need $
inAllPackages "defs.m4"
++ inAllPackages "package.yaml"
-- PKG/defs.m4 <- PKG/.version
"hledger*/defs.m4" %> \out -> do
let versionfile = takeDirectory out </> ".version"
need [versionfile]
version <- ((head . words) <$>) $ liftIO $ readFile versionfile
cmd_ Shell sed "-i -e" ("'s/(_version_}}, *){{[^}]+/\\1{{"++version++"/'") out
-- PKG/package.yaml <- PKG/.version
"hledger*/package.yaml" %> \out -> do
let versionfile = takeDirectory out </> ".version"
need [versionfile]
version <- ((head . words) <$>) $ liftIO $ readFile versionfile
let ma:jor:_ = splitOn "." version
nextmajorversion = intercalate "." $ ma : (show $ read jor+1) : []
-- 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
-- tagrelease: \
-- $(call def-help,tagrelease, commit a release tag based on $(VERSIONFILE) for each package )
-- for p in $(PACKAGES); do git tag -f $$p-$(VERSION); done
-- MISC
-- Generate the web manuals based on the current checkout and save
@ -486,6 +573,8 @@ main = do
cmd Shell "cp -r site/images" snapshot :: Action ExitCode
cmd Shell "touch" out -- :: Action ExitCode
-- Cleanup.
phony "clean" $ do
putNormal "Cleaning generated help texts, manuals, staged site content"
removeFilesAfter "." commandtxts

1
hledger-api/.version Normal file
View File

@ -0,0 +1 @@
1.13

1
hledger-lib/.version Normal file
View File

@ -0,0 +1 @@
1.13.1

1
hledger-ui/.version Normal file
View File

@ -0,0 +1 @@
1.13

1
hledger-web/.version Normal file
View File

@ -0,0 +1 @@
1.13

1
hledger/.version Normal file
View File

@ -0,0 +1 @@
1.13.2