Skip to content

Commit

Permalink
Merge pull request #3859 from w00000dy/serg
Browse files Browse the repository at this point in the history
Only create bin.gz files for esp8266
  • Loading branch information
blazoncek committed Mar 29, 2024
2 parents 157dbff + 6f6356e commit b7db5be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wled-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
name: firmware-${{ matrix.environment }}
path: |
build_output/release/*.bin
build_output/release/*_ESP02.bin.gz
build_output/release/*_ESP02*.bin.gz
release:
name: Create Release
runs-on: ubuntu-latest
Expand Down
56 changes: 17 additions & 39 deletions pio-scripts/output_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import gzip

OUTPUT_DIR = "build_output{}".format(os.path.sep)
OUTPUT_DIR = os.path.join("build_output")

def _get_cpp_define_value(env, define):
define_list = [item[-1] for item in env["CPPDEFINES"] if item[0] == define]
Expand All @@ -13,63 +13,41 @@ 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)

def _create_dirs(dirs=["map", "release"]):
for d in dirs:
if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
os.mkdir("{}{}".format(OUTPUT_DIR, d))
os.makedirs(os.path.join(OUTPUT_DIR, d), exist_ok=True)

def create_release(source):
release_name = _get_cpp_define_value(env, "WLED_RELEASE_NAME")
if release_name:
_create_dirs(["release"])
version = _get_cpp_define_value(env, "WLED_VERSION")
# get file extension of source file (.bin or .bin.gz)
ext = source.split(".", 1)[1]
release_file = "{}release{}WLED_{}_{}.{}".format(OUTPUT_DIR, os.path.sep, version, release_name, ext)
release_file = os.path.join(OUTPUT_DIR, "release", f"WLED_{version}_{release_name}.bin")
release_gz_file = release_file + ".gz"
print(f"Copying {source} to {release_file}")
shutil.copy(source, release_file)
bin_gzip(release_file, release_gz_file)

def bin_rename_copy(source, target, env):
_create_dirs()
variant = env["PIOENV"]

# 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/<variant>.bin
shutil.copy(str(target[0]), bin_file)

create_release(bin_file)
create_release(str(target[0]))

# copy firmware.map to map/<variant>.map
if os.path.isfile("firmware.map"):
shutil.move("firmware.map", map_file)

def bin_gzip(source, target, env):
_create_dirs()
variant = env["PIOENV"]

# create string with location and file names based on variant
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
gzip_file = "{}firmware{}{}.bin.gz".format(OUTPUT_DIR, os.path.sep, variant)

# 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:
def bin_gzip(source, target):
# only create gzip for esp8266
if not env["PIOPLATFORM"] == "espressif8266":
return

print(f"Creating gzip file {target} from {source}")
with open(source,"rb") as fp:
with gzip.open(target, "wb", compresslevel = 9) as f:
shutil.copyfileobj(fp, f)

create_release(gzip_file)

env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_rename_copy, bin_gzip])
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_rename_copy)

0 comments on commit b7db5be

Please sign in to comment.