Skip to content

Commit

Permalink
Add gcc version detection to qmk doctor (qmk#8338)
Browse files Browse the repository at this point in the history
  • Loading branch information
skullydazed authored and jakobaa committed Jul 7, 2020
1 parent 40dcbd5 commit 069194b
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions lib/python/qmk/cli/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from qmk import submodules
from qmk.questions import yesno

ESSENTIAL_BINARIES = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc', 'bin/qmk']
ESSENTIAL_BINARIES = {
'dfu-programmer': {},
'avrdude': {},
'dfu-util': {},
'avr-gcc': {},
'arm-none-eabi-gcc': {},
'bin/qmk': {},
}
ESSENTIAL_SUBMODULES = ['lib/chibios', 'lib/lufa']


Expand All @@ -24,12 +31,42 @@ def _udev_rule(vid, pid=None):
return 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", MODE:="0666"' % vid


def check_arm_gcc_version():
"""Returns True if the arm-none-eabi-gcc version is not known to cause problems.
"""
if 'output' in ESSENTIAL_BINARIES['arm-none-eabi-gcc']:
first_line = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].split('\n')[0]
second_half = first_line.split(')', 1)[1].strip()
version_number = second_half.split()[0]
cli.log.info('Found arm-none-eabi-gcc version %s', version_number)

return True # 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.
"""
if 'output' in ESSENTIAL_BINARIES['avr-gcc']:
first_line = ESSENTIAL_BINARIES['avr-gcc']['output'].split('\n')[0]
version_number = first_line.split()[2]

major, minor, rest = version_number.split('.', 2)
if int(major) > 8:
cli.log.error('We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
return False

cli.log.info('Found avr-gcc version %s', version_number)
return True

return False


def check_binaries():
"""Iterates through ESSENTIAL_BINARIES and tests them.
"""
ok = True

for binary in ESSENTIAL_BINARIES:
for binary in sorted(ESSENTIAL_BINARIES):
if not is_executable(binary):
ok = False

Expand Down Expand Up @@ -116,7 +153,9 @@ def is_executable(command):
return False

# Make sure the command can be executed
check = subprocess.run([command, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5)
check = subprocess.run([command, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, universal_newlines=True)
ESSENTIAL_BINARIES[command]['output'] = check.stdout

if check.returncode in [0, 1]: # Older versions of dfu-programmer exit 1
cli.log.debug('Found {fg_cyan}%s', command)
return True
Expand Down Expand Up @@ -196,6 +235,13 @@ def doctor(cli):
else:
ok = False

# Make sure the tools are at the correct version
if not check_arm_gcc_version():
ok = False

if not check_avr_gcc_version():
ok = False

# Check out the QMK submodules
sub_ok = check_submodules()

Expand Down

0 comments on commit 069194b

Please sign in to comment.