Skip to content

Commit

Permalink
pio.yml and post_build updates
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ewoudwijma committed Apr 16, 2024
1 parent 7187fb3 commit c8a56d1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 0 additions & 1 deletion src/SysModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 29 additions & 32 deletions tools/post_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit c8a56d1

Please sign in to comment.