From 2984d786c3d2943bcf6fa091cac3d8e36d0c5f9d Mon Sep 17 00:00:00 2001 From: Ming Aldrich-Gan Date: Sat, 20 Jan 2024 05:49:06 -0500 Subject: [PATCH] Add pre_build_script support - Add `pre_build_script` support, similar to `post_build_script`. - For backwards compatibility with existing `zmake.json` files, `context.config.get("pre_build_script", "")` is called instead of `context.config["post_build_script"]` to avoid errors if `"pre_build_script"` is undefined. - Expand both `pre_build_script` and `post_build_script` contents with `os.path.expanduser` to expand `~` into the user's home directory. - Fix a typo in the README. --- README.md | 2 +- zmake/project_build.py | 10 +++++++++- zmake/zmake.json | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index faaf1be..81b3dbd 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ cd zmake # Create and activate venv python3.10 -m venv venv -source venv/bin/active +source venv/bin/activate # Install deps and build pip install -r requirements.txt diff --git a/zmake/project_build.py b/zmake/project_build.py index c6abfd2..bcf1496 100644 --- a/zmake/project_build.py +++ b/zmake/project_build.py @@ -22,6 +22,14 @@ ] +@build_handler("Pre-build command") +def post_build(context: ZMakeContext): + if context.config.get("pre_build_script", "") == "": + return + + subprocess.Popen([os.path.expanduser(context.config["pre_build_script"]), str(context.path)]).wait() + + @build_handler("Prepare") def prepare(context: ZMakeContext): path_build = context.path / "build" @@ -385,4 +393,4 @@ def post_build(context: ZMakeContext): if context.config["post_build_script"] == "": return - subprocess.Popen([context.config["post_build_script"], str(context.path)]).wait() + subprocess.Popen([os.path.expanduser(context.config["post_build_script"]), str(context.path)]).wait() diff --git a/zmake/zmake.json b/zmake/zmake.json index ef4aa92..61bd15f 100644 --- a/zmake/zmake.json +++ b/zmake/zmake.json @@ -20,6 +20,7 @@ "with_adb": false, "adb_path": "/storage/emulated/0/Android/data/com.xiaomi.hm.health/files/watch_skin_local", + "pre_build_script": "", "post_build_script": "", "common_files": [],