1
0
Fork 0

CLI refactoring for common build target APIs (#22221)

This commit is contained in:
Nick Brassel 2023-11-15 16:24:54 +11:00 committed by GitHub
parent c4d3521ba6
commit 4938210711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 296 additions and 285 deletions

View file

@ -12,7 +12,7 @@ from typing import Dict, Iterator, List, Union
from milc import cli, MILC
from qmk.commands import create_make_command
from qmk.commands import find_make
from qmk.constants import QMK_FIRMWARE
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.keyboard import keyboard_completer, keyboard_folder
@ -76,9 +76,12 @@ def parse_make_n(f: Iterator[str]) -> List[Dict[str, str]]:
return records
def write_compilation_database(keyboard: str, keymap: str, output_path: Path) -> bool:
def write_compilation_database(keyboard: str = None, keymap: str = None, output_path: Path = QMK_FIRMWARE / 'compile_commands.json', skip_clean: bool = False, command: List[str] = None, **env_vars) -> bool:
# Generate the make command for a specific keyboard/keymap.
command = create_make_command(keyboard, keymap, dry_run=True)
if not command:
from qmk.build_targets import KeyboardKeymapBuildTarget # Lazy load due to circular references
target = KeyboardKeymapBuildTarget(keyboard, keymap)
command = target.compile_command(dry_run=True, **env_vars)
if not command:
cli.log.error('You must supply both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.')
@ -90,9 +93,10 @@ def write_compilation_database(keyboard: str, keymap: str, output_path: Path) ->
env.pop("MAKEFLAGS", None)
# re-use same executable as the main make invocation (might be gmake)
clean_command = [command[0], 'clean']
cli.log.info('Making clean with {fg_cyan}%s', ' '.join(clean_command))
cli.run(clean_command, capture_output=False, check=True, env=env)
if not skip_clean:
clean_command = [find_make(), "clean"]
cli.log.info('Making clean with {fg_cyan}%s', ' '.join(clean_command))
cli.run(clean_command, capture_output=False, check=True, env=env)
cli.log.info('Gathering build instructions from {fg_cyan}%s', ' '.join(command))