From 1b1b1ed83cdba93535b01449cacbb1100d94912d Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon, 18 Jan 2021 19:21:51 +0100 Subject: [PATCH] build gz only for ESP8266 --- pio-tools/gzip-firmware.py | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/pio-tools/gzip-firmware.py b/pio-tools/gzip-firmware.py index e29c05576..bb1759123 100644 --- a/pio-tools/gzip-firmware.py +++ b/pio-tools/gzip-firmware.py @@ -3,26 +3,32 @@ import os import shutil import gzip -OUTPUT_DIR = "build_output{}".format(os.path.sep) +platform = env.PioPlatform() +board = env.BoardConfig() +mcu = board.get("build.mcu", "esp32") +# gzip only for ESP8266 +if env["PIOPLATFORM"] != "espressif32": -def bin_gzip(source, target, env): - variant = str(target[0]).split(os.path.sep)[2] - - # 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) + OUTPUT_DIR = "build_output{}".format(os.path.sep) - # check if new target files exist and remove if necessary - if os.path.isfile(gzip_file): os.remove(gzip_file) + def bin_gzip(source, target, env): + variant = str(target[0]).split(os.path.sep)[2] - # 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) - - ORG_FIRMWARE_SIZE = os.stat(bin_file).st_size - GZ_FIRMWARE_SIZE = os.stat(gzip_file).st_size + # 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) - print("Compression reduced firmware size by {:.0f}% (was {} bytes, now {} bytes)".format((GZ_FIRMWARE_SIZE / ORG_FIRMWARE_SIZE) * 100, ORG_FIRMWARE_SIZE, GZ_FIRMWARE_SIZE)) + # check if new target files exist and remove if necessary + if os.path.isfile(gzip_file): os.remove(gzip_file) -env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip]) + # 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) + + ORG_FIRMWARE_SIZE = os.stat(bin_file).st_size + GZ_FIRMWARE_SIZE = os.stat(gzip_file).st_size + + print("Compression reduced firmware size by {:.0f}% (was {} bytes, now {} bytes)".format((GZ_FIRMWARE_SIZE / ORG_FIRMWARE_SIZE) * 100, ORG_FIRMWARE_SIZE, GZ_FIRMWARE_SIZE)) + + env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip])