make_dependencies.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  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 info.json, rules.mk, and config.h files for a keyboard.
  18. """
  19. interesting_files = [
  20. 'info.json',
  21. 'rules.mk',
  22. 'post_rules.mk',
  23. 'config.h',
  24. 'post_config.h',
  25. ]
  26. check_files = []
  27. # Walk up the keyboard's directory tree looking for the files we're interested in
  28. keyboards_root = Path('keyboards')
  29. parent_path = Path('keyboards') / cli.args.keyboard
  30. while parent_path != keyboards_root:
  31. for file in interesting_files:
  32. check_files.append(parent_path / file)
  33. parent_path = parent_path.parent
  34. # Find the keymap and include any of the interesting files
  35. if cli.args.keymap is not None:
  36. km = locate_keymap(cli.args.keyboard, cli.args.keymap)
  37. if km is not None:
  38. # keymap.json is only valid for the keymap, so check this one separately
  39. check_files.append(km.parent / 'keymap.json')
  40. # Add all the interesting files
  41. for file in interesting_files:
  42. check_files.append(km.parent / file)
  43. # If we have a matching userspace, include those too
  44. for file in interesting_files:
  45. check_files.append(Path('users') / cli.args.keymap / file)
  46. dump_lines(cli.args.output, [f'generated-files: $(wildcard {found})\n' for found in check_files])