compile.py 2.1 KB

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