logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

make_dependencies.py (2586B)


  1. """Used by the make system to generate dependency lists for each of the generated files.
  2. """
  3. from pathlib import Path
  4. from milc import cli
  5. from argcomplete.completers import FilesCompleter
  6. from qmk.commands import dump_lines
  7. from qmk.keyboard import keyboard_completer, keyboard_folder
  8. from qmk.keymap import keymap_completer, locate_keymap
  9. from qmk.path import normpath, FileType, unix_style_path
  10. @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON.')
  11. @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
  12. @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
  13. @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate dependency file for.')
  14. @cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
  15. @cli.subcommand('Generates the list of dependencies associated with a keyboard build and its generated files.', hidden=True)
  16. def generate_make_dependencies(cli):
  17. """Generates the list of dependent config files for a keyboard.
  18. """
  19. interesting_files = [
  20. 'info.json',
  21. 'keyboard.json',
  22. 'rules.mk',
  23. 'post_rules.mk',
  24. 'config.h',
  25. 'post_config.h',
  26. ]
  27. check_files = []
  28. # Walk up the keyboard's directory tree looking for the files we're interested in
  29. keyboards_root = Path('keyboards')
  30. parent_path = Path('keyboards') / cli.args.keyboard
  31. while parent_path != keyboards_root:
  32. for file in interesting_files:
  33. check_files.append(parent_path / file)
  34. parent_path = parent_path.parent
  35. # Find the keymap and include any of the interesting files
  36. if cli.args.keymap is not None:
  37. km = locate_keymap(cli.args.keyboard, cli.args.keymap)
  38. if km is not None:
  39. # keymap.json is only valid for the keymap, so check this one separately
  40. check_files.append(km.parent / 'keymap.json')
  41. # Add all the interesting files
  42. for file in interesting_files:
  43. check_files.append(km.parent / file)
  44. # If we have a matching userspace, include those too
  45. for file in interesting_files:
  46. check_files.append(Path('users') / cli.args.keymap / file)
  47. dump_lines(cli.args.output, [f'generated-files: $(wildcard {unix_style_path(found)})\n' for found in check_files])