From 49382107115f611a61f1f5e20a3b2a92000a35da Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 15 Nov 2023 16:24:54 +1100 Subject: CLI refactoring for common build target APIs (#22221) --- lib/python/qmk/cli/generate/compilation_database.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/python/qmk/cli/generate/compilation_database.py') diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 9e5c266516..5100d2b6d2 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -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)) -- cgit v1.2.3