Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate make dependency file during build for info.json's etc. #20451

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Generate make dependency file during build for info.json's etc.
  • Loading branch information
tzarc committed May 14, 2023
commit 0f92a0819a11e1d1425a5e33a59959c2c3025327
9 changes: 9 additions & 0 deletions builddefs/build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ $(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES)

generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.c $(KEYBOARD_OUTPUT)/src/default_keyboard.h

generated-files: $(KEYMAP_OUTPUT)/src/info_deps.d

$(KEYMAP_OUTPUT)/src/info_deps.d:
@$(SILENT) || printf "$(MSG_GENERATING) $@" | $(AWK_CMD)
$(eval CMD=$(QMK_BIN) generate-make-dependencies -kb $(KEYBOARD) -km $(KEYMAP) -o $(KEYMAP_OUTPUT)/src/info_deps.d)
@$(BUILD_CMD)

-include $(KEYMAP_OUTPUT)/src/info_deps.d

.INTERMEDIATE : generated-files

# Userspace setup and definitions
Expand Down
1 change: 1 addition & 0 deletions lib/python/qmk/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'qmk.cli.generate.keyboard_h',
'qmk.cli.generate.keycodes',
'qmk.cli.generate.keycodes_tests',
'qmk.cli.generate.make_dependencies',
'qmk.cli.generate.rgb_breathe_table',
'qmk.cli.generate.rules_mk',
'qmk.cli.generate.version_h',
Expand Down
56 changes: 56 additions & 0 deletions lib/python/qmk/cli/generate/make_dependencies.py
Original file line number Diff line number Diff line change
@@ -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])