Skip to content

Commit

Permalink
#feature Autogenerating version number
Browse files Browse the repository at this point in the history
  • Loading branch information
loredan committed Jan 17, 2020
1 parent 1ed6701 commit 5cf9c4e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/platformio.ini
Expand Up @@ -32,7 +32,7 @@ board = ATmega88P
framework = arduino
lib_deps = Arduino

build_flags =
build_flags = !python version_git.py
; --verbose

upload_protocol = arduino
Expand All @@ -58,7 +58,7 @@ board = ATmega328PB
framework = arduino
lib_deps = Arduino

build_flags =
build_flags = !python version_git.py
; --verbose

upload_protocol = arduino
Expand Down
Expand Up @@ -84,7 +84,7 @@ update the voltMeterConstant variable in pP_config.h with the correct value
------------------------------------------------------------*/

#define PP_VERSION "2.2.1_882a87"
// #define PP_VERSION "2.2.1_882a87"

/* Debug output verbose mode will continuously output sensor readings
rather than waiting for user input */
Expand Down
4 changes: 4 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/version_git.py
@@ -0,0 +1,4 @@
import subprocess

major_version = "2.2.1"
print("-DPP_VERSION=\\\"" + major_version + "_" + subprocess.check_output(["git", "rev-parse", "HEAD"])[0:6] + "\\\"")

This comment has been minimized.

Copy link
@theopensourcerer

theopensourcerer Jan 19, 2020

I just tried to build this develop branch in VSCode/Platform and git an error about the print line being bytes and not a string. (Sorry have now lost the exact error). Anyway, casting the check_output to a string allowed me to compile and the version shows when I issue a CONFIG command... , e.g.:

print("-DPP_VERSION=\\\"" + major_version + "_" + str(subprocess.check_output(["git", "rev-parse", "HEAD"])[0:6]) + "\\\"")

And output:
Screenshot from 2020-01-19 15-08-57

This comment has been minimized.

Copy link
@loredan

loredan Jan 19, 2020

Author Contributor

The issue is with default Python version on PC, on Discord we figured two ways to work around it:

Do decode("utf-8") on the check_output output if it's not str
Specify Python version in .ini file, e.g. !python2 version-git.py

First one is a bit of a hack, IMO, but second one could cause build errors if specified Python version is not found, so I guess we go with first, I just need to update pull request

0 comments on commit 5cf9c4e

Please sign in to comment.