I have referenced the Custom firmware/program name section of the Advanced Scripting doc. I’ve got a start on things, but some of it is not clicking. I’m trying to concatenate the firmware name from:
- Framework
- Board
- Pre-processor flag
- Git tag
So far I am using this platformio.ini
:
[env:uno]
platform = atmelavr
board = uno
framework = arduino
build_flags = !python git_rev.py
extra_scripts = pre:name_firmware.py
My git_rev.py
is as follows:
import subprocess
tagcmd = "git describe --tags --abbrev=0"
version = subprocess.check_output(tagcmd).decode().strip()
revcmd = "git log --pretty=format:'%h' -n 1"
commit = subprocess.check_output(revcmd).decode().strip()
print "-DPIO_SRC_TAG=%s" % version
print "-DPIO_SRC_REV=%s" % commit
And my name_firmware.py
is as follows (so far):
import subprocess
Import("env")
my_flags = env.ParseFlags(env['BUILD_FLAGS'])
defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")}
env.Replace(PROGNAME="myfile-%s-%s-%s-%s" % (
defines.get("PIOFRAMEWORK"),
defines.get("PIOENV"),
"PreProcDef",
defines.get("PIO_SRC_TAG")))
So far, the compiled file is named myfile-None-None-PreProcDef-1.2.3.hex
As you can see I get the PIO_SRC_TAG from my Git tag, but I am not getting the framework (expecting “arduino”) and I am not getting the board (expecting “uno”). Hopefully someone can help me with those two?
Also, is there any way to get a pre-processor definition? Where I currently have “PreProcDef” I’d like to get a #define out of one of my config.h
file. For instance I have a define like this:
#define STATIC_CONFIG SHIELD_TWI
I’d like to just get the “TWI” portion if possible, but I can always do a case statement if I have to get the whole SHIELD_TWI
part… Hopefully there’s a snazzy way to do that without grep/sed hell.
Desired end result would be: myfile-arduino-uno-twi-1.2.3.hex
Banging my head on this but I’m pretty sure it’s possible. Any assistance would be highly appreciated!
Thank you for reading.