From c8a56d16b4762ce71b6d02f843d066e42cf17490 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Tue, 16 Apr 2024 13:54:56 +0200 Subject: [PATCH] pio.yml and post_build updates pio.yml - change name from StarMod-esp32... to StarMod-esp32dev... post_build: - check isGitHub - add _create_dirs to create build_output/release in case of github - do not generate map file - do not generate zip file --- .github/workflows/pio.yml | 2 +- src/SysModule.h | 1 - tools/post_build.py | 61 +++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/.github/workflows/pio.yml b/.github/workflows/pio.yml index ce34e695..33a86403 100644 --- a/.github/workflows/pio.yml +++ b/.github/workflows/pio.yml @@ -33,7 +33,7 @@ jobs: - name: 'Upload Artifact' uses: actions/upload-artifact@v3 with: - name: StarMod-esp32-${{env.git_branch}}-${{env.git_hash}}.bin + name: StarMod-esp32dev-${{env.git_branch}}-${{env.git_hash}}.bin path: .pio/build/esp32dev/firmware.bin retention-days: 30 diff --git a/src/SysModule.h b/src/SysModule.h index d41d22a4..53b28224 100644 --- a/src/SysModule.h +++ b/src/SysModule.h @@ -11,7 +11,6 @@ #pragma once -// #define VERSION 2024041411 //update for each build. Time in GMT !!! //make a string from pio variables (_INIT and STRINGIFY needed to make TOSTRING work) #define _INIT(x) x #define STRINGIFY(X) #X diff --git a/tools/post_build.py b/tools/post_build.py index a422693f..f27d886b 100644 --- a/tools/post_build.py +++ b/tools/post_build.py @@ -18,50 +18,47 @@ print("***************************************************************************************************************************") print("") -OUTPUT_DIR = os.path.expanduser("~")+"/Downloads/" +isGitHub = "runner" in os.path.expanduser("~") #do not copy in github PlatformIO CI (/home/runner/ is output dir in github) + +if isGitHub: + OUTPUT_DIR = "build_output{}".format(os.path.sep) +else: + OUTPUT_DIR = "{}{}Downloads{}".format(os.path.expanduser("~"), os.path.sep, os.path.sep) + def _get_cpp_define_value(env, define): define_list = [item[-1] for item in env["CPPDEFINES"] if item[0] == define] - if define_list: return define_list[0] - return None +def _create_dirs(dirs=["firmware", "map"]): + # check if output directories exist and create if necessary + if not os.path.isdir(OUTPUT_DIR): + os.mkdir(OUTPUT_DIR) + for d in dirs: + if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)): + os.mkdir("{}{}".format(OUTPUT_DIR, d)) + def bin_rename_copy(source, target, env): - if "runner" not in OUTPUT_DIR: #do not copy in github PlatformIO CI (/home/runner/ is output dir in github) - app = _get_cpp_define_value(env, "APP") - version = _get_cpp_define_value(env, "VERSION") - pioenv = env["PIOENV"] + app = _get_cpp_define_value(env, "APP") + version = _get_cpp_define_value(env, "VERSION") + pioenv = env["PIOENV"] + if isGitHub: + _create_dirs(["release"]) # create string with location and file names based on pioenv - map_file = "{}{}_{}_{}.map".format(OUTPUT_DIR, app, version, pioenv) + bin_file = "{}release{}{}_{}_{}.bin".format(OUTPUT_DIR, os.path.sep, app, version, pioenv) + else: bin_file = "{}{}_{}_{}.bin".format(OUTPUT_DIR, app, version, pioenv) - gzip_file = "{}{}_{}_{}.bin.gz".format(OUTPUT_DIR, app, version, pioenv) - - - # 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 bin_file - shutil.copy(str(target[0]), bin_file) - print(" created " + bin_file) - - # copy firmware.map to map_file - if os.path.isfile("firmware.map"): - shutil.move("firmware.map", map_file) - - # do not create zip version (yet) - # # check if new target files exist and remove if necessary - # if os.path.isfile(gzip_file): os.remove(gzip_file) + # check if new target files exist and remove if necessary + for f in [bin_file]: #map_file, + if os.path.isfile(f): + os.remove(f) - # # write gzip firmware file - # with open(bin_file,"rb") as fp: - # with gzip.open(gzip_file, "wb", compresslevel = 9) as f: - # shutil.copyfileobj(fp, f) - # print(" created " + gzip_file) + # copy firmware.bin to bin_file + shutil.copy(str(target[0]), bin_file) + print(" created " + bin_file) env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_rename_copy])