mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
merge gzip into firmware rename function
This commit is contained in:
@@ -50,7 +50,6 @@ check_flags =
|
|||||||
extra_scripts =
|
extra_scripts =
|
||||||
scripts/main_script.py
|
scripts/main_script.py
|
||||||
scripts/rename_fw.py
|
scripts/rename_fw.py
|
||||||
scripts/gzip_fw.py
|
|
||||||
board = esp12e
|
board = esp12e
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
@@ -61,7 +60,6 @@ build_flags = ${common.build_flags}
|
|||||||
[env:esp32-ci]
|
[env:esp32-ci]
|
||||||
extra_scripts =
|
extra_scripts =
|
||||||
scripts/rename_fw.py
|
scripts/rename_fw.py
|
||||||
scripts/gzip_fw.py
|
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board_build.partitions = min_spiffs.csv
|
board_build.partitions = min_spiffs.csv
|
||||||
@@ -71,6 +69,7 @@ build_flags = ${common.build_flags}
|
|||||||
extra_scripts =
|
extra_scripts =
|
||||||
pre:scripts/build_interface.py
|
pre:scripts/build_interface.py
|
||||||
scripts/main_script.py
|
scripts/main_script.py
|
||||||
|
scripts/rename_fw.py
|
||||||
board = esp12e ; https://github.com/platformio/platform-espressif8266/tree/master/boards
|
board = esp12e ; https://github.com/platformio/platform-espressif8266/tree/master/boards
|
||||||
platform = espressif8266 ; https://github.com/platformio/platform-espressif8266/releases
|
platform = espressif8266 ; https://github.com/platformio/platform-espressif8266/releases
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
@@ -85,6 +84,7 @@ lib_ignore =
|
|||||||
[env:esp32]
|
[env:esp32]
|
||||||
extra_scripts =
|
extra_scripts =
|
||||||
pre:scripts/build_interface.py
|
pre:scripts/build_interface.py
|
||||||
|
scripts/rename_fw.py
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
; platform = https://github.com/platformio/platform-espressif32.git
|
; platform = https://github.com/platformio/platform-espressif32.git
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
Import('env')
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import shutil
|
|
||||||
import gzip
|
|
||||||
|
|
||||||
OUTPUT_DIR = "build{}".format(os.path.sep)
|
|
||||||
|
|
||||||
def bin_gzip(source, target, env):
|
|
||||||
|
|
||||||
# get the version
|
|
||||||
bag = {}
|
|
||||||
exprs = [
|
|
||||||
(re.compile(r'^#define EMSESP_APP_VERSION\s+"(\S+)"'), 'app_version'),
|
|
||||||
]
|
|
||||||
with open('./src/version.h', 'r') as f:
|
|
||||||
for l in f.readlines():
|
|
||||||
for expr, var in exprs:
|
|
||||||
m = expr.match(l)
|
|
||||||
if m and len(m.groups()) > 0:
|
|
||||||
bag[var] = m.group(1)
|
|
||||||
|
|
||||||
app_version = bag.get('app_version')
|
|
||||||
|
|
||||||
variant = "EMS-ESP-" + app_version.replace(".", "_") + "-" + 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)
|
|
||||||
|
|
||||||
# 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:
|
|
||||||
shutil.copyfileobj(fp, f)
|
|
||||||
|
|
||||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip])
|
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
Import('env')
|
Import('env', "projenv")
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import gzip
|
||||||
|
|
||||||
OUTPUT_DIR = "build{}".format(os.path.sep)
|
OUTPUT_DIR = "build{}".format(os.path.sep)
|
||||||
|
|
||||||
def bin_copy(source, target, env):
|
def bin_copy(source, target, env):
|
||||||
|
|
||||||
# get the version
|
# get the EMS-ESP version
|
||||||
bag = {}
|
bag = {}
|
||||||
exprs = [
|
exprs = [(re.compile(r'^#define EMSESP_APP_VERSION\s+"(\S+)"'), 'app_version')]
|
||||||
(re.compile(r'^#define EMSESP_APP_VERSION\s+"(\S+)"'), 'app_version'),
|
|
||||||
]
|
|
||||||
with open('./src/version.h', 'r') as f:
|
with open('./src/version.h', 'r') as f:
|
||||||
for l in f.readlines():
|
for l in f.readlines():
|
||||||
for expr, var in exprs:
|
for expr, var in exprs:
|
||||||
@@ -19,27 +18,29 @@ def bin_copy(source, target, env):
|
|||||||
if m and len(m.groups()) > 0:
|
if m and len(m.groups()) > 0:
|
||||||
bag[var] = m.group(1)
|
bag[var] = m.group(1)
|
||||||
|
|
||||||
app_version = bag.get('app_version')
|
|
||||||
|
|
||||||
variant = "EMS-ESP-" + app_version.replace(".", "_") + "-" + str(target[0]).split(os.path.sep)[2]
|
# esp8266 or esp32
|
||||||
|
platform = "esp" + env['PIOPLATFORM'].strip("espressif")
|
||||||
|
|
||||||
# check if output directories exist and create if necessary
|
# str(target[0]).split(os.path.sep)[2]
|
||||||
if not os.path.isdir(OUTPUT_DIR):
|
variant = "EMS-ESP-" + bag.get('app_version').replace(".", "_") + "-" + platform
|
||||||
os.mkdir(OUTPUT_DIR)
|
|
||||||
|
|
||||||
for d in ['firmware']:
|
|
||||||
if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
|
|
||||||
os.mkdir("{}{}".format(OUTPUT_DIR, d))
|
|
||||||
|
|
||||||
# create string with location and file names based on variant
|
# create string with location and file names based on variant
|
||||||
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, 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
|
# check if new target files exist and remove if necessary
|
||||||
for f in [bin_file]:
|
if os.path.isfile(bin_file): os.remove(bin_file)
|
||||||
if os.path.isfile(f):
|
if os.path.isfile(gzip_file): os.remove(gzip_file)
|
||||||
os.remove(f)
|
|
||||||
|
|
||||||
# copy firmware.bin to firmware/<variant>.bin
|
# copy firmware.bin to new name
|
||||||
shutil.copy(str(target[0]), bin_file)
|
shutil.copy(str(target[0]), bin_file)
|
||||||
|
|
||||||
|
# create a zip'd version
|
||||||
|
with open(bin_file, "rb") as fp:
|
||||||
|
with gzip.open(gzip_file, "wb", compresslevel = 9) as f:
|
||||||
|
shutil.copyfileobj(fp, f)
|
||||||
|
|
||||||
|
print("Built firmwares: "+ bin_file + ", " + gzip_file)
|
||||||
|
|
||||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_copy])
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_copy])
|
||||||
|
|||||||
Reference in New Issue
Block a user