aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbin/build-all.sh14
-rwxr-xr-xbin/version-string.sh58
-rwxr-xr-xmake4
3 files changed, 63 insertions, 13 deletions
diff --git a/bin/build-all.sh b/bin/build-all.sh
index f239217..f2420a7 100755
--- a/bin/build-all.sh
+++ b/bin/build-all.sh
@@ -80,19 +80,7 @@ function make-version-h {
# old: version = build date
#date '+#define VERSION_NUMBER "%Y-%m-%d"' > ui/$UI/version.h
- # version = git tag + revs since + dirty flag
- REV=$(git describe --tags --dirty --abbrev=8 --match='r2*')
- # reformatting this would be easier with a perl one-liner,
- # but I'm trying to avoid extra build dependencies
- REV="${REV:1}" # strip the leading 'r'
- # strip rev hash (git won't give "commits since tag" without the rev hash)
- REV="${REV/-g[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]/}"
- REV="${REV/-dirty/.1}" # convert '-dirty' to '.1'
- # handle an empty name (happens during github action runs)
- if [[ -z "$REV" ]]; then
- HASH=$(git describe --always)
- REV="0.$HASH"
- fi
+ REV=$(bin/version-string.sh c)
# save the version name to version.h
mkdir -p ".build/$UI"
echo '#define VERSION_NUMBER "'"$REV"'"' > ".build/$UI/version.h"
diff --git a/bin/version-string.sh b/bin/version-string.sh
new file mode 100755
index 0000000..c1c5155
--- /dev/null
+++ b/bin/version-string.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+# Print a version string for the currently-checked-out code.
+# Copyright (C) 2023 Selene ToyKeeper
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Usage: version-string.sh [c|git|both]
+# Prints in C or Git format. Defaults to both.
+
+function main {
+ # eat first arg if invoked via 'make'
+ [[ "version" = "$1" ]] && shift
+
+ # default to showing both formats
+ ARGS="$*"
+ [[ -z "$ARGS" ]] && ARGS="both"
+
+ for arg in $ARGS ; do
+ case "$arg" in
+ git|g)
+ git-describe
+ ;;
+ c|C)
+ c-version-string
+ ;;
+ *)
+ echo -n 'C: ' ; c-version-string
+ echo -n 'git: ' ; git-describe
+ ;;
+ esac
+ done
+}
+
+function git-describe {
+ git describe --tags --dirty --match='r2*'
+}
+
+function c-version-string {
+ # version = git tag + revs since + dirty flag
+ REV=$(git-describe)
+ # convert "r2020-01-01-158-g0abcdef-dirty" to "2020-01-01+158#1"
+ REV=$(echo "$REV" |
+ sed -E 's/^r//;
+ s/-dirty/#1/;
+ s/-g[0-9a-f]+//;
+ s/^([0-9]{4}-[0-9]{2}-[0-9]{2})-/\1+/;
+ '
+ )
+ # handle an empty name (can happen during github action runs)
+ if [[ -z "$REV" ]]; then
+ HASH=$(git describe --always)
+ REV="0.$HASH"
+ fi
+ # print the version string
+ echo "$REV"
+}
+
+main "$@"
+
diff --git a/make b/make
index d34a4b8..ca3a84a 100755
--- a/make
+++ b/make
@@ -27,6 +27,7 @@ Usage: ./make TASK
docs Convert all .md files to .html
models Generate the MODELS file
release Zip up all .hex files to prep for publishing a release
+ version Show the current version string
todo Show tasks noted in source code files
... or TASK can be the partial name of a build target.
@@ -75,6 +76,9 @@ function main() {
release)
./bin/make-release.sh "$@"
;;
+ version)
+ ./bin/version-string.sh "$@"
+ ;;
todo)
grep -E 'TODO:|FIXME:' -- **/*.[ch] **/*.md
;;
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.