diff options
author | Nick Brassel <nick@tzarc.org> | 2023-09-28 20:48:58 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-28 11:48:58 +0100 |
commit | fb0c64a567b6dd2536aae0c2df56a915ffa72404 (patch) | |
tree | 71b94d52b854a803d726d80fb7c20d0ddc363805 /lib/python/qmk/cli/generate | |
parent | 0ecb03ad47a1ec1871537cd9fa3ea39cc60f52aa (diff) |
Allow inline generation of compile_commands.json while doing a `qmk compile`, using `--compiledb` (#21549)
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-x | lib/python/qmk/cli/generate/compilation_database.py | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 5e1a18a69b..9e5c266516 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -76,33 +76,9 @@ def parse_make_n(f: Iterator[str]) -> List[Dict[str, str]]: return records -@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard\'s name') -@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap\'s name') -@cli.subcommand('Create a compilation database.') -@automagic_keyboard -@automagic_keymap -def generate_compilation_database(cli: MILC) -> Union[bool, int]: - """Creates a compilation database for the given keyboard build. - - Does a make clean, then a make -n for this target and uses the dry-run output to create - a compilation database (compile_commands.json). This file can help some IDEs and - IDE-like editors work better. For more information about this: - - https://clang.llvm.org/docs/JSONCompilationDatabase.html - """ - command = None - # check both config domains: the magic decorator fills in `generate_compilation_database` but the user is - # more likely to have set `compile` in their config file. - current_keyboard = cli.config.generate_compilation_database.keyboard or cli.config.user.keyboard - current_keymap = cli.config.generate_compilation_database.keymap or cli.config.user.keymap - - if current_keyboard and current_keymap: - # Generate the make command for a specific keyboard/keymap. - command = create_make_command(current_keyboard, current_keymap, dry_run=True) - elif not current_keyboard: - cli.log.error('Could not determine keyboard!') - elif not current_keymap: - cli.log.error('Could not determine keymap!') +def write_compilation_database(keyboard: str, keymap: str, output_path: Path) -> bool: + # Generate the make command for a specific keyboard/keymap. + command = create_make_command(keyboard, keymap, dry_run=True) if not command: cli.log.error('You must supply both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.') @@ -128,9 +104,34 @@ def generate_compilation_database(cli: MILC) -> Union[bool, int]: cli.log.info("Found %s compile commands", len(db)) - dbpath = QMK_FIRMWARE / 'compile_commands.json' - - cli.log.info(f"Writing build database to {dbpath}") - dbpath.write_text(json.dumps(db, indent=4)) + cli.log.info(f"Writing build database to {output_path}") + output_path.write_text(json.dumps(db, indent=4)) return True + + +@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='The keyboard\'s name') +@cli.argument('-km', '--keymap', completer=keymap_completer, help='The keymap\'s name') +@cli.subcommand('Create a compilation database.') +@automagic_keyboard +@automagic_keymap +def generate_compilation_database(cli: MILC) -> Union[bool, int]: + """Creates a compilation database for the given keyboard build. + + Does a make clean, then a make -n for this target and uses the dry-run output to create + a compilation database (compile_commands.json). This file can help some IDEs and + IDE-like editors work better. For more information about this: + + https://clang.llvm.org/docs/JSONCompilationDatabase.html + """ + # check both config domains: the magic decorator fills in `generate_compilation_database` but the user is + # more likely to have set `compile` in their config file. + current_keyboard = cli.config.generate_compilation_database.keyboard or cli.config.user.keyboard + current_keymap = cli.config.generate_compilation_database.keymap or cli.config.user.keymap + + if not current_keyboard: + cli.log.error('Could not determine keyboard!') + elif not current_keymap: + cli.log.error('Could not determine keymap!') + + return write_compilation_database(current_keyboard, current_keymap, QMK_FIRMWARE / 'compile_commands.json') |