summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-04-06 17:59:06 +0200
committerxengineering <me@xengineering.eu>2025-04-06 17:59:06 +0200
commit867755129e5c50f4e35bc34d5818c2397f3f09db (patch)
tree72758147e7fe1a10a2202b9fdbd487d587524502
parent84ab791be78c4f2014a78b09305c5c332b5383e3 (diff)
downloadiot-contact-867755129e5c50f4e35bc34d5818c2397f3f09db.tar
iot-contact-867755129e5c50f4e35bc34d5818c2397f3f09db.tar.zst
iot-contact-867755129e5c50f4e35bc34d5818c2397f3f09db.zip
tools: Use argparse for build scripts
This makes them re-usable for the application and native_sim firmwares.
-rw-r--r--fw/btl/meson.build17
-rwxr-xr-xtools/build_zephyr.py47
-rwxr-xr-xtools/configure_zephyr.py59
3 files changed, 77 insertions, 46 deletions
diff --git a/fw/btl/meson.build b/fw/btl/meson.build
index cedd11d..b64fd40 100644
--- a/fw/btl/meson.build
+++ b/fw/btl/meson.build
@@ -3,13 +3,13 @@ external_project = import('unstable-external_project')
external_project.add_project(
configure_zephyr,
configure_options: [
- bootloader_firmware,
- meson.current_build_dir() / 'build',
- board,
- zephyr,
- ';'.join(zephyr_modules),
- meson.current_source_dir() / 'bootloader.conf',
- signing_key,
+ '--source-tree', bootloader_firmware,
+ '--build-tree', meson.current_build_dir() / 'build',
+ '--board', board,
+ '--zephyr-base', zephyr,
+ '--zephyr-modules', ';'.join(zephyr_modules),
+ '--extra-config', meson.current_source_dir() / 'bootloader.conf',
+ '--signing-key', signing_key,
],
verbose: true,
)
@@ -18,7 +18,8 @@ bootloader = custom_target('bootloader',
output: ['bootloader.bin'],
command: [
build_zephyr,
- meson.current_build_dir() / 'build',
+ '--build-tree', meson.current_build_dir() / 'build',
+ '--target-name', 'bootloader.bin',
],
build_by_default: true,
install: true,
diff --git a/tools/build_zephyr.py b/tools/build_zephyr.py
index c99727e..e201bac 100755
--- a/tools/build_zephyr.py
+++ b/tools/build_zephyr.py
@@ -6,29 +6,42 @@
# obtain one at https://mozilla.org/MPL/2.0/.
+import argparse
import multiprocessing
import shutil
import subprocess
-import sys
import pathlib
-build_tree = pathlib.Path(sys.argv[1])
-output_dir = build_tree.parent
+def main() -> None:
+ parser = argparse.ArgumentParser(
+ description="Build a Zephyr GNU Make build",
+ )
+ parser.add_argument("-B", "--build-tree", required=True)
+ parser.add_argument("-n", "--target-name", required=True)
-subprocess.run(
- [
- "make",
- f"-j{multiprocessing.cpu_count()}",
- "-C",
- f"{str(build_tree)}",
- ],
- shell=False,
- check=True,
-)
+ args = parser.parse_args()
-shutil.copy(
- build_tree / "zephyr" / "zephyr.bin",
- output_dir / "bootloader.bin"
-)
+ build_tree = pathlib.Path(args.build_tree)
+ output_dir = build_tree.parent
+
+ subprocess.run(
+ [
+ "make",
+ f"-j{multiprocessing.cpu_count()}",
+ "-C",
+ f"{str(build_tree)}",
+ ],
+ shell=False,
+ check=True,
+ )
+
+ shutil.copy(
+ build_tree / "zephyr" / "zephyr.bin",
+ output_dir / args.target_name
+ )
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/configure_zephyr.py b/tools/configure_zephyr.py
index fa1fc5d..e709063 100755
--- a/tools/configure_zephyr.py
+++ b/tools/configure_zephyr.py
@@ -6,30 +6,47 @@
# obtain one at https://mozilla.org/MPL/2.0/.
+import argparse
import subprocess
-import sys
-source_tree = sys.argv[1]
-build_tree = sys.argv[2]
-board = sys.argv[3]
-zephyr_base = sys.argv[4]
-zephyr_modules = sys.argv[5]
-extra_conf_file = sys.argv[6]
-signing_key_file = sys.argv[7]
+def main() -> None:
+ parser = argparse.ArgumentParser(
+ description="Configure a Zephyr CMake build",
+ )
+ parser.add_argument("-S", "--source-tree", required=True)
+ parser.add_argument("-B", "--build-tree", required=True)
+ parser.add_argument("-b", "--board", required=True)
+ parser.add_argument("-z", "--zephyr-base", required=True)
+ parser.add_argument("-m", "--zephyr-modules", required=False)
+ parser.add_argument("-c", "--extra-config", required=False)
+ parser.add_argument("-k", "--signing-key", required=False)
+ parser.add_argument("--prefix", required=False)
+ parser.add_argument("--libdir", required=False)
+ parser.add_argument("--bindir", required=False)
-subprocess.run(
- [
+ args = parser.parse_args()
+
+ command = [
"cmake",
- f"-S{source_tree}",
- f"-B{build_tree}",
- f"-DBOARD={board}",
- f"-DZEPHYR_BASE={zephyr_base}",
- f"-DZEPHYR_MODULES={zephyr_modules}",
- f"-DEXTRA_CONF_FILE={extra_conf_file}",
- f"-DCONFIG_BOOT_SIGNATURE_KEY_FILE=\"{signing_key_file}\""
- ],
- shell=False,
- check=True,
-)
+ f"-S{args.source_tree}",
+ f"-B{args.build_tree}",
+ f"-DBOARD={args.board}",
+ f"-DZEPHYR_BASE={args.zephyr_base}",
+ ]
+
+ if args.zephyr_modules is not None:
+ command.append(f"-DZEPHYR_MODULES={args.zephyr_modules}")
+
+ if args.extra_config is not None:
+ command.append(f"-DEXTRA_CONF_FILE={args.extra_config}")
+
+ if args.signing_key is not None:
+ command.append(f"-DCONFIG_BOOT_SIGNATURE_KEY_FILE=\"{args.signing_key}\"")
+
+ subprocess.run(command, shell=False, check=True)
+
+
+if __name__ == "__main__":
+ main()