Selaa lähdekoodia

Remove `DEFAULT_FOLDER` handling (#23281)

Joel Challis 1 vuosi sitten
vanhempi
sitoutus
0326355edc

+ 4 - 4
Makefile

@@ -115,7 +115,7 @@ endef
 TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND)
 
 # As TRY_TO_MATCH_RULE_FROM_LIST_HELPER, but with additional
-# resolution of DEFAULT_FOLDER and keyboard_aliases.hjson for provided rule 
+# resolution of keyboard_aliases.hjson for provided rule 
 define TRY_TO_MATCH_RULE_FROM_LIST_HELPER_KB
     # Split on ":", padding with empty strings to avoid indexing issues
     TOKEN1:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE))
@@ -255,7 +255,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
@@ -447,7 +447,7 @@ 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:
@@ -455,7 +455,7 @@ list-tests:
 
 .PHONY: generate-keyboards-file
 generate-keyboards-file:
-	$(QMK_BIN) list-keyboards --no-resolve-defaults
+	$(QMK_BIN) list-keyboards
 
 .PHONY: clean
 clean:

+ 1 - 1
data/mappings/info_rules.hjson

@@ -53,8 +53,8 @@
     "WS2812_DRIVER": {"info_key": "ws2812.driver"},
 
     // Items we want flagged in lint
-    "DEFAULT_FOLDER": {"info_key": "_deprecated.default_folder", "deprecated": true},
     "CTPC": {"info_key": "_invalid.ctpc", "invalid": true, "replace_with": "CONVERT_TO=proton_c"},
     "CONVERT_TO_PROTON_C": {"info_key": "_invalid.ctpc", "invalid": true, "replace_with": "CONVERT_TO=proton_c"},
+    "DEFAULT_FOLDER": {"info_key": "_invalid.default_folder", "invalid": true},
     "VIAL_ENABLE": {"info_key": "_invalid.vial", "invalid": true}
 }

+ 0 - 2
docs/config_options.md

@@ -364,8 +364,6 @@ This is a [make](https://www.gnu.org/software/make/manual/make.html) file that i
 
 ## Build Options
 
-* `DEFAULT_FOLDER`
-  * Used to specify a default folder when a keyboard has more than one sub-folder.
 * `FIRMWARE_FORMAT`
   * Defines which format (bin, hex) is copied to the root `qmk_firmware` folder after building.
 * `SRC`

+ 1 - 5
lib/python/qmk/cli/ci/validate_aliases.py

@@ -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):
@@ -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

+ 1 - 2
lib/python/qmk/cli/list/keyboards.py

@@ -5,10 +5,9 @@ from milc import cli
 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)

+ 2 - 2
lib/python/qmk/cli/migrate.py

@@ -6,14 +6,14 @@ from dotty_dict import dotty
 
 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 = []

+ 1 - 1
lib/python/qmk/cli/resolve_alias.py

@@ -5,7 +5,7 @@ from milc import cli
 
 @cli.argument('--allow-unknown', arg_only=True, action='store_true', help="Return original if rule is not a valid keyboard.")
 @cli.argument('keyboard', arg_only=True, help='The keyboard\'s name')
-@cli.subcommand('Resolve DEFAULT_FOLDER and any keyboard_aliases for provided rule')
+@cli.subcommand('Resolve any keyboard_aliases for provided rule')
 def resolve_alias(cli):
     try:
         print(keyboard_folder(cli.args.keyboard))

+ 0 - 11
lib/python/qmk/info.py

@@ -223,12 +223,6 @@ def _validate(keyboard, info_data):
 def info_json(keyboard, force_layout=None):
     """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),
@@ -1005,11 +999,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:

+ 8 - 26
lib/python/qmk/keyboard.py

@@ -99,8 +99,6 @@ def find_keyboard_from_dir():
             keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1
             current_path = current_path.parents[keymap_index]
 
-        current_path = resolve_keyboard(current_path)
-
         if qmk.path.is_keyboard(current_path):
             return str(current_path)
 
@@ -121,7 +119,7 @@ def find_readme(keyboard):
 def keyboard_folder(keyboard):
     """Returns the actual keyboard folder.
 
-    This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard.
+    This checks aliases to resolve the actual path for a keyboard.
     """
     aliases = keyboard_alias_definitions()
 
@@ -131,8 +129,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}')
 
@@ -158,7 +154,7 @@ def keyboard_aliases(keyboard):
 def keyboard_folder_or_all(keyboard):
     """Returns the actual keyboard folder.
 
-    This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard.
+    This checks aliases to resolve the actual path for a keyboard.
     If the supplied argument is "all", it returns an AllKeyboards object.
     """
     if keyboard == 'all':
@@ -179,32 +175,18 @@ def keyboard_completer(prefix, action, parser, parsed_args):
     return list_keyboards()
 
 
-def list_keyboards(resolve_defaults=True):
-    """Returns a list of all keyboards - optionally processing any DEFAULT_FOLDER.
+def list_keyboards():
+    """Returns a list of all keyboards
     """
     # We avoid pathlib here because this is performance critical code.
-    paths = []
-    for marker in ['rules.mk', 'keyboard.json']:
-        kb_wildcard = os.path.join(base_path, "**", marker)
-        paths += [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
+    kb_wildcard = os.path.join(base_path, "**", 'keyboard.json')
+    paths = [path for path in glob(kb_wildcard, recursive=True) if os.path.sep + 'keymaps' + os.path.sep not in path]
 
     found = map(_find_name, paths)
-    if resolve_defaults:
-        found = map(resolve_keyboard, found)
 
     return sorted(set(found))
 
 
-@lru_cache(maxsize=None)
-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']:
-        keyboard = rules['DEFAULT_FOLDER']
-        rules = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
-    return keyboard
-
-
 def config_h(keyboard):
     """Parses all the config.h files for a keyboard.
 
@@ -216,7 +198,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
@@ -235,7 +217,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):

+ 2 - 4
lib/python/qmk/path.py

@@ -21,11 +21,9 @@ def is_keyboard(keyboard_name):
     if Path(keyboard_name).is_absolute():
         return False
 
-    keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
-    rules_mk = keyboard_path / 'rules.mk'
-    keyboard_json = keyboard_path / 'keyboard.json'
+    keyboard_json = QMK_FIRMWARE / 'keyboards' / keyboard_name / 'keyboard.json'
 
-    return rules_mk.exists() or keyboard_json.exists()
+    return keyboard_json.exists()
 
 
 def under_qmk_firmware(path=Path(os.environ['ORIG_CWD'])):