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

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]