2020-01-24 19:31:16 +00:00
|
|
|
"""QMK Doctor
|
2019-07-15 19:14:27 +00:00
|
|
|
|
2020-01-24 19:31:16 +00:00
|
|
|
Check out the user's QMK environment and make sure it's ready to compile.
|
2019-07-15 19:14:27 +00:00
|
|
|
"""
|
2019-08-22 06:40:24 +00:00
|
|
|
import platform
|
2019-07-15 19:14:27 +00:00
|
|
|
|
|
|
|
from milc import cli
|
2020-11-28 20:02:18 +00:00
|
|
|
from milc.questions import yesno
|
2020-01-24 19:31:16 +00:00
|
|
|
from qmk import submodules
|
2020-09-24 05:16:00 +00:00
|
|
|
from qmk.constants import QMK_FIRMWARE
|
2020-03-29 12:29:44 +00:00
|
|
|
from qmk.commands import run
|
2020-12-21 12:29:36 +00:00
|
|
|
from qmk.os_helpers import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo
|
2020-01-24 19:31:16 +00:00
|
|
|
|
|
|
|
|
2020-12-19 00:42:30 +00:00
|
|
|
def os_tests():
|
|
|
|
"""Determine our OS and run platform specific tests
|
|
|
|
"""
|
|
|
|
platform_id = platform.platform().lower()
|
|
|
|
|
|
|
|
if 'darwin' in platform_id or 'macos' in platform_id:
|
|
|
|
return os_test_macos()
|
|
|
|
elif 'linux' in platform_id:
|
|
|
|
return os_test_linux()
|
|
|
|
elif 'windows' in platform_id:
|
|
|
|
return os_test_windows()
|
|
|
|
else:
|
|
|
|
cli.log.warning('Unsupported OS detected: %s', platform_id)
|
|
|
|
return CheckStatus.WARNING
|
|
|
|
|
|
|
|
|
2020-01-24 19:31:16 +00:00
|
|
|
def os_test_linux():
|
|
|
|
"""Run the Linux specific tests.
|
|
|
|
"""
|
2021-03-18 17:24:21 +00:00
|
|
|
# Don't bother with udev on WSL, for now
|
|
|
|
if 'microsoft' in platform.uname().release.lower():
|
|
|
|
cli.log.info("Detected {fg_cyan}Linux (WSL){fg_reset}.")
|
2020-01-24 19:31:16 +00:00
|
|
|
|
2021-04-02 10:44:27 +00:00
|
|
|
# https://github.com/microsoft/WSL/issues/4197
|
2021-04-02 21:24:09 +00:00
|
|
|
if QMK_FIRMWARE.as_posix().startswith("/mnt"):
|
2021-04-02 10:44:27 +00:00
|
|
|
cli.log.warning("I/O performance on /mnt may be extremely slow.")
|
|
|
|
return CheckStatus.WARNING
|
|
|
|
|
2021-03-18 17:24:21 +00:00
|
|
|
return CheckStatus.OK
|
|
|
|
else:
|
|
|
|
cli.log.info("Detected {fg_cyan}Linux{fg_reset}.")
|
|
|
|
from qmk.os_helpers.linux import check_udev_rules
|
|
|
|
|
|
|
|
return check_udev_rules()
|
2020-01-24 19:31:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def os_test_macos():
|
|
|
|
"""Run the Mac specific tests.
|
|
|
|
"""
|
2021-04-02 10:44:27 +00:00
|
|
|
cli.log.info("Detected {fg_cyan}macOS %s{fg_reset}.", platform.mac_ver()[0])
|
2020-01-24 19:31:16 +00:00
|
|
|
|
2020-11-16 21:09:32 +00:00
|
|
|
return CheckStatus.OK
|
2020-01-24 19:31:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def os_test_windows():
|
|
|
|
"""Run the Windows specific tests.
|
|
|
|
"""
|
2021-04-02 10:44:27 +00:00
|
|
|
win32_ver = platform.win32_ver()
|
|
|
|
cli.log.info("Detected {fg_cyan}Windows %s (%s){fg_reset}.", win32_ver[0], win32_ver[1])
|
2020-01-24 19:31:16 +00:00
|
|
|
|
2020-11-16 21:09:32 +00:00
|
|
|
return CheckStatus.OK
|
2020-01-24 19:31:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.')
|
|
|
|
@cli.argument('-n', '--no', action='store_true', arg_only=True, help='Answer no to all questions.')
|
2019-09-22 20:25:33 +00:00
|
|
|
@cli.subcommand('Basic QMK environment checks')
|
|
|
|
def doctor(cli):
|
2019-07-15 19:14:27 +00:00
|
|
|
"""Basic QMK environment checks.
|
|
|
|
|
|
|
|
This is currently very simple, it just checks that all the expected binaries are on your system.
|
|
|
|
|
|
|
|
TODO(unclaimed):
|
|
|
|
* [ ] Compile a trivial program with each compiler
|
|
|
|
"""
|
2019-08-22 16:38:10 +00:00
|
|
|
cli.log.info('QMK Doctor is checking your environment.')
|
2021-04-02 10:44:27 +00:00
|
|
|
cli.log.info('QMK home: {fg_cyan}%s', QMK_FIRMWARE)
|
2019-08-22 16:38:10 +00:00
|
|
|
|
2020-12-19 00:42:30 +00:00
|
|
|
status = os_tests()
|
2019-08-22 16:38:10 +00:00
|
|
|
|
2020-12-20 14:46:01 +00:00
|
|
|
# Make sure our QMK home is a Git repo
|
|
|
|
git_ok = check_git_repo()
|
|
|
|
|
|
|
|
if git_ok == CheckStatus.WARNING:
|
|
|
|
cli.log.warning("QMK home does not appear to be a Git repository! (no .git folder)")
|
|
|
|
status = CheckStatus.WARNING
|
|
|
|
|
2020-01-24 19:31:16 +00:00
|
|
|
# Make sure the basic CLI tools we need are available and can be executed.
|
|
|
|
bin_ok = check_binaries()
|
|
|
|
|
|
|
|
if not bin_ok:
|
|
|
|
if yesno('Would you like to install dependencies?', default=True):
|
2020-03-29 12:29:44 +00:00
|
|
|
run(['util/qmk_install.sh'])
|
2020-01-24 19:31:16 +00:00
|
|
|
bin_ok = check_binaries()
|
|
|
|
|
|
|
|
if bin_ok:
|
|
|
|
cli.log.info('All dependencies are installed.')
|
2019-07-15 19:14:27 +00:00
|
|
|
else:
|
2020-11-16 21:09:32 +00:00
|
|
|
status = CheckStatus.ERROR
|
2020-01-24 19:31:16 +00:00
|
|
|
|
2020-03-08 16:21:45 +00:00
|
|
|
# Make sure the tools are at the correct version
|
2020-12-21 12:29:36 +00:00
|
|
|
ver_ok = check_binary_versions()
|
2020-11-16 21:09:32 +00:00
|
|
|
if CheckStatus.ERROR in ver_ok:
|
|
|
|
status = CheckStatus.ERROR
|
|
|
|
elif CheckStatus.WARNING in ver_ok and status == CheckStatus.OK:
|
|
|
|
status = CheckStatus.WARNING
|
2020-03-08 16:21:45 +00:00
|
|
|
|
2020-01-24 19:31:16 +00:00
|
|
|
# Check out the QMK submodules
|
|
|
|
sub_ok = check_submodules()
|
|
|
|
|
2020-11-16 21:09:32 +00:00
|
|
|
if sub_ok == CheckStatus.OK:
|
2020-01-24 19:31:16 +00:00
|
|
|
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()
|
|
|
|
|
2021-02-16 17:45:05 +00:00
|
|
|
if sub_ok == CheckStatus.ERROR:
|
2020-11-16 21:09:32 +00:00
|
|
|
status = CheckStatus.ERROR
|
2021-02-16 17:45:05 +00:00
|
|
|
elif sub_ok == CheckStatus.WARNING and status == CheckStatus.OK:
|
2020-11-16 21:09:32 +00:00
|
|
|
status = CheckStatus.WARNING
|
2019-07-15 19:14:27 +00:00
|
|
|
|
2019-08-22 16:38:10 +00:00
|
|
|
# Report a summary of our findings to the user
|
2020-11-16 21:09:32 +00:00
|
|
|
if status == CheckStatus.OK:
|
2019-07-15 19:14:27 +00:00
|
|
|
cli.log.info('{fg_green}QMK is ready to go')
|
2020-11-16 21:09:32 +00:00
|
|
|
return 0
|
|
|
|
elif status == CheckStatus.WARNING:
|
|
|
|
cli.log.info('{fg_yellow}QMK is ready to go, but minor problems were found')
|
|
|
|
return 1
|
2019-08-22 06:40:24 +00:00
|
|
|
else:
|
2020-11-16 21:09:32 +00:00
|
|
|
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
|