compile.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. from qmk.commands import create_make_command
  8. from qmk.commands import parse_configurator_json
  9. from qmk.commands import compile_configurator_json
  10. import qmk.keymap
  11. import qmk.path
  12. @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), help='The configurator export to compile')
  13. @cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.')
  14. @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
  15. @cli.subcommand('Compile a QMK Firmware.')
  16. def compile(cli):
  17. """Compile a QMK Firmware.
  18. If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.
  19. FIXME(skullydazed): add code to check and warn if the keymap already exists
  20. If --keyboard and --keymap are provided this command will build a firmware based on that.
  21. """
  22. if cli.args.filename:
  23. # Parse the configurator json
  24. user_keymap = parse_configurator_json(cli.args.filename)
  25. # Generate the keymap
  26. keymap_path = qmk.path.keymap(user_keymap['keyboard'])
  27. cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)
  28. # Compile the keymap
  29. command = compile_configurator_json(cli.args.filename)
  30. cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
  31. elif cli.config.compile.keyboard and cli.config.compile.keymap:
  32. # Generate the make command for a specific keyboard/keymap.
  33. command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap)
  34. else:
  35. cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`.')
  36. return False
  37. cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
  38. subprocess.run(command)