summaryrefslogtreecommitdiff
path: root/tools/gen_presets.py
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-07-02 18:18:52 +0700
committerhathach <[email protected]>2025-07-02 18:18:52 +0700
commitcf3966efd9fc552d641ea1e76e5aaad3ace3afd2 (patch)
treed59add439dcbfcd6e2cd9fec9aaecc413e5b5509 /tools/gen_presets.py
parentf10467e711017fb05a6e0ee496e451e2e8834549 (diff)
parent963971c6aa14411f0cc6f0c4f727d199c738e2a5 (diff)
Merge branch 'master' into fork/HiFiPhile/dcd_notif
Diffstat (limited to 'tools/gen_presets.py')
-rwxr-xr-xtools/gen_presets.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/tools/gen_presets.py b/tools/gen_presets.py
new file mode 100755
index 000000000..94b8d16b0
--- /dev/null
+++ b/tools/gen_presets.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+import os
+import json
+from pathlib import Path
+
+def main():
+ board_list = []
+
+ # Find all board.cmake files
+ for root, dirs, files in os.walk("hw/bsp"):
+ for file in files:
+ if file == "board.cmake":
+ board_list.append(os.path.basename(root))
+
+ print('Generating presets for the following boards:')
+ print(board_list)
+
+ # Generate the presets
+ presets = {}
+ presets['version'] = 6
+
+ # Configure presets
+ presets['configurePresets'] = [
+ {"name": "default",
+ "hidden": True,
+ "description": r"Configure preset for the ${presetName} board",
+ "generator": "Ninja Multi-Config",
+ "binaryDir": r"${sourceDir}/build/${presetName}",
+ "cacheVariables": {
+ "CMAKE_DEFAULT_BUILD_TYPE": "RelWithDebInfo",
+ "BOARD": r"${presetName}"
+ }}]
+
+ presets['configurePresets'].extend(
+ sorted(
+ [
+ {
+ 'name': board,
+ 'inherits': 'default'
+ }
+ for board in board_list
+ ], key=lambda x: x['name']
+ )
+ )
+
+ # Build presets
+ # no inheritance since 'name' doesn't support macro expansion
+ presets['buildPresets'] = sorted(
+ [
+ {
+ 'name': board,
+ 'description': "Build preset for the " + board + " board",
+ 'configurePreset': board
+ }
+ for board in board_list
+ ], key=lambda x: x['name']
+ )
+
+ # Workflow presets
+ presets['workflowPresets'] = sorted(
+ [
+ {
+ "name": board,
+ "steps": [
+ {
+ "type": "configure",
+ "name": board
+ },
+ {
+ "type": "build",
+ "name": board
+ }
+ ]
+ }
+ for board in board_list
+ ], key=lambda x: x['name']
+ )
+
+ path_boardpresets = "hw/bsp/BoardPresets.json"
+ with open(path_boardpresets, "w") as f:
+ f.write('{}\n'.format(json.dumps(presets, indent=2)))
+
+ # Generate presets for examples
+ presets = {
+ "version": 6,
+ "include": [
+ ]
+ }
+
+ example_list = []
+ for root, dirs, files in os.walk("examples"):
+ for file in files:
+ # Filter out ESP-IDF CMakeLists.txt in src folder
+ if file == "CMakeLists.txt" and os.path.basename(root) != 'src':
+ presets['include'] = [os.path.relpath(path_boardpresets, root).replace(os.sep, '/')]
+ with open(os.path.join(root, 'CMakePresets.json'), 'w') as f:
+ f.write('{}\n'.format(json.dumps(presets, indent=2)))
+ example_list.append(os.path.basename(root))
+
+ print('Generating presets for the following examples:')
+ print(example_list)
+
+
+if __name__ == "__main__":
+ main()