Merge remote-tracking branch 'origin/master' into develop

Resolved Conflicts:
    keyboards/kc60/rules.mk
    keyboards/xd96/rules.mk
    lib/python/qmk/cli/__init__.py
This commit is contained in:
Zach White 2020-11-22 08:28:53 -08:00
commit ac3b7d79e0
938 changed files with 35990 additions and 13003 deletions

View file

@ -9,6 +9,7 @@ from milc import cli
from . import c2json
from . import cformat
from . import chibios
from . import clean
from . import compile
from . import config
from . import docs
@ -19,6 +20,7 @@ from . import hello
from . import info
from . import json
from . import json2c
from . import lint
from . import list
from . import kle2json
from . import new

View file

@ -0,0 +1,16 @@
"""Clean the QMK firmware folder of build artifacts.
"""
from qmk.commands import run
from milc import cli
import shutil
@cli.argument('-a', '--all', arg_only=True, action='store_true', help='Remove *.hex and *.bin files in the QMK root as well.')
@cli.subcommand('Clean the QMK firmware folder of build artifacts.')
def clean(cli):
"""Runs `make clean` (or `make distclean` if --all is passed)
"""
make_cmd = 'gmake' if shutil.which('gmake') else 'make'
run([make_cmd, 'distclean' if cli.args.all else 'clean'])

View file

@ -7,6 +7,7 @@ import re
import shutil
import subprocess
from pathlib import Path
from enum import Enum
from milc import cli
from milc.questions import yesno
@ -14,6 +15,13 @@ from qmk import submodules
from qmk.constants import QMK_FIRMWARE
from qmk.commands import run
class CheckStatus(Enum):
OK = 1
WARNING = 2
ERROR = 3
ESSENTIAL_BINARIES = {
'dfu-programmer': {},
'avrdude': {},
@ -33,9 +41,12 @@ def _udev_rule(vid, pid=None, *args):
"""
rule = ""
if pid:
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", TAG+="uaccess", RUN{builtin}+="uaccess"' % (vid, pid)
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", TAG+="uaccess"' % (
vid,
pid,
)
else:
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", TAG+="uaccess", RUN{builtin}+="uaccess"' % vid
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", TAG+="uaccess"' % vid
if args:
rule = ', '.join([rule, *args])
return rule
@ -69,24 +80,25 @@ def check_arm_gcc_version():
version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip()
cli.log.info('Found arm-none-eabi-gcc version %s', version_number)
return True # Right now all known arm versions are ok
return CheckStatus.OK # Right now all known arm versions are ok
def check_avr_gcc_version():
"""Returns True if the avr-gcc version is not known to cause problems.
"""
rc = CheckStatus.ERROR
if 'output' in ESSENTIAL_BINARIES['avr-gcc']:
version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
cli.log.info('Found avr-gcc version %s', version_number)
rc = CheckStatus.OK
parsed_version = parse_gcc_version(version_number)
if parsed_version['major'] > 8:
cli.log.error('We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
return False
cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
rc = CheckStatus.WARNING
cli.log.info('Found avr-gcc version %s', version_number)
return True
return False
return rc
def check_avrdude_version():
@ -95,7 +107,7 @@ def check_avrdude_version():
version_number = last_line.split()[2][:-1]
cli.log.info('Found avrdude version %s', version_number)
return True
return CheckStatus.OK
def check_dfu_util_version():
@ -104,7 +116,7 @@ def check_dfu_util_version():
version_number = first_line.split()[1]
cli.log.info('Found dfu-util version %s', version_number)
return True
return CheckStatus.OK
def check_dfu_programmer_version():
@ -113,7 +125,7 @@ def check_dfu_programmer_version():
version_number = first_line.split()[1]
cli.log.info('Found dfu-programmer version %s', version_number)
return True
return CheckStatus.OK
def check_binaries():
@ -131,58 +143,56 @@ def check_binaries():
def check_submodules():
"""Iterates through all submodules to make sure they're cloned and up to date.
"""
ok = True
for submodule in submodules.status().values():
if submodule['status'] is None:
cli.log.error('Submodule %s has not yet been cloned!', submodule['name'])
ok = False
return CheckStatus.ERROR
elif not submodule['status']:
cli.log.error('Submodule %s is not up to date!', submodule['name'])
ok = False
cli.log.warning('Submodule %s is not up to date!', submodule['name'])
return CheckStatus.WARNING
return ok
return CheckStatus.OK
def check_udev_rules():
"""Make sure the udev rules look good.
"""
ok = True
rc = CheckStatus.OK
udev_dir = Path("/etc/udev/rules.d/")
desired_rules = {
'atmel-dfu': {
_udev_rule("03EB", "2FEF"), # ATmega16U2
_udev_rule("03EB", "2FF0"), # ATmega32U2
_udev_rule("03EB", "2FF3"), # ATmega16U4
_udev_rule("03EB", "2FF4"), # ATmega32U4
_udev_rule("03EB", "2FF9"), # AT90USB64
_udev_rule("03EB", "2FFB") # AT90USB128
_udev_rule("03eb", "2fef"), # ATmega16U2
_udev_rule("03eb", "2ff0"), # ATmega32U2
_udev_rule("03eb", "2ff3"), # ATmega16U4
_udev_rule("03eb", "2ff4"), # ATmega32U4
_udev_rule("03eb", "2ff9"), # AT90USB64
_udev_rule("03eb", "2ffb") # AT90USB128
},
'kiibohd': {_udev_rule("1C11", "B007")},
'kiibohd': {_udev_rule("1c11", "b007")},
'stm32': {
_udev_rule("1EAF", "0003"), # STM32duino
_udev_rule("0483", "DF11") # STM32 DFU
_udev_rule("1eaf", "0003"), # STM32duino
_udev_rule("0483", "df11") # STM32 DFU
},
'bootloadhid': {_udev_rule("16C0", "05DF")},
'usbasploader': {_udev_rule("16C0", "05DC")},
'massdrop': {_udev_rule("03EB", "6124", 'ENV{ID_MM_DEVICE_IGNORE}="1"')},
'bootloadhid': {_udev_rule("16c0", "05df")},
'usbasploader': {_udev_rule("16c0", "05dc")},
'massdrop': {_udev_rule("03eb", "6124", 'ENV{ID_MM_DEVICE_IGNORE}="1"')},
'caterina': {
# Spark Fun Electronics
_udev_rule("1B4F", "9203", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 3V3/8MHz
_udev_rule("1B4F", "9205", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 5V/16MHz
_udev_rule("1B4F", "9207", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # LilyPad 3V3/8MHz (and some Pro Micro clones)
# Pololu Electronics
_udev_rule("1FFB", "0101", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # A-Star 32U4
_udev_rule("1b4f", "9203", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 3V3/8MHz
_udev_rule("1b4f", "9205", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 5V/16MHz
_udev_rule("1b4f", "9207", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # LilyPad 3V3/8MHz (and some Pro Micro clones)
# Pololu EleCTRONICS
_udev_rule("1ffb", "0101", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # A-Star 32U4
# Arduino SA
_udev_rule("2341", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Leonardo
_udev_rule("2341", "0037", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Micro
# Adafruit Industries LLC
_udev_rule("239A", "000C", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Feather 32U4
_udev_rule("239A", "000D", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 3V3/8MHz
_udev_rule("239A", "000E", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 5V/16MHz
# dog hunter AG
_udev_rule("2A03", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Leonardo
_udev_rule("2A03", "0037", 'ENV{ID_MM_DEVICE_IGNORE}="1"') # Micro
# Adafruit INDUSTRIES llC
_udev_rule("239a", "000c", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Feather 32U4
_udev_rule("239a", "000d", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 3V3/8MHz
_udev_rule("239a", "000e", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 5V/16MHz
# dog hunter ag
_udev_rule("2a03", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Leonardo
_udev_rule("2a03", "0037", 'ENV{ID_MM_DEVICE_IGNORE}="1"') # Micro
}
}
@ -209,31 +219,43 @@ def check_udev_rules():
# Check if the desired rules are among the currently present rules
for bootloader, rules in desired_rules.items():
# For caterina, check if ModemManager is running
if bootloader == "caterina":
if check_modem_manager():
ok = False
cli.log.warn("{bg_yellow}Detected ModemManager without the necessary udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.")
if not rules.issubset(current_rules):
deprecated_rule = deprecated_rules.get(bootloader)
if deprecated_rule and deprecated_rule.issubset(current_rules):
cli.log.warn("{bg_yellow}Found old, deprecated udev rules for '%s' boards. The new rules on https://docs.qmk.fm/#/faq_build?id=linux-udev-rules offer better security with the same functionality.", bootloader)
cli.log.warning("{fg_yellow}Found old, deprecated udev rules for '%s' boards. The new rules on https://docs.qmk.fm/#/faq_build?id=linux-udev-rules offer better security with the same functionality.", bootloader)
else:
cli.log.warn("{bg_yellow}Missing udev rules for '%s' boards. See https://docs.qmk.fm/#/faq_build?id=linux-udev-rules for more details.", bootloader)
# For caterina, check if ModemManager is running
if bootloader == "caterina":
if check_modem_manager():
rc = CheckStatus.WARNING
cli.log.warning("{fg_yellow}Detected ModemManager without the necessary udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.")
rc = CheckStatus.WARNING
cli.log.warning("{fg_yellow}Missing or outdated udev rules for '%s' boards. Run 'sudo cp %s/util/udev/50-qmk.rules /etc/udev/rules.d/'.", bootloader, QMK_FIRMWARE)
return ok
else:
cli.log.warning("{fg_yellow}'%s' does not exist. Skipping udev rule checking...", udev_dir)
return rc
def check_systemd():
"""Check if it's a systemd system
"""
return bool(shutil.which("systemctl"))
def check_modem_manager():
"""Returns True if ModemManager is running.
"""
if shutil.which("systemctl"):
if check_systemd():
mm_check = run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
if mm_check.returncode == 0:
return True
else:
cli.log.warn("Can't find systemctl to check for ModemManager.")
"""(TODO): Add check for non-systemd systems
"""
return False
def is_executable(command):
@ -263,12 +285,8 @@ def os_test_linux():
"""Run the Linux specific tests.
"""
cli.log.info("Detected {fg_cyan}Linux.")
ok = True
if not check_udev_rules():
ok = False
return ok
return check_udev_rules()
def os_test_macos():
@ -276,7 +294,7 @@ def os_test_macos():
"""
cli.log.info("Detected {fg_cyan}macOS.")
return True
return CheckStatus.OK
def os_test_windows():
@ -284,7 +302,7 @@ def os_test_windows():
"""
cli.log.info("Detected {fg_cyan}Windows.")
return True
return CheckStatus.OK
@cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.')
@ -299,23 +317,20 @@ def doctor(cli):
* [ ] Compile a trivial program with each compiler
"""
cli.log.info('QMK Doctor is checking your environment.')
ok = True
status = CheckStatus.OK
# Determine our OS and run platform specific tests
platform_id = platform.platform().lower()
if 'darwin' in platform_id or 'macos' in platform_id:
if not os_test_macos():
ok = False
status = os_test_macos()
elif 'linux' in platform_id:
if not os_test_linux():
ok = False
status = os_test_linux()
elif 'windows' in platform_id:
if not os_test_windows():
ok = False
status = os_test_windows()
else:
cli.log.error('Unsupported OS detected: %s', platform_id)
ok = False
cli.log.warning('Unsupported OS detected: %s', platform_id)
status = CheckStatus.WARNING
cli.log.info('QMK home: {fg_cyan}%s', QMK_FIRMWARE)
@ -330,31 +345,41 @@ def doctor(cli):
if bin_ok:
cli.log.info('All dependencies are installed.')
else:
ok = False
status = CheckStatus.ERROR
# Make sure the tools are at the correct version
ver_ok = []
for check in (check_arm_gcc_version, check_avr_gcc_version, check_avrdude_version, check_dfu_util_version, check_dfu_programmer_version):
if not check():
ok = False
ver_ok.append(check())
if CheckStatus.ERROR in ver_ok:
status = CheckStatus.ERROR
elif CheckStatus.WARNING in ver_ok and status == CheckStatus.OK:
status = CheckStatus.WARNING
# Check out the QMK submodules
sub_ok = check_submodules()
if sub_ok:
if sub_ok == CheckStatus.OK:
cli.log.info('Submodules are up to date.')
else:
if yesno('Would you like to clone the submodules?', default=True):
submodules.update()
sub_ok = check_submodules()
if not sub_ok:
ok = False
if CheckStatus.ERROR in sub_ok:
status = CheckStatus.ERROR
elif CheckStatus.WARNING in sub_ok and status == CheckStatus.OK:
status = CheckStatus.WARNING
# Report a summary of our findings to the user
if ok:
if status == CheckStatus.OK:
cli.log.info('{fg_green}QMK is ready to go')
return 0
elif status == CheckStatus.WARNING:
cli.log.info('{fg_yellow}QMK is ready to go, but minor problems were found')
return 1
else:
cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
# FIXME(skullydazed/unclaimed): Link to a document about troubleshooting, or discord or something
return ok
cli.log.info('{fg_red}Major problems detected, please fix these problems before proceeding.')
cli.log.info('{fg_blue}Check out the FAQ (https://docs.qmk.fm/#/faq_build) or join the QMK Discord (https://discord.gg/Uq7gcHh) for help.')
return 2

View file

@ -1 +1,2 @@
from . import api
from . import docs

View file

@ -0,0 +1,37 @@
"""Build QMK documentation locally
"""
import shutil
import subprocess
from pathlib import Path
from milc import cli
DOCS_PATH = Path('docs/')
BUILD_PATH = Path('.build/docs/')
@cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True)
def generate_docs(cli):
"""Invoke the docs generation process
TODO(unclaimed):
* [ ] Add a real build step... something static docs
"""
if BUILD_PATH.exists():
shutil.rmtree(BUILD_PATH)
shutil.copytree(DOCS_PATH, BUILD_PATH)
# When not verbose we want to hide all output
args = {'check': True}
if not cli.args.verbose:
args.update({'stdout': subprocess.DEVNULL, 'stderr': subprocess.STDOUT})
cli.log.info('Generating internal docs...')
# Generate internal docs
subprocess.run(['doxygen', 'Doxyfile'], **args)
subprocess.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args)
cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH)

View file

@ -3,6 +3,7 @@
Compile an info.json for a particular keyboard and pretty-print it.
"""
import json
import platform
from milc import cli
@ -12,6 +13,8 @@ from qmk.keymap import locate_keymap
from qmk.info import info_json
from qmk.path import is_keyboard
platform_id = platform.platform().lower()
ROW_LETTERS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop'
COL_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijilmnopqrstuvwxyz'
@ -36,13 +39,13 @@ def show_keymap(kb_info_json, title_caps=True):
else:
cli.echo('{fg_cyan}layer_%s{fg_reset}:', layer_num)
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], layer))
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, layer))
def show_layouts(kb_info_json, title_caps=True):
"""Render the layouts with info.json labels.
"""
for layout_name, layout_art in render_layouts(kb_info_json).items():
for layout_name, layout_art in render_layouts(kb_info_json, cli.config.info.ascii).items():
title = layout_name.title() if title_caps else layout_name
cli.echo('{fg_cyan}%s{fg_reset}:', title)
print(layout_art) # Avoid passing dirty data to cli.echo()
@ -69,7 +72,7 @@ def show_matrix(kb_info_json, title_caps=True):
else:
cli.echo('{fg_blue}matrix_%s{fg_reset}:', layout_name)
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], labels))
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels))
def print_friendly_output(kb_info_json):
@ -124,6 +127,7 @@ def print_text_output(kb_info_json):
@cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.')
@cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.')
@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).')
@cli.argument('--ascii', action='store_true', default='windows' in platform_id, help='Render layout box drawings in ASCII only.')
@cli.subcommand('Keyboard information.')
@automagic_keyboard
@automagic_keymap
@ -132,7 +136,7 @@ def info(cli):
"""
# Determine our keyboard(s)
if not cli.config.info.keyboard:
cli.log.error('Missing paramater: --keyboard')
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['info'].print_help()
return False

View file

@ -0,0 +1,70 @@
"""Command to look over a keyboard/keymap and check for common mistakes.
"""
from milc import cli
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.info import info_json
from qmk.keymap import locate_keymap
from qmk.path import is_keyboard, keyboard
@cli.argument('--strict', action='store_true', help='Treat warnings as errors.')
@cli.argument('-kb', '--keyboard', help='The keyboard to check.')
@cli.argument('-km', '--keymap', help='The keymap to check.')
@cli.subcommand('Check keyboard and keymap for common mistakes.')
@automagic_keyboard
@automagic_keymap
def lint(cli):
"""Check keyboard and keymap for common mistakes.
"""
if not cli.config.lint.keyboard:
cli.log.error('Missing required argument: --keyboard')
cli.print_help()
return False
if not is_keyboard(cli.config.lint.keyboard):
cli.log.error('No such keyboard: %s', cli.config.lint.keyboard)
return False
# Gather data about the keyboard.
ok = True
keyboard_path = keyboard(cli.config.lint.keyboard)
keyboard_info = info_json(cli.config.lint.keyboard)
readme_path = keyboard_path / 'readme.md'
# Check for errors in the info.json
if keyboard_info['parse_errors']:
ok = False
cli.log.error('Errors found when generating info.json.')
if cli.config.lint.strict and keyboard_info['parse_warnings']:
ok = False
cli.log.error('Warnings found when generating info.json (Strict mode enabled.)')
# Check for a readme.md and warn if it doesn't exist
if not readme_path.exists():
ok = False
cli.log.error('Missing %s', readme_path)
# Keymap specific checks
if cli.config.lint.keymap:
keymap_path = locate_keymap(cli.config.lint.keyboard, cli.config.lint.keymap)
if not keymap_path:
ok = False
cli.log.error("Can't find %s keymap for %s keyboard.", cli.config.lint.keymap, cli.config.lint.keyboard)
else:
keymap_readme = keymap_path.parent / 'readme.md'
if not keymap_readme.exists():
cli.log.warning('Missing %s', keymap_readme)
if cli.config.lint.strict:
ok = False
# Check and report the overall status
if ok:
cli.log.info('Lint check passed!')
return True
cli.log.error('Lint check failed!')
return False