compile.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Compile a QMK Firmware.
  2. You can compile a keymap already in the repo or using a QMK Configurator export.
  3. """
  4. import subprocess
  5. from argparse import FileType
  6. from milc import cli
  7. import qmk.path
  8. from qmk.commands import compile_configurator_json, create_make_command, find_keyboard_keymap, parse_configurator_json
  9. @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), help='The configurator export to compile')
  10. @cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.')
  11. @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
  12. @cli.subcommand('Compile a QMK Firmware.')
  13. def compile(cli):
  14. """Compile a QMK Firmware.
  15. If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.
  16. If a keyboard and keymap are provided this command will build a firmware based on that.
  17. """
  18. if cli.args.filename:
  19. # If a configurator JSON was provided skip straight to compiling it
  20. # FIXME(skullydazed): add code to check and warn if the keymap already exists when compiling a json keymap.
  21. user_keymap = parse_configurator_json(cli.args.filename)
  22. keymap_path = qmk.path.keymap(user_keymap['keyboard'])
  23. command = compile_configurator_json(user_keymap)
  24. cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
  25. else:
  26. # Perform the action the user specified
  27. user_keyboard, user_keymap = find_keyboard_keymap()
  28. if user_keyboard and user_keymap:
  29. # Generate the make command for a specific keyboard/keymap.
  30. command = create_make_command(user_keyboard, user_keymap)
  31. else:
  32. cli.log.error('You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.')
  33. cli.echo('usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]')
  34. return False
  35. cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
  36. subprocess.run(command)