Skip to content

Commit

Permalink
post build releases
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Apr 15, 2024
1 parent 7187fb3 commit 6e25c5a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
Binary file not shown.
Binary file not shown.
71 changes: 45 additions & 26 deletions tools/post_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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])

0 comments on commit 6e25c5a

Please sign in to comment.