firmware/build_patches/openwrt/0021-rules-add-AUTORELEASE-and-COMMITCOUNT-variables.patch

83 lines
2.7 KiB
Diff
Raw Normal View History

treewide: set PKG_RELEASE automatically Backport support for COMMITCOUNT and AUTORELEASE from OpenWrt. COMMITCOUNT allows to have the PKG_RELEASE calculated automatically based on the number of commits for the package folder. AUTORELEASE will count the number of commits since the last upstream bump. This is relevant for packages with PKG_VERSION or PKG_SOURCE_DATE set, but will not work for us since it assumes the use of certain identifiers in commit titles. COMMITCOUNT works fine for most of our packages, with the following exceptions: * fff-nodewatcher would yield a commit count of 55, while the current PKG_RELEASE is 61. Thus, we do not touch it for now. * Packages that have been renamed will start counting from 1 after the rename, since folder renames are not tracked by git. This will result in descreasing PKG_RELEASE after the change for these packages. However, since moving essentially creates a new package anyway, counting from 1 makes sense conceptually, and PKG_RELEASE is still replaced for these packages. * alfred-json and fff-macnock use upstream code and thus would normally require AUTORELEASE. As discussed above, this will not work for us, so just leave these two untouched. Note that all this is quite irrelevant for the way we use packages currently, as without opkg PKG_RELEASE does not matter to us anyway. So, let's just be happy about not having to bump PKG_RELEASE anymore, while keeping the basic functionality intact. The only package where the PKG_RELEASE is actually used for something is fff-nodewatcher, where the version will be displayed in the Monitoring. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2021-02-26 21:42:00 +01:00
From: Paul Spooren <mail@aparcar.org>
Date: Fri, 1 Jan 2021 14:02:12 -1000
Subject: rules: add AUTORELEASE and COMMITCOUNT variables
The lack of bumped PKG_RELEASE variables is a recurring theme on the
mailing list and in GitHub comments. This costs precious review time,
a rare good within the OpenWrt project.
Instead of relying on a manually set PKG_RELEASE this commit adds a
`commitcount` function that uses the number of Git commits to determine
the release. The function is called via the variables `$(AUTORELEASE)`
or `$(COMMITCOUNT)`. The `PKG_RELEASE` variable can be set to either of
the two.
- $(AUTORELEASE):
Release is automagically set to the number of commits since the last
commit containing either ": update to " or ": bump to ".
Example below:
$ git log packages/foobar/
foobar: fixup file location
foobar: disable docs
foobar: bump to 5.3.2
foobar: fixup copyright
Resulting package name: foobar_5.3.2-3_all.ipk, two package changes
since the last upstream version change, using a 1 based counter.
- $(COMMITCOUNT):
For non-traditional versioning (x.y.z), most prominent `base-files`,
this variable contains the total number of package commits.
The new functionality can also be used by other feeds like packages.git.
In case no build information is available, e.g. when using release
tarballs, the SOURCE_DATE_EPOCH is used to have a reproducible release
identifier.
Suggested-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Paul Spooren <mail@aparcar.org>
(cherry picked from commit 9ae3c6f94c616cfbf854d3ec749c7fafc9893942)
diff --git a/rules.mk b/rules.mk
index 41ed9bafd01b458a1ff3bf7b7b43cc6c48cca845..7c1f39ccf4023601a7647f4eaf648b6392f480b9 100644
--- a/rules.mk
+++ b/rules.mk
@@ -404,6 +404,32 @@ endef
# file extension
ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
+# Count Git commits of a package
+# $(1) => if non-empty: count commits since last ": [uU]pdate to " or ": [bB]ump to " in commit message
+define commitcount
+$(shell \
+ if git log -1 >/dev/null 2>/dev/null; then \
+ if [ -n "$(1)" ]; then \
+ last_bump="$$(git log --pretty=format:'%h %s' . | \
+ grep --max-count=1 -e ': [uU]pdate to ' -e ': [bB]ump to ' | \
+ cut -f 1 -d ' ')"; \
+ fi; \
+ if [ -n "$$last_bump" ]; then \
+ echo -n $$(($$(git rev-list --count "$$last_bump..HEAD" .) + 1)); \
+ else \
+ echo -n $$(($$(git rev-list --count HEAD .) + 1)); \
+ fi; \
+ else \
+ secs="$$(($(SOURCE_DATE_EPOCH) % 86400))"; \
+ date="$$(date --utc --date="@$(SOURCE_DATE_EPOCH)" "+%y%m%d")"; \
+ printf '%s.%05d' "$$date" "$$secs"; \
+ fi; \
+)
+endef
+
+COMMITCOUNT = $(if $(DUMP),,$(call commitcount))
+AUTORELEASE = $(if $(DUMP),,$(call commitcount,1))
+
all:
FORCE: ;
.PHONY: FORCE