From 07ce1db304b295dc70930fc9e6732c797316eab1 Mon Sep 17 00:00:00 2001 From: Yurii Date: Sat, 13 Jan 2024 20:34:00 +0300 Subject: [PATCH] feat: make fs after build and copy to build dir --- tools/build.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tools/build.py b/tools/build.py index 91466d3..d9f9c98 100644 --- a/tools/build.py +++ b/tools/build.py @@ -2,20 +2,33 @@ import shutil import os Import("env") + def post_build(source, target, env): - if os.path.exists(os.path.join(env["PROJECT_DIR"], "build")) == False: - return + copy_to_build_dir({ + source[0].get_abspath(): "firmware_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")), + env.subst("$BUILD_DIR/${PROGNAME}.factory.bin"): "firmware_%s_%s.factory.bin" % (env["PIOENV"], env.GetProjectOption("version")), + }, os.path.join(env["PROJECT_DIR"], "build")); + + env.Execute("pio run --target buildfs --environment %s" % env["PIOENV"]); - files = { - env.subst("$BUILD_DIR/${PROGNAME}.bin"): "firmware_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")), - env.subst("$BUILD_DIR/${PROGNAME}.factory.bin"): "firmware_%s_%s.factory.bin" % (env["PIOENV"], env.GetProjectOption("version")), - } - for src in files: - if os.path.exists(src): - dest = os.path.join(env["PROJECT_DIR"], "build", files[src]) - - print("Copying '%s' to '%s'" % (src, dest)) - shutil.copy(src, dest) +def after_buildfs(source, target, env): + copy_to_build_dir({ + source[0].get_abspath(): "filesystem_%s_%s.bin" % (env["PIOENV"], env.GetProjectOption("version")), + }, os.path.join(env["PROJECT_DIR"], "build")); -env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", post_build) \ No newline at end of file + +def copy_to_build_dir(files, build_dir): + if os.path.exists(build_dir) == False: + return + + for src in files: + if os.path.exists(src): + dst = os.path.join(build_dir, files[src]) + + print("Copying '%s' to '%s'" % (src, dst)) + shutil.copy(src, dst) + + +env.AddPostAction("buildprog", post_build) +env.AddPostAction("buildfs", after_buildfs) \ No newline at end of file