[PATCH v2 1/4] rules: add AUTORELEASE and COMMITCOUNT variables
Paul Spooren
mail at aparcar.org
Tue Jan 19 17:20:32 EST 2021
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`, it
is possible to pass an argument to get the total number of commits.
The new functionality can also be used by other feeds like packages.git.
Suggested-by: Daniel Golle <daniel at makrotopia.org>
Signed-off-by: Paul Spooren <mail at aparcar.org>
---
v2: The initial version would use `git log --grep` which also scans
through the commit message, not only the commit subject. That can cause
problems in cases where other commit are referenced in commit messages
and overall slows the down the execution. Instead pipe output to grep.
rules.mk | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/rules.mk b/rules.mk
index f79340b124..6d3c98b8f6 100644
--- a/rules.mk
+++ b/rules.mk
@@ -408,6 +408,32 @@ endef
# file extension
ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
+# Count Git commits of a package
+# $(1) => if non-empty count commits since "update" or "bump" to determine package release
+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
--
2.29.2
More information about the openwrt-devel
mailing list