def METHOD_NAME(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.METHOD_NAME.keyboard or cli.config.user.keyboard
    current_keymap = cli.config.METHOD_NAME.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!')
    if not command:
        cli.log.error('You must supply both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.')
        cli.echo('usage: qmk generate-compilation-database [-kb KEYBOARD] [-km KEYMAP]')
        return False
    # remove any environment variable overrides which could trip us up
    env = os.environ.copy()
    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)
    cli.log.info('Gathering build instructions from {fg_cyan}%s', ' '.join(command))
    result = cli.run(command, capture_output=True, check=True, env=env)
    db = parse_make_n(result.stdout.splitlines())
    if not db:
        cli.log.error("Failed to parse output from make output:\n%s", result.stdout)
        return False
    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))
    return True