Merge pull request #12830 from Jason2866/gzip_map

gzip map file to save disk space
This commit is contained in:
Jason2866 2021-08-06 20:59:09 +02:00 committed by GitHub
commit 0b28019544
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 3 deletions

View File

@ -6,11 +6,32 @@ import gzip
platform = env.PioPlatform()
board = env.BoardConfig()
mcu = board.get("build.mcu", "esp32")
OUTPUT_DIR = "build_output{}".format(os.path.sep)
def map_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 = "{}map{}{}.map".format(OUTPUT_DIR, os.path.sep, variant)
gzip_file = "{}map{}{}.map.gz".format(OUTPUT_DIR, os.path.sep, variant)
# check if new target map files exist and remove if necessary
if os.path.isfile(gzip_file): os.remove(gzip_file)
# write gzip map file
with open(bin_file,"rb") as fp:
with gzip.open(gzip_file, "wb", compresslevel = 9) as f:
shutil.copyfileobj(fp, f)
# remove map file
if os.path.isfile(bin_file): os.remove(bin_file)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [map_gzip])
# gzip only for ESP8266
if env["PIOPLATFORM"] != "espressif32":
OUTPUT_DIR = "build_output{}".format(os.path.sep)
def bin_gzip(source, target, env):
variant = str(target[0]).split(os.path.sep)[2]
@ -33,5 +54,5 @@ if env["PIOPLATFORM"] != "espressif32":
print("\u001b[31;1m!!! Tasmota firmware size is too big with {} bytes. Max size is 995326 bytes !!! \u001b[0m".format(ORG_FIRMWARE_SIZE))
else:
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])