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