From 2dc1d19e67e2ad1606470bb14ca44e9f8c684d2b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 30 Nov 2023 17:45:46 -0700 Subject: changed version number to use the latest release tag instead of build date Before: 2023-11-30 (build date) After: 2023-10-31-98.1 (latest release tag + number of commits since + dirty flag) --- bin/build-all.sh | 20 ++++++++++++++++---- bin/build.sh | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/build-all.sh b/bin/build-all.sh index df72ad5..27209ca 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -21,9 +21,21 @@ UI=anduril mkdir -p hex -# TODO: use a git tag for the version, instead of build date -# TODO: use build/version.h instead of $UI/version.h ? -date '+#define VERSION_NUMBER "%Y-%m-%d"' > ui/$UI/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' +# save the version name to version.h +mkdir -p ".build/$UI" +echo '#define VERSION_NUMBER "'"$REV"'"' > ".build/$UI/version.h" + PASS=0 FAIL=0 @@ -48,7 +60,7 @@ for TARGET in hw/*/*/**/"$UI".h ; do if [ 1 = $SKIP ]; then continue ; fi # announce what we're going to build - echo "===== $UI : $NAME =====" + echo "===== $UI $REV : $NAME =====" # try to compile, track result, and rename compiled files if bin/build.sh "$TARGET" ; then diff --git a/bin/build.sh b/bin/build.sh index 9b4b0b3..d044ca5 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -49,7 +49,7 @@ export CPP=avr-cpp export OBJCOPY=avr-objcopy export DFPFLAGS="-B $DFPPATH/gcc/dev/$MCUNAME/ -I $DFPPATH/include/" # TODO: include $user/ first so it can override other stuff -INCLUDES="-I ui -I hw -I. -I.. -I../.. -I../../.." +INCLUDES="-I .build -I ui -I hw -I. -I.. -I../.. -I../../.." export CFLAGS=" -Wall -g -Os -mmcu=$MCUNAME -c -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS" export CPPFLAGS="-Wall -g -Os -mmcu=$MCUNAME -C -std=gnu99 -fgnu89-inline -fwhole-program $MCUFLAGS $INCLUDES -fshort-enums $DFPFLAGS" export OFLAGS="-Wall -g -Os -mmcu=$MCUNAME -mrelax $DFPFLAGS" -- cgit v1.2.3 From c01068bc2258a479227851dd6f2bca8d8a806205 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 30 Nov 2023 17:48:24 -0700 Subject: build-all.sh: re-indented, started organizing code into functions (still needs a proper rewrite, but at least the version.h code is in a separate function now) --- bin/build-all.sh | 159 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 75 deletions(-) (limited to 'bin') diff --git a/bin/build-all.sh b/bin/build-all.sh index 27209ca..444809e 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -9,80 +9,89 @@ # enable "**" for recursive glob (requires bash) shopt -s globstar -if [ "$#" -gt 0 ]; then - # multiple search terms with "AND" - SEARCH=( "$@" ) - # memes - [ "$1" = "me" ] && shift && shift && echo "Make your own $*." && exit 1 -fi - -# TODO: detect UI from $0 and/or $* -UI=anduril - -mkdir -p hex - -# 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' -# save the version name to version.h -mkdir -p ".build/$UI" -echo '#define VERSION_NUMBER "'"$REV"'"' > ".build/$UI/version.h" - - -PASS=0 -FAIL=0 -PASSED='' -FAILED='' - -# build targets are hw/$vendor/$model/**/$ui.h -for TARGET in hw/*/*/**/"$UI".h ; do - - # friendly name for this build - NAME=$(echo "$TARGET" | perl -ne 's|/|-|g; /hw-(.*)-'"$UI"'.h/ && print "$1\n";') - - # limit builds to searched patterns, if given - SKIP=0 - if [ ${#SEARCH[@]} -gt 0 ]; then - for text in "${SEARCH[@]}" ; do - if ! echo "$NAME $TARGET" | grep -i -- "$text" > /dev/null ; then - SKIP=1 +function main { + + if [ "$#" -gt 0 ]; then + # multiple search terms with "AND" + SEARCH=( "$@" ) + # memes + [ "$1" = "me" ] && shift && shift && echo "Make your own $*." && exit 1 + fi + + # TODO: detect UI from $0 and/or $* + UI=anduril + + mkdir -p hex + + make-version-h # generate a version.h file + + PASS=0 + FAIL=0 + PASSED='' + FAILED='' + + # build targets are hw/$vendor/$model/**/$ui.h + for TARGET in hw/*/*/**/"$UI".h ; do + + # friendly name for this build + NAME=$(echo "$TARGET" | perl -ne 's|/|-|g; /hw-(.*)-'"$UI"'.h/ && print "$1\n";') + + # limit builds to searched patterns, if given + SKIP=0 + if [ ${#SEARCH[@]} -gt 0 ]; then + for text in "${SEARCH[@]}" ; do + if ! echo "$NAME $TARGET" | grep -i -- "$text" > /dev/null ; then + SKIP=1 + fi + done + fi + if [ 1 = $SKIP ]; then continue ; fi + + # announce what we're going to build + echo "===== $UI $REV : $NAME =====" + + # try to compile, track result, and rename compiled files + if bin/build.sh "$TARGET" ; then + HEX_OUT="hex/$UI.$NAME.hex" + mv -f "ui/$UI/$UI".hex "$HEX_OUT" + MD5=$(md5sum "$HEX_OUT" | cut -d ' ' -f 1) + echo " # $MD5" + echo " > $HEX_OUT" + PASS=$((PASS + 1)) + PASSED="$PASSED $NAME" + else + echo "ERROR: build failed" + FAIL=$((FAIL + 1)) + FAILED="$FAILED $NAME" fi + done - fi - if [ 1 = $SKIP ]; then continue ; fi - - # announce what we're going to build - echo "===== $UI $REV : $NAME =====" - - # try to compile, track result, and rename compiled files - if bin/build.sh "$TARGET" ; then - HEX_OUT="hex/$UI.$NAME.hex" - mv -f "ui/$UI/$UI".hex "$HEX_OUT" - MD5=$(md5sum "$HEX_OUT" | cut -d ' ' -f 1) - echo " # $MD5" - echo " > $HEX_OUT" - PASS=$((PASS + 1)) - PASSED="$PASSED $NAME" - else - echo "ERROR: build failed" - FAIL=$((FAIL + 1)) - FAILED="$FAILED $NAME" - fi - -done - -# summary -echo "===== $PASS builds succeeded, $FAIL failed =====" -#echo "PASS: $PASSED" -if [ 0 != $FAIL ]; then - echo "FAIL:$FAILED" - exit 1 -fi + + # summary + echo "===== $PASS builds succeeded, $FAIL failed =====" + #echo "PASS: $PASSED" + if [ 0 != $FAIL ]; then + echo "FAIL:$FAILED" + exit 1 + fi +} + +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' + # save the version name to version.h + mkdir -p ".build/$UI" + echo '#define VERSION_NUMBER "'"$REV"'"' > ".build/$UI/version.h" +} + +main "$@" + -- cgit v1.2.3 From c1542a1dce5c40afc36148a1c1ddbd559fcc3014 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 1 Dec 2023 18:21:55 -0700 Subject: added bin/make-release.sh to generate a .zip file ready for release --- bin/make-release.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 bin/make-release.sh (limited to 'bin') diff --git a/bin/make-release.sh b/bin/make-release.sh new file mode 100755 index 0000000..da985d1 --- /dev/null +++ b/bin/make-release.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# Create a release file for Anduril .hex files. +# Copyright (C) 2023 Selene ToyKeeper +# SPDX-License-Identifier: GPL-3.0-or-later + +set -e # abort on error + +# run from repo root +REPODIR=$(dirname "$0")/.. +cd "$REPODIR" + +# get rid of 1st arg if it's "release" passed from 'make' +[[ "$1" = "release" ]] && shift + +# try to get the repo ready for a release +# (or not; probably better to do these steps manually) +#make clean +#make + +# release name +#REV=$(date +'%Y-%m-%d') +REV=$(git describe --tags --dirty --match='r2*') +REV="${REV:1}" # convert 'r2023-...' to '2023-...' +# allow manually specifying a release name +[[ -n "$1" ]] && REV="$1" + +# releases are named "$project.$revision" +RELNAME="anduril.$REV" + +# release directory +RELDIR="releases/$RELNAME" +mkdir -p "$RELDIR" "$RELDIR/hex" + +# add documentation and stuff +cp -a \ + ChangeLog.md \ + LICENSE \ + MODELS \ + README.md \ + docs/anduril-manual.md \ + docs/battery-rainbow.png \ + docs/which-hex-file.md \ + "$RELDIR" + +# add the .hex files +rename -f 's|hex/anduril.|'"$RELDIR/hex/$RELNAME"'.|;' hex/*.hex + +# make a .zip file +cd releases +mkdir -p zip +ZPATH=zip/"$RELNAME".zip +zip -q -r "$ZPATH" "$RELNAME" +cd .. +ls -l "releases/$ZPATH" + -- cgit v1.2.3 From dcbacb61bb3e04872927008a394524ed9208c740 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 2 Dec 2023 13:30:42 -0700 Subject: build-all: handle the case where "git describe" can't get any tags Resulting revision is "$MODEL-0.$HASH" where the hash is the commit short ID --- bin/build-all.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'bin') diff --git a/bin/build-all.sh b/bin/build-all.sh index 444809e..f239217 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -88,6 +88,11 @@ function make-version-h { # 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 # save the version name to version.h mkdir -p ".build/$UI" echo '#define VERSION_NUMBER "'"$REV"'"' > ".build/$UI/version.h" -- cgit v1.2.3 From 8e86d66238572c1d97cd54a592da0573a51892a1 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 3 Dec 2023 17:47:36 -0700 Subject: updated MODELS, bin/models.py, and hw/BRANDS... - changed column order to (model, mcu, name) - changed column sizes (auto-sized w/ 2 spaces between columns) - made it handle hex digits in model numbers - reserved 1900 to 2199 for years only, not model numbers - noted gChart and thefreeman sharing a brand ID --- bin/models.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/models.py b/bin/models.py index 8e54d1c..1a1152e 100755 --- a/bin/models.py +++ b/bin/models.py @@ -24,12 +24,18 @@ def main(args): foo.sort() models = [x[-1] for x in foo] + colsizes = [ + max(len(m.model) for m in models), + max(len(m.mcu) for m in models), + max(len(m.name) for m in models), + ] + print('Models: %i\n' % len(models)) - fmt = '%s\t%-30s\t%s' - print(fmt % ('Model', 'Name', 'MCU')) - print(fmt % ('-----', '----', '---')) + fmt = '%%-%is %%-%is %%s' % (colsizes[0], colsizes[1]) + print(fmt % ('Model', 'MCU', 'Name')) + print(fmt % ('-----', '---', '----')) for m in models: - print(fmt % (m.model, m.name, m.mcu)) + print(fmt % (m.model, m.mcu, m.name)) print('\nDuplicates:') for i, m in enumerate(models): @@ -56,6 +62,7 @@ def load_model(path): m.name = path.replace('hw/','').replace('/', '-') m.mcu = inherit(path, 'arch') m.model = inherit(path, 'model') + if m.model: m.model = model_translate(m.model) return m @@ -73,6 +80,24 @@ def inherit(path, field): return None +def model_translate(m): + """Convert raw ordinal hex codes into human-friendly a-f digits. + """ + m = str(m) + replace = { + chr(ord('0') + 10): 'a', + chr(ord('0') + 11): 'b', + chr(ord('0') + 12): 'c', + chr(ord('0') + 13): 'd', + chr(ord('0') + 14): 'e', + chr(ord('0') + 15): 'f', + } + for s, r in replace.items(): + m = m.replace(s, r) + + return m + + if __name__ == "__main__": import sys main(sys.argv[1:]) -- cgit v1.2.3 From 7153149c99e416f6efad3b84e5b550c0abf56454 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 5 Dec 2023 11:54:54 -0700 Subject: moved version string calculation to bin/version-string.sh Also updated the format slightly, so this rev is: `2023-12-03+2#1` +N for commits since tag #1 for dirty --- bin/build-all.sh | 14 +------------ bin/version-string.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 13 deletions(-) create mode 100755 bin/version-string.sh (limited to 'bin') 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 "$@" + -- cgit v1.2.3