summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2023-05-15 22:10:42 +1000
committerNick Brassel <nick@tzarc.org>2023-05-15 22:10:42 +1000
commit433dc6068603e61d466e755aedcea0be96664f95 (patch)
treee243523f9cf99d630d566f172359434818aea62f /lib/python/qmk/cli/generate
parentdba0f1d452f138d0ed44fe2f096cfe80e610fb32 (diff)
parent507e32b28c5067fb01cb85c3259a50bec7ec1907 (diff)
Merge remote-tracking branch 'upstream/master' into develop
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-xlib/python/qmk/cli/generate/make_dependencies.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/generate/make_dependencies.py b/lib/python/qmk/cli/generate/make_dependencies.py
new file mode 100755
index 0000000000..635c341897
--- /dev/null
+++ b/lib/python/qmk/cli/generate/make_dependencies.py
@@ -0,0 +1,56 @@
+"""Used by the make system to generate dependency lists for each of the generated files.
+"""
+from pathlib import Path
+from milc import cli
+
+from argcomplete.completers import FilesCompleter
+
+from qmk.commands import dump_lines
+from qmk.constants import QMK_FIRMWARE
+from qmk.keyboard import keyboard_completer, keyboard_folder
+from qmk.keymap import keymap_completer, locate_keymap
+from qmk.path import normpath, FileType
+
+
+@cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON.')
+@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
+@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
+@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate dependency file for.')
+@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
+@cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True)
+def generate_make_dependencies(cli):
+ """Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard.
+ """
+ interesting_files = [
+ 'info.json',
+ 'keymap.json',
+ 'rules.mk',
+ 'post_rules.mk',
+ 'config.h',
+ 'post_config.h',
+ ]
+
+ found_files = []
+
+ # Walk up the keyboard's directory tree looking for the files we're interested in
+ keyboards_root = Path('keyboards')
+ parent_path = Path('keyboards') / cli.args.keyboard
+ while parent_path != keyboards_root:
+ for file in interesting_files:
+ test_path = parent_path / file
+ if test_path.exists():
+ found_files.append(test_path)
+ parent_path = parent_path.parent
+
+ # Find the keymap and include any of the interesting files
+ if cli.args.keymap is not None:
+ km = locate_keymap(cli.args.keyboard, cli.args.keymap)
+ if km is not None:
+ for file in interesting_files:
+ found_files.extend(km.parent.glob(f'**/{file}'))
+
+ # If we have a matching userspace, include those too
+ for file in interesting_files:
+ found_files.extend((QMK_FIRMWARE / 'users' / cli.args.keymap).glob(f'**/{file}'))
+
+ dump_lines(cli.args.output, [f'generated-files: {found.resolve()}\n' for found in found_files])