PlatformIO Community

Rename bin file on build

Is there a way to rename the bin file to include the DBUILD_TAG when targeting a specific build?

e.g. in the platformio.ini I have the a entry version = -DBUILD_TAG=2.2. I would like this to be concatenated to the bin file when doing a release build so that firmware.bin becomes firmware_v2.2.bin

Sure, take a look at Advanced Scripting. You need an extra script

Import("env")

build_tag = "v2.2"

env.Replace(PROGNAME="firmware_%s" % build_tag)
1 Like

Thanks Ivan

I got it working using a python script that renames it and moves it to a release location. Working like a well oiled machine now :slight_smile:

1 Like

I can’t get this to work.
This is show in the output
warning: Calling missing SConscript without error is deprecated.
Transition by adding must_exist=0 to SConscript calls.
Missing SConscript ‘extra_script.py’

So what exactly is your project file structure and the content of your extra script?

Thanks Max for your help, here the info

the content of extrascript.py:

Import("env", "projenv")
# access to global construction environment
print(env)
# access to project construction environment
print(projenv)
my_flags = env.ParseFlags(env['BUILD_FLAGS'])
defines = {k: v for (k, v) in my_flags.get("CPPDEFINES")}
print(defines)
env.Replace(PROGNAME="firmware_test%s" % defines.get("VERSION")) 

location of the extrascript.py file
Screenshot 2020-04-10 09.26.18

my platform.ini

[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino
lib_deps =
    PubSubClient
    EspSoftwareSerial
build_flags = -D VERSION=1.1.3
extra_scripts = pre:extra_script.py
monitor_speed = 115200

output

So in your platformio.ini you instruct PIO to execute extra_script.py but in your project there’s no such file, but a extrascript.py instead. You just have a typo :sweat_smile:.

1 Like

:blush: thanks a lot