diff --git a/build_output/release/StarMod_24041415_esp32dev.bin b/build_output/release/StarMod_24041415_esp32dev.bin new file mode 100644 index 00000000..d61d5534 Binary files /dev/null and b/build_output/release/StarMod_24041415_esp32dev.bin differ diff --git a/build_output/release/StarMod_24041415_esp32dev.bin.gz b/build_output/release/StarMod_24041415_esp32dev.bin.gz new file mode 100644 index 00000000..46f50bf3 Binary files /dev/null and b/build_output/release/StarMod_24041415_esp32dev.bin.gz differ diff --git a/tools/post_build.py b/tools/post_build.py index a422693f..d3d340d2 100644 --- a/tools/post_build.py +++ b/tools/post_build.py @@ -18,7 +18,13 @@ print("***************************************************************************************************************************") print("") -OUTPUT_DIR = os.path.expanduser("~")+"/Downloads/" +isGitHub = "runner" not 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] @@ -28,40 +34,53 @@ def _get_cpp_define_value(env, define): 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() #creates firmware and map + _create_dirs(["release"]) # create string with location and file names based on pioenv + map_file = "{}map{}{}_{}_{}.map".format(OUTPUT_DIR, os.path.sep, app, version, pioenv) + bin_file = "{}release{}{}_{}_{}.bin".format(OUTPUT_DIR, os.path.sep, app, version, pioenv) + else: map_file = "{}{}_{}_{}.map".format(OUTPUT_DIR, app, version, pioenv) 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) - # 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.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) + # 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) + # github needs zips (I think) + if isGitHub: + gzip_file = "{}release{}{}_{}_{}.bin.gz".format(OUTPUT_DIR, os.path.sep, app, version, pioenv) + # check if new target files exist and remove if necessary + if os.path.isfile(gzip_file): os.remove(gzip_file) - # # 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) + # 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) env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_rename_copy])