From 87b42c4c4e343c2050144424af04f146b86ed77a Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Sat, 16 Nov 2019 20:16:39 +0100 Subject: [PATCH] Copy compiled firmware(s) in folder `build_output/firmware`... easier to find and firmware is named after the `envs`. A second folder is generated in `build_output` -> `map` where the generated map files to the bin(s) are stored. --- pio/name-firmware.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/pio/name-firmware.py b/pio/name-firmware.py index 1a65ad4fc..dfb9b7f85 100644 --- a/pio/name-firmware.py +++ b/pio/name-firmware.py @@ -2,11 +2,32 @@ Import('env') import os import shutil -def name_firmware(source, target, env): - base_dir = os.path.dirname(str(target[0])) - new_file = "{}{}{}.bin".format(base_dir, os.path.sep, str(target[0]).split(os.path.sep)[1]) - if os.path.isfile(new_file): - os.remove(new_file) - shutil.copyfile(str(target[0]), new_file) +OUTPUT_DIR = "build_output{}".format(os.path.sep) -env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [name_firmware]) +def bin_map_copy(source, target, env): + variant = str(target[0]).split(os.path.sep)[1] + + # check if output directories exist and create if necessary + if not os.path.isdir(OUTPUT_DIR): + os.mkdir(OUTPUT_DIR) + + for d in ['firmware', 'map']: + if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)): + os.mkdir("{}{}".format(OUTPUT_DIR, d)) + + # create string with location and file names based on variant + map_file = "{}map{}{}.map".format(OUTPUT_DIR, os.path.sep, variant) + bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant) + + # check if new target files exist and remove if necessary + for f in [map_file, bin_file]: + if os.path.isfile(f): + os.remove(f) + + # copy firmware.bin to firmware/.bin + shutil.copy(str(target[0]), bin_file) + + # copy firmware.map to map/.map + shutil.copy("firmware.map", map_file) + +env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_map_copy])