Version control and tracking is hard.
For sure in the Arduino IDE, which invites to rapid prototyping and has no built-in version tracking or version control mechanism.
A possible solution:
To make it somewhat more practical and less error prone I made some scripts to assist this process.
It works if you already use or start using git for your version control.
Using these scripts is as easy as adding them to your sketch folder and adding
#include "gitTagVersion.h" ... Serial.println( sketchVersion );
to your Arduino sketch.
That is all that is needed.
The output in the example above will be something like
That breaks down to tag v1.0.0, 3 commits since that tag, at commit ab3fb04.
How to install and use?
There are 2 scripts involved, the first script is a replacement for the Arduino
Save it as verify.sh:
echo "const char * sketchVersion = \"$(git describe --tags --always --dirty)\";" > gitTagVersion.h ~/arduino-1.8.5/arduino --verify test.ino rm gitTagVersion.h
And the second script replaces the
Save it as upload.sh:
echo "const char * sketchVersion = \"$(git describe --tags --always --dirty)\";" > gitTagVersion.h ~/arduino-1.8.5/arduino --upload test.ino --pref custom_DebugLevel=esp32_none rm gitTagVersion.h
Some things to note about these scripts:
- The scripts REPLACE the buttons.
You won’t be able to use the buttons anymore, as these buttons don’t generate the necessary version info from git.
Using them will result in this error:
fatal error: gitTagVersion.h: No such file or directory
- The scripts are hardcoded to use Arduino 1.8.5 and have to be updated if you update your Arduino IDE.
- These script only work in Linux with a vanilla Arduino install.
If you use Windows, or are on a Mac the scripts will not work.
- To change the debug output (using the
LOGx_ESPmacros) on ESP32 builds, change the custom_DebugLevel in the
Uploadscript to esp32_xxxx, where xxxx is none, info, error, debug or verbose.