compile.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Compile a QMK Firmware.
  2. You can compile a keymap already in the repo or using a QMK Configurator export.
  3. """
  4. from argcomplete.completers import FilesCompleter
  5. from milc import cli
  6. import qmk.path
  7. from qmk.decorators import automagic_keyboard, automagic_keymap
  8. from qmk.commands import do_compile
  9. from qmk.keyboard import keyboard_completer, is_keyboard_target
  10. from qmk.keymap import keymap_completer
  11. from qmk.metadata import true_values, false_values
  12. @cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), completer=FilesCompleter('.json'), help='The configurator export to compile')
  13. @cli.argument('-t', '--target', help="The make target to run. By default it compiles the keyboard only.")
  14. @cli.argument('-kb', '--keyboard', type=is_keyboard_target, completer=keyboard_completer, help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.')
  15. @cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
  16. @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.")
  17. @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.")
  18. @cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter your list against info.json.")
  19. @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
  20. @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
  21. @cli.subcommand('Compile a QMK Firmware.')
  22. @automagic_keyboard
  23. @automagic_keymap
  24. def compile(cli):
  25. """Compile a QMK Firmware.
  26. If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.
  27. If a keyboard and keymap are provided this command will build a firmware based on that.
  28. """
  29. # If -f has been specified without a keyboard target, assume -kb all
  30. keyboard = cli.config.compile.keyboard or ''
  31. if cli.args.filter and not cli.args.keyboard:
  32. cli.log.debug('--filter supplied without --keyboard, assuming --keyboard all.')
  33. keyboard = 'all'
  34. if cli.args.filename and cli.args.filter:
  35. cli.log.warning('Ignoring --filter because a keymap.json was provided.')
  36. filters = {}
  37. for filter in cli.args.filter:
  38. if '=' in filter:
  39. key, value = filter.split('=', 1)
  40. if value in true_values:
  41. value = True
  42. elif value in false_values:
  43. value = False
  44. elif value.isdigit():
  45. value = int(value)
  46. elif '.' in value and value.replace('.').isdigit():
  47. value = float(value)
  48. filters[key] = value
  49. return do_compile(keyboard, cli.config.compile.keymap, cli.config.compile.parallel, cli.config.compile.target, filters)