aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Brassel <[email protected]>2024-11-14 20:43:23 +1100
committerGitHub <[email protected]>2024-11-14 20:43:23 +1100
commita8a47c40114c72a042516c1f93384f228685eb3e (patch)
tree5cd8e67f0ea37b628e2647fb89db3a7799635637
parent4757ef281f5cb52668134dfc0b1c8c03445ec2ae (diff)
downloadqmk_firmware-a8a47c40114c72a042516c1f93384f228685eb3e.tar.gz
qmk_firmware-a8a47c40114c72a042516c1f93384f228685eb3e.zip
Perform test compiles during `qmk doctor`. (#24282)
Co-authored-by: James Young <[email protected]>
-rw-r--r--lib/python/qmk/cli/doctor/check.py62
1 files changed, 60 insertions, 2 deletions
diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py
index d563811aba..2804a1d7df 100644
--- a/lib/python/qmk/cli/doctor/check.py
+++ b/lib/python/qmk/cli/doctor/check.py
@@ -4,6 +4,8 @@ from enum import Enum
import re
import shutil
from subprocess import DEVNULL, TimeoutExpired
+from tempfile import TemporaryDirectory
+from pathlib import Path
from milc import cli
from qmk import submodules
@@ -44,7 +46,35 @@ 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 CheckStatus.OK # Right now all known arm versions are ok
+ # Right now all known ARM versions are ok, so check that it can produce binaries
+ return _check_arm_gcc_installation()
+
+
+def _check_arm_gcc_installation():
+ """Returns OK if the arm-none-eabi-gcc is fully installed and can produce binaries.
+ """
+ with TemporaryDirectory() as temp_dir:
+ temp_file = Path(temp_dir) / 'test.elf'
+
+ args = ['arm-none-eabi-gcc', '-mcpu=cortex-m0', '-mthumb', '-mno-thumb-interwork', '--specs=nosys.specs', '--specs=nano.specs', '-x', 'c', '-o', str(temp_file), '-']
+ result = cli.run(args, stdin=None, stdout=None, stderr=None, input='#include <newlib.h>\nint main() { return __NEWLIB__ * __NEWLIB_MINOR__ * __NEWLIB_PATCHLEVEL__; }')
+ if result.returncode == 0:
+ cli.log.info('Successfully compiled using arm-none-eabi-gcc')
+ else:
+ cli.log.error(f'Failed to compile a simple program with arm-none-eabi-gcc, return code {result.returncode}')
+ cli.log.error(f'Command: {" ".join(args)}')
+ return CheckStatus.ERROR
+
+ args = ['arm-none-eabi-size', str(temp_file)]
+ result = cli.run(args, stdin=None, stdout=None, stderr=None)
+ if result.returncode == 0:
+ cli.log.info('Successfully tested arm-none-eabi-binutils using arm-none-eabi-size')
+ else:
+ cli.log.error(f'Failed to execute arm-none-eabi-size, perhaps corrupt arm-none-eabi-binutils, return code {result.returncode}')
+ cli.log.error(f'Command: {" ".join(args)}')
+ return CheckStatus.ERROR
+
+ return CheckStatus.OK
def _check_avr_gcc_version():
@@ -53,7 +83,35 @@ def _check_avr_gcc_version():
version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
cli.log.info('Found avr-gcc version %s', version_number)
- return CheckStatus.OK
+ # Right now all known AVR versions are ok, so check that it can produce binaries
+ return _check_avr_gcc_installation()
+
+
+def _check_avr_gcc_installation():
+ """Returns OK if the avr-gcc is fully installed and can produce binaries.
+ """
+ with TemporaryDirectory() as temp_dir:
+ temp_file = Path(temp_dir) / 'test.elf'
+
+ args = ['avr-gcc', '-mmcu=atmega32u4', '-x', 'c', '-o', str(temp_file), '-']
+ result = cli.run(args, stdin=None, stdout=None, stderr=None, input='int main() { return 0; }')
+ if result.returncode == 0:
+ cli.log.info('Successfully compiled using avr-gcc')
+ else:
+ cli.log.error(f'Failed to compile a simple program with avr-gcc, return code {result.returncode}')
+ cli.log.error(f'Command: {" ".join(args)}')
+ return CheckStatus.ERROR
+
+ args = ['avr-size', str(temp_file)]
+ result = cli.run(args, stdin=None, stdout=None, stderr=None)
+ if result.returncode == 0:
+ cli.log.info('Successfully tested avr-binutils using avr-size')
+ else:
+ cli.log.error(f'Failed to execute avr-size, perhaps corrupt avr-binutils, return code {result.returncode}')
+ cli.log.error(f'Command: {" ".join(args)}')
+ return CheckStatus.ERROR
+
+ return CheckStatus.OK
def _check_avrdude_version():