Skip to content

Commit 6582a41

Browse files
committed
Merge pull request adafruit#421 from dhylands/git-version
Add the git version and build-date to the banner
2 parents 70193b2 + bf7d690 commit 6582a41

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

py/py-version.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
git_hash="$(git rev-parse --short HEAD 2> /dev/null || echo unknown)"
4+
git_files_are_clean=1
5+
# Check if there are any modified files.
6+
git diff --no-ext-diff --quiet --exit-code 2> /dev/null || git_files_are_clean=0
7+
# Check if there are any staged files.
8+
git diff-index --cached --quiet HEAD -- 2> /dev/null || git_files_are_clean=0
9+
if [ "${git_files_are_clean}" != "1" ]; then
10+
git_hash="${git_hash}-dirty"
11+
fi
12+
cat <<EOF
13+
// This file was generated by py/py-version.sh
14+
#define MICROPY_GIT_HASH "${git_hash}"
15+
#define MICROPY_BUILD_DATE "$(date '+%Y-%m-%d')"
16+
EOF

py/py.mk

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ PY_O_BASENAME = \
9090
# prepend the build destination prefix to the py object files
9191
PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME))
9292

93+
# Anything that depends on FORCE will be considered out-of-date
94+
FORCE:
95+
.PHONY: FORCE
96+
97+
$(PY_BUILD)/py-version.h: FORCE
98+
$(Q)$(PY_SRC)/py-version.sh > $@.tmp
99+
$(Q)if [ -f "$@" ] && cmp -s $@ $@.tmp; then rm $@.tmp; else echo "Generating $@"; mv $@.tmp $@; fi
100+
93101
# qstr data
94102

95103
# Adding an order only dependency on $(PY_BUILD) causes $(PY_BUILD) to get
@@ -104,7 +112,7 @@ $(PY_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(PY_SRC)/makeqst
104112
# the right .o's to get recompiled if the generated.h file changes. Adding
105113
# an order-only dependendency to all of the .o's will cause the generated .h
106114
# to get built before we try to compile any of them.
107-
$(PY_O): | $(PY_BUILD)/qstrdefs.generated.h
115+
$(PY_O): | $(PY_BUILD)/qstrdefs.generated.h $(PY_BUILD)/py-version.h
108116

109117
# emitters
110118

stmhal/pyexec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "pyexec.h"
2424
#include "storage.h"
2525
#include "usb.h"
26+
#include "build/py/py-version.h"
2627

2728
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
2829
STATIC bool repl_display_debugging_info = 0;
@@ -155,7 +156,7 @@ int pyexec_friendly_repl(void) {
155156
#endif
156157

157158
friendly_repl_reset:
158-
stdout_tx_str("Micro Python build <git hash> on 25/1/2014; " MICROPY_HW_BOARD_NAME " with STM32F405RG\r\n");
159+
stdout_tx_str("Micro Python build " MICROPY_GIT_HASH " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with STM32F405RG\r\n");
159160
stdout_tx_str("Type \"help()\" for more information.\r\n");
160161

161162
// to test ctrl-C

0 commit comments

Comments
 (0)