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 json
  5. import os
  6. import sys
  7. import subprocess
  8. from argparse import FileType
  9. from milc import cli
  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 = json.load(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. qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers'])
  29. cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
  30. # Compile the keymap
  31. command = ['make', ':'.join((user_keymap['keyboard'], user_keymap['keymap']))]
  32. elif cli.config.compile.keyboard and cli.config.compile.keymap:
  33. # Generate the make command for a specific keyboard/keymap.
  34. command = ['make', ':'.join((cli.config.compile.keyboard, cli.config.compile.keymap))]
  35. else:
  36. cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`.')
  37. return False
  38. cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
  39. subprocess.run(command)