Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for qmk compile -kb all. #22022

Merged
merged 8 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/python/qmk/cli/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import qmk.path
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.keymap import keymap_completer, locate_keymap


Expand Down Expand Up @@ -40,6 +40,13 @@ def compile(cli):

If a keyboard and keymap are provided this command will build a firmware based on that.
"""
if is_all_keyboards(cli.args.keyboard):
from qmk.cli.mass_compile import mass_compile
cli.args.builds = []
cli.args.filter = []
cli.args.no_temp = False
return mass_compile(cli)

# Build the environment vars
envs = build_environment(cli.args.env)

Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import qmk.path
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json, build_environment
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.keymap import keymap_completer, locate_keymap
from qmk.flashers import flasher

Expand Down Expand Up @@ -89,6 +89,11 @@ def flash(cli):

If bootloader is omitted the make system will use the configured bootloader for that keyboard.
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False
tzarc marked this conversation as resolved.
Show resolved Hide resolved

if cli.args.filename and cli.args.filename.suffix in ['.bin', '.hex', '.uf2']:
return _flash_binary(cli.args.filename, cli.args.mcu)

Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/autocorrect_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

from qmk.commands import dump_lines
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.keymap import keymap_completer, locate_keymap
from qmk.path import normpath

Expand Down Expand Up @@ -256,6 +256,11 @@ def to_hex(b: int) -> str:
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
@cli.subcommand('Generate the autocorrection data file from a dictionary file.')
def generate_autocorrect_data(cli):
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

autocorrections = parse_file(cli.args.filename)
trie = make_trie(autocorrections)
data = serialize_trie(autocorrections, trie)
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/compilation_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from qmk.commands import create_make_command
from qmk.constants import QMK_FIRMWARE
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.keymap import keymap_completer


Expand Down Expand Up @@ -90,6 +90,11 @@ def generate_compilation_database(cli: MILC) -> Union[bool, int]:

https://clang.llvm.org/docs/JSONCompilationDatabase.html
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

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.
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/config_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from qmk.info import info_json
from qmk.json_schema import json_load
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.commands import dump_lines, parse_configurator_json
from qmk.path import normpath, FileType
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
Expand Down Expand Up @@ -173,6 +173,11 @@ def generate_led_animations_config(led_feature_json, config_h_lines, prefix):
def generate_config_h(cli):
"""Generates the info_config.h file.
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

# Determine our keyboard/keymap
if cli.args.filename:
user_keymap = parse_configurator_json(cli.args.filename)
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/info_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from qmk.info import info_json
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import compile_schema_store
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.path import is_keyboard, normpath


Expand Down Expand Up @@ -55,6 +55,11 @@ def strip_info_json(kb_info_json):
def generate_info_json(cli):
"""Generate an info.json file for a keyboard
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

# Determine our keyboard(s)
if not cli.config.generate_info_json.keyboard:
cli.log.error('Missing parameter: --keyboard')
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/keyboard_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qmk.info import info_json
from qmk.commands import dump_lines
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.path import normpath
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE

Expand Down Expand Up @@ -64,6 +64,11 @@ def _gen_led_config(info_data):
def generate_keyboard_c(cli):
"""Generates the keyboard.h file.
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

kb_info_json = info_json(cli.args.keyboard)

# Build the layouts.h file.
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/keyboard_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from qmk.path import normpath
from qmk.info import info_json
from qmk.commands import dump_lines
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.constants import COL_LETTERS, ROW_LETTERS, GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE


Expand Down Expand Up @@ -101,6 +101,11 @@ def _generate_keycodes(kb_info_json):
def generate_keyboard_h(cli):
"""Generates the keyboard.h file.
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

# Build the info.json file
kb_info_json = info_json(cli.args.keyboard)

Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/make_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from argcomplete.completers import FilesCompleter

from qmk.commands import dump_lines
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.keymap import keymap_completer, locate_keymap
from qmk.path import normpath, FileType

Expand All @@ -20,6 +20,11 @@
def generate_make_dependencies(cli):
"""Generates the list of dependent info.json, rules.mk, and config.h files for a keyboard.
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

interesting_files = [
'info.json',
'rules.mk',
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/generate/rules_mk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from qmk.info import info_json
from qmk.json_schema import json_load
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keyboard import keyboard_completer, keyboard_folder, is_all_keyboards
from qmk.commands import dump_lines, parse_configurator_json
from qmk.path import normpath, FileType
from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE
Expand Down Expand Up @@ -49,6 +49,11 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
def generate_rules_mk(cli):
"""Generates a rules.mk file from info.json.
"""
if is_all_keyboards(cli.args.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

converter = None
# Determine our keyboard/keymap
if cli.args.filename:
Expand Down
7 changes: 6 additions & 1 deletion lib/python/qmk/cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from qmk.json_encoders import InfoJSONEncoder
from qmk.constants import COL_LETTERS, ROW_LETTERS
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.keyboard import keyboard_completer, keyboard_folder, render_layouts, render_layout, rules_mk
from qmk.keyboard import keyboard_completer, keyboard_folder, render_layouts, render_layout, rules_mk, is_all_keyboards
from qmk.info import info_json, keymap_json
from qmk.keymap import locate_keymap
from qmk.path import is_keyboard
Expand Down Expand Up @@ -174,6 +174,11 @@ def print_parsed_rules_mk(keyboard_name):
def info(cli):
"""Compile an info.json for a particular keyboard and pretty-print it.
"""
if is_all_keyboards(cli.config.info.keyboard):
cli.log.error('You must specify a single keyboard.')
cli.print_help()
return False

# Determine our keyboard(s)
if not cli.config.info.keyboard:
cli.log.error('Missing parameter: --keyboard')
Expand Down
24 changes: 24 additions & 0 deletions lib/python/qmk/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,29 @@
},
}


class AllKeyboards:
"""Represents all keyboards.
"""
def __str__(self):
return 'all'

def __repr__(self):
return 'all'

def __eq__(self, other):
return isinstance(other, AllKeyboards)


base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep


def is_all_keyboards(keyboard):
"""Returns True if the keyboard is an AllKeyboards object.
"""
return isinstance(keyboard, AllKeyboards)


def find_keyboard_from_dir():
"""Returns a keyboard name based on the user's current directory.
"""
Expand Down Expand Up @@ -68,7 +88,11 @@ def keyboard_folder(keyboard):
"""Returns the actual keyboard folder.

This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard.
If the supplied argument is "all", it returns an AllKeyboards object.
"""
if keyboard == 'all':
return AllKeyboards()

tzarc marked this conversation as resolved.
Show resolved Hide resolved
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))

if keyboard in aliases:
Expand Down