[PATCH 1/2] rules: add findrev function from LuCI

Paul Spooren mail at aparcar.org
Fri Jan 1 19:22:12 EST 2021


`findrev` can be used to automatically determine the revision of a
package by checking the latest Git commit of a package folder. In case
not Git informtion is available the folder timestamp is used.

This function is migrated from `luci.git` where it is used for all
package versions. As openwrt.git does not contain any PO files, the
special case for PO files is inverted, not requiring an extra parameter
per default.

The newly added function can be used for packages that do not follow a
traditional versioning schema, most prominent case `base-files` which
requires tedious `PKG_RELEASE` bumps.

Below a naming example:

	base-files_21.001.85028-0f68971_x86_64.ipk

The `luci.mk` implementation prefixes the version with `git-` which was
removed as the information is redundant to the attached `revision` behind
the timestamp. The `revision` is missing if no Git information was found.

CC: Jo-Philipp Wich <jo at mein.io>

Signed-off-by: Paul Spooren <mail at aparcar.org>
---
 rules.mk | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/rules.mk b/rules.mk
index f79340b124..dcefd92761 100644
--- a/rules.mk
+++ b/rules.mk
@@ -408,6 +408,30 @@ endef
 # file extension
 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
 
+define findrev
+	$(shell \
+		if git log -1 >/dev/null 2>/dev/null; then \
+			set -- $$(git log -1 --format="%ct %h" --abbrev=7 -- $(if $(1),po,. ':(exclude)po')); \
+			if [ -n "$$1" ]; then
+				secs="$$(($$1 % 86400))"; \
+				yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
+				printf '%s.%05d-%s' "$$yday" "$$secs" "$$2"; \
+			else \
+				echo "unknown"; \
+			fi; \
+		else \
+			ts=$$(find . -type f $(if $(1),,-not) -path './po/*' -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \
+			if [ -n "$$ts" ]; then \
+				secs="$$(($$ts % 86400))"; \
+				date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \
+				printf '%s.%05d' "$$date" "$$secs"; \
+			else \
+				echo "unknown"; \
+			fi; \
+		fi \
+	)
+endef
+
 all:
 FORCE: ;
 .PHONY: FORCE
-- 
2.29.2




More information about the openwrt-devel mailing list