[PATCH v3 1/3] rules: add commitcount function

Paul Spooren mail at aparcar.org
Sun Jan 10 04:23:59 EST 2021


`commitcount` returns the number of commits affecting the current
folder. The newly added function can be used for packages that do not
follow a traditional versioning schema, most prominent `base-files`
which requires tedious `PKG_RELEASE` bumps.

Below a naming example:

	base-files_1399-r15385+75-c5d033a34d_x86_64.ipk

In cases where no Git system is used, the timestamp of SOURCE_DATE_EPOCH
is used instead, allowing reproducible builds.

	base-files_210107.30634-r1538581-c5d033a34d_x86_64.ipk

Signed-off-by: Paul Spooren <mail at aparcar.org>
---
v2:
- reproducible versions via SOURCE_DATE_EPOCH
- wrap function in ifndef DUMP
v3:
- don't use tabs in `commitcount` to remove stripping in VERSION:=
  definition

 rules.mk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/rules.mk b/rules.mk
index f79340b124..ac406983b9 100644
--- a/rules.mk
+++ b/rules.mk
@@ -408,6 +408,24 @@ endef
 # file extension
 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
 
+ifndef DUMP
+define commitcount
+$(shell \
+  if git log -1 >/dev/null 2>/dev/null; then \
+    printf '%s' $$(git rev-list --count HEAD .); \
+  else \
+    secs="$$(($(SOURCE_DATE_EPOCH) % 86400))"; \
+    date="$$(date --utc --date="@$(SOURCE_DATE_EPOCH)" "+%y%m%d")"; \
+    printf '%s.%05d' "$$date" "$$secs"; \
+  fi \
+)
+endef
+else
+define commitcount
+1
+endef
+endif
+
 all:
 FORCE: ;
 .PHONY: FORCE
-- 
2.29.2




More information about the openwrt-devel mailing list