WLED/pio-scripts/output_bins.py

66 wiersze
2.2 KiB
Python
Czysty Zwykły widok Historia

Import('env')
import os
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]
if define_list:
return define_list[0]
return None
def _create_dirs(dirs=["map", "release", "firmware"]):
for d in dirs:
2024-03-19 19:06:09 +00:00
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:
version = _get_cpp_define_value(env, "WLED_VERSION")
2024-03-19 19:06:09 +00:00
release_file = os.path.join(OUTPUT_DIR, "release", f"WLED_{version}_{release_name}.bin")
2024-03-26 16:34:01 +00:00
release_gz_file = release_file + ".gz"
2024-03-19 19:06:09 +00:00
print(f"Copying {source} to {release_file}")
shutil.copy(source, release_file)
2024-03-19 19:06:09 +00:00
bin_gzip(release_file, release_gz_file)
else:
variant = env["PIOENV"]
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
print(f"Copying {source} to {bin_file}")
shutil.copy(source, bin_file)
def bin_rename_copy(source, target, env):
_create_dirs()
variant = env["PIOENV"]
builddir = os.path.join(env["PROJECT_BUILD_DIR"], variant)
source_map = os.path.join(builddir, env["PROGNAME"] + ".map")
# create string with location and file names based on variant
map_file = "{}map{}{}.map".format(OUTPUT_DIR, os.path.sep, variant)
2024-03-19 19:06:09 +00:00
create_release(str(target[0]))
# copy firmware.map to map/<variant>.map
if os.path.isfile("firmware.map"):
print("Found linker mapfile firmware.map")
shutil.copy("firmware.map", map_file)
if os.path.isfile(source_map):
print(f"Found linker mapfile {source_map}")
shutil.copy(source_map, map_file)
2024-03-19 19:06:09 +00:00
def bin_gzip(source, target):
2024-03-26 16:34:01 +00:00
# only create gzip for esp8266
if not env["PIOPLATFORM"] == "espressif8266":
return
2024-03-27 20:34:51 +00:00
print(f"Creating gzip file {target} from {source}")
2024-03-19 19:06:09 +00:00
with open(source,"rb") as fp:
with gzip.open(target, "wb", compresslevel = 9) as f:
shutil.copyfileobj(fp, f)
2024-03-19 19:06:09 +00:00
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_rename_copy)