Merge remote-tracking branch 'upstream/develop' into xap

This commit is contained in:
Nick Brassel
2024-05-02 20:48:16 +10:00
833 changed files with 20096 additions and 3668 deletions
@@ -25,7 +25,6 @@ def system_libs(binary: str) -> List[Path]:
"""Find the system include directory that the given build tool uses.
"""
cli.log.debug("searching for system library directory for binary: %s", binary)
bin_path = shutil.which(binary)
# Actually query xxxxxx-gcc to find its include paths.
if binary.endswith("gcc") or binary.endswith("g++"):
@@ -37,7 +36,31 @@ def system_libs(binary: str) -> List[Path]:
paths.append(Path(line.strip()).resolve())
return paths
return list(Path(bin_path).resolve().parent.parent.glob("*/include")) if bin_path else []
return list(Path(binary).resolve().parent.parent.glob("*/include")) if binary else []
@lru_cache(maxsize=10)
def cpu_defines(binary: str, compiler_args: str) -> List[str]:
cli.log.debug("gathering definitions for compilation: %s %s", binary, compiler_args)
if binary.endswith("gcc") or binary.endswith("g++"):
invocation = [binary, '-dM', '-E']
if binary.endswith("gcc"):
invocation.extend(['-x', 'c'])
elif binary.endswith("g++"):
invocation.extend(['-x', 'c++'])
compiler_args = shlex.split(compiler_args)
invocation.extend(compiler_args)
invocation.append('-')
result = cli.run(invocation, capture_output=True, check=True, stdin=None, input='\n')
define_args = []
for line in result.stdout.splitlines():
line_args = line.split(' ', 2)
if len(line_args) == 3 and line_args[0] == '#define':
define_args.append(f'-D{line_args[1]}={line_args[2]}')
elif len(line_args) == 2 and line_args[0] == '#define':
define_args.append(f'-D{line_args[1]}')
return list(sorted(set(define_args)))
return []
file_re = re.compile(r'printf "Compiling: ([^"]+)')
@@ -68,9 +91,12 @@ def parse_make_n(f: Iterator[str]) -> List[Dict[str, str]]:
# we have a hit!
this_cmd = m.group(1)
args = shlex.split(this_cmd)
for s in system_libs(args[0]):
binary = shutil.which(args[0])
compiler_args = set(filter(lambda x: x.startswith('-m') or x.startswith('-f'), args))
for s in system_libs(binary):
args += ['-isystem', '%s' % s]
new_cmd = ' '.join(shlex.quote(s) for s in args if s != '-mno-thumb-interwork')
args.extend(cpu_defines(binary, ' '.join(shlex.quote(s) for s in compiler_args)))
new_cmd = ' '.join(shlex.quote(s) for s in args)
records.append({"directory": str(QMK_FIRMWARE.resolve()), "command": new_cmd, "file": this_file})
state = 'start'
+15 -20
View File
@@ -6,9 +6,9 @@ from milc import cli
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.info import info_json
from qmk.keyboard import keyboard_completer, list_keyboards
from qmk.keyboard import keyboard_completer, keyboard_folder_or_all, is_all_keyboards, list_keyboards
from qmk.keymap import locate_keymap, list_keymaps
from qmk.path import is_keyboard, keyboard
from qmk.path import keyboard
from qmk.git import git_get_ignored_files
from qmk.c_parse import c_source_files
@@ -198,39 +198,34 @@ def keyboard_check(kb):
@cli.argument('--strict', action='store_true', help='Treat warnings as errors')
@cli.argument('-kb', '--keyboard', completer=keyboard_completer, help='Comma separated list of keyboards to check')
@cli.argument('-kb', '--keyboard', action='append', type=keyboard_folder_or_all, completer=keyboard_completer, help='Keyboard to check. May be passed multiple times.')
@cli.argument('-km', '--keymap', help='The keymap to check')
@cli.argument('--all-kb', action='store_true', arg_only=True, help='Check all keyboards')
@cli.argument('--all-km', action='store_true', arg_only=True, help='Check all keymaps')
@cli.subcommand('Check keyboard and keymap for common mistakes.')
@automagic_keyboard
@automagic_keymap
def lint(cli):
"""Check keyboard and keymap for common mistakes.
"""
failed = []
# Determine our keyboard list
if cli.args.all_kb:
if cli.args.keyboard:
cli.log.warning('Both --all-kb and --keyboard passed, --all-kb takes precedence.')
keyboard_list = list_keyboards()
elif not cli.config.lint.keyboard:
cli.log.error('Missing required arguments: --keyboard or --all-kb')
if not cli.config.lint.keyboard:
cli.log.error('Missing required arguments: --keyboard')
cli.print_help()
return False
if isinstance(cli.config.lint.keyboard, str):
# if provided via config - string not array
keyboard_list = [cli.config.lint.keyboard]
elif is_all_keyboards(cli.args.keyboard[0]):
keyboard_list = list_keyboards()
else:
keyboard_list = cli.config.lint.keyboard.split(',')
keyboard_list = cli.config.lint.keyboard
failed = []
# Lint each keyboard
for kb in keyboard_list:
if not is_keyboard(kb):
cli.log.error('No such keyboard: %s', kb)
continue
# Determine keymaps to also check
if cli.args.all_km:
if cli.args.keymap == 'all':
keymaps = list_keymaps(kb)
elif cli.config.lint.keymap:
keymaps = {cli.config.lint.keymap}
+2
View File
@@ -101,6 +101,8 @@ def find_keyboard_from_dir():
keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1
current_path = current_path.parents[keymap_index]
current_path = resolve_keyboard(current_path)
if qmk.path.is_keyboard(current_path):
return str(current_path)