2021-04-21 22:41:36 +00:00
|
|
|
Import('env')
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import gzip
|
|
|
|
|
2024-04-03 16:31:17 +00:00
|
|
|
OUTPUT_DIR = "build_output{}".format(os.path.sep)
|
|
|
|
#OUTPUT_DIR = os.path.join("build_output")
|
2021-04-21 22:41:36 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-04-03 16:31:17 +00:00
|
|
|
def _create_dirs(dirs=["map", "release", "firmware"]):
|
2021-04-21 22:41:36 +00:00
|
|
|
for d in dirs:
|
2024-03-19 19:06:09 +00:00
|
|
|
os.makedirs(os.path.join(OUTPUT_DIR, d), exist_ok=True)
|
2021-04-21 22:41:36 +00:00
|
|
|
|
2024-01-24 20:22:54 +00:00
|
|
|
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}")
|
2024-01-24 20:22:54 +00:00
|
|
|
shutil.copy(source, release_file)
|
2024-03-19 19:06:09 +00:00
|
|
|
bin_gzip(release_file, release_gz_file)
|
2024-04-03 16:31:17 +00:00
|
|
|
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)
|
2024-01-24 20:22:54 +00:00
|
|
|
|
2021-04-21 22:41:36 +00:00
|
|
|
def bin_rename_copy(source, target, env):
|
|
|
|
_create_dirs()
|
|
|
|
variant = env["PIOENV"]
|
2024-05-05 19:56:01 +00:00
|
|
|
builddir = os.path.join(env["PROJECT_BUILD_DIR"], variant)
|
|
|
|
source_map = os.path.join(builddir, env["PROGNAME"] + ".map")
|
2021-04-21 22:41:36 +00:00
|
|
|
|
|
|
|
# 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]))
|
2024-01-24 20:22:54 +00:00
|
|
|
|
2021-04-21 22:41:36 +00:00
|
|
|
# copy firmware.map to map/<variant>.map
|
|
|
|
if os.path.isfile("firmware.map"):
|
2024-05-05 19:56:01 +00:00
|
|
|
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)
|
2021-04-21 22:41:36 +00:00
|
|
|
|
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:
|
2021-04-21 22:41:36 +00:00
|
|
|
shutil.copyfileobj(fp, f)
|
|
|
|
|
2024-03-19 19:06:09 +00:00
|
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_rename_copy)
|