Skip to content

Commit

Permalink
Deprecate DEFAULT_FOLDER
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr committed Mar 14, 2024
1 parent 63dd131 commit 4453160
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 41 deletions.
17 changes: 4 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ define PARSE_RULE
$$(eval $$(call PARSE_TEST))
# If the rule starts with the name of a known keyboard, then continue
# the parsing from PARSE_KEYBOARD
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(shell $(QMK_BIN) list-keyboards --no-resolve-defaults)),true)
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(shell $(QMK_BIN) list-keyboards)),true)
KEYBOARD_RULE=$$(MATCHED_ITEM)
$$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
else
Expand Down Expand Up @@ -172,15 +172,6 @@ define PARSE_KEYBOARD

# KEYBOARD_FOLDERS := $$(subst /, , $(CURRENT_KB))

DEFAULT_FOLDER := $$(CURRENT_KB)

# We assume that every rules.mk will contain the full default value
$$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/rules.mk)
ifneq ($$(DEFAULT_FOLDER),$$(CURRENT_KB))
$$(eval include $(ROOT_DIR)/keyboards/$$(DEFAULT_FOLDER)/rules.mk)
endif
CURRENT_KB := $$(DEFAULT_FOLDER)

# 5/4/3/2/1
KEYBOARD_FOLDER_PATH_1 := $$(CURRENT_KB)
KEYBOARD_FOLDER_PATH_2 := $$(patsubst %/,%,$$(dir $$(KEYBOARD_FOLDER_PATH_1)))
Expand Down Expand Up @@ -242,7 +233,7 @@ endef
# if we are going to compile all keyboards, match the rest of the rule
# for each of them
define PARSE_ALL_KEYBOARDS
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(shell $(QMK_BIN) list-keyboards --no-resolve-defaults)))
$$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(shell $(QMK_BIN) list-keyboards)))
endef

# Prints a list of all known keymaps for the given keyboard
Expand Down Expand Up @@ -434,15 +425,15 @@ git-submodules: git-submodule

.PHONY: list-keyboards
list-keyboards:
$(QMK_BIN) list-keyboards --no-resolve-defaults | tr '\n' ' '
$(QMK_BIN) list-keyboards | tr '\n' ' '

.PHONY: list-tests
list-tests:
$(eval $(call LIST_TEST))

.PHONY: generate-keyboards-file
generate-keyboards-file:
$(QMK_BIN) list-keyboards --no-resolve-defaults
$(QMK_BIN) list-keyboards

.PHONY: clean
clean:
Expand Down
1 change: 1 addition & 0 deletions data/mappings/info_rules.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
// Items we want flagged in lint
"CTPC": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"},
"CONVERT_TO_PROTON_C": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"},
"DEFAULT_FOLDER": {"info_key": "_deprecated.default_folder", "deprecated": true}
"VIAL_ENABLE": {"info_key": "_invalid.vial", "invalid": true}
}
6 changes: 1 addition & 5 deletions lib/python/qmk/cli/ci/validate_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
from milc import cli

from qmk.keyboard import resolve_keyboard, keyboard_folder, keyboard_alias_definitions
from qmk.keyboard import keyboard_folder, keyboard_alias_definitions


def _safe_keyboard_folder(target):
Expand All @@ -17,10 +17,6 @@ def _target_keyboard_exists(target):
if not target:
return False

# If the target directory existed but there was no rules.mk or rules.mk was incorrectly parsed, then we can't build it.
if not resolve_keyboard(target):
return False

# If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either.
if not _safe_keyboard_folder(target):
return False
Expand Down
3 changes: 1 addition & 2 deletions lib/python/qmk/cli/list/keyboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import qmk.keyboard


@cli.argument('--no-resolve-defaults', arg_only=True, action='store_false', help='Ignore any "DEFAULT_FOLDER" within keyboards rules.mk')
@cli.subcommand("List the keyboards currently defined within QMK")
def list_keyboards(cli):
"""List the keyboards currently defined within QMK
"""
for keyboard_name in qmk.keyboard.list_keyboards(cli.args.no_resolve_defaults):
for keyboard_name in qmk.keyboard.list_keyboards():
print(keyboard_name)
4 changes: 2 additions & 2 deletions lib/python/qmk/cli/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

from milc import cli

from qmk.keyboard import keyboard_completer, keyboard_folder, resolve_keyboard
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.info import info_json, find_info_json
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import json_load


def _candidate_files(keyboard):
kb_dir = Path(resolve_keyboard(keyboard))
kb_dir = Path(keyboard)

cur_dir = Path('keyboards')
files = []
Expand Down
11 changes: 0 additions & 11 deletions lib/python/qmk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ def _validate(keyboard, info_data):
def info_json(keyboard):
"""Generate the info.json data for a specific keyboard.
"""
cur_dir = Path('keyboards')
root_rules_mk = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')

if 'DEFAULT_FOLDER' in root_rules_mk:
keyboard = root_rules_mk['DEFAULT_FOLDER']

info_data = {
'keyboard_name': str(keyboard),
'keyboard_folder': str(keyboard),
Expand Down Expand Up @@ -947,11 +941,6 @@ def find_info_json(keyboard):
keyboard_parent = keyboard_path.parent
info_jsons = [keyboard_path / 'info.json', keyboard_path / 'keyboard.json']

# Add DEFAULT_FOLDER before parents, if present
rules = rules_mk(keyboard)
if 'DEFAULT_FOLDER' in rules:
info_jsons.append(Path(rules['DEFAULT_FOLDER']) / 'info.json')

# Add in parent folders for least specific
for _ in range(5):
if keyboard_parent == base_path:
Expand Down
22 changes: 14 additions & 8 deletions lib/python/qmk/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ def __eq__(self, other):

@lru_cache(maxsize=1)
def keyboard_alias_definitions():
return json_load(Path('data/mappings/keyboard_aliases.hjson'))
data = json_load(Path('data/mappings/keyboard_aliases.hjson'))

# Add fake entries to maintain DEFAULT_FOLDER logic for CLI
for kb in list_keyboards(False):
res = _resolve_keyboard(kb)
if res != kb:
data[kb] = {'target': res}

return data


def is_all_keyboards(keyboard):
Expand Down Expand Up @@ -129,8 +137,6 @@ def keyboard_folder(keyboard):
if keyboard == last_keyboard:
break

keyboard = resolve_keyboard(keyboard)

if not qmk.path.is_keyboard(keyboard):
raise ValueError(f'Invalid keyboard: {keyboard}')

Expand All @@ -142,7 +148,7 @@ def keyboard_aliases(keyboard):
Includes the keyboard itself.
"""
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
aliases = keyboard_alias_definitions()

if keyboard in aliases:
keyboard = aliases[keyboard].get('target', keyboard)
Expand Down Expand Up @@ -188,13 +194,13 @@ def list_keyboards(resolve_defaults=True):

found = map(_find_name, paths)
if resolve_defaults:
found = map(resolve_keyboard, found)
found = map(_resolve_keyboard, found)

return sorted(set(found))


@lru_cache(maxsize=None)
def resolve_keyboard(keyboard):
def _resolve_keyboard(keyboard):
cur_dir = Path('keyboards')
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
while 'DEFAULT_FOLDER' in rules and keyboard != rules['DEFAULT_FOLDER']:
Expand All @@ -214,7 +220,7 @@ def config_h(keyboard):
"""
config = {}
cur_dir = Path('keyboards')
keyboard = Path(resolve_keyboard(keyboard))
keyboard = Path(keyboard)

for dir in keyboard.parts:
cur_dir = cur_dir / dir
Expand All @@ -233,7 +239,7 @@ def rules_mk(keyboard):
a dictionary representing the content of the entire rules.mk tree for a keyboard
"""
cur_dir = Path('keyboards')
keyboard = Path(resolve_keyboard(keyboard))
keyboard = Path(keyboard)
rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')

for i, dir in enumerate(keyboard.parts):
Expand Down

0 comments on commit 4453160

Please sign in to comment.