summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
m---------lib/chibios-contrib0
-rwxr-xr-xlib/python/qmk/cli/format/json.py4
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py2
-rwxr-xr-xlib/python/qmk/cli/generate/keyboard_c.py25
-rw-r--r--lib/python/qmk/cli/git/submodule.py8
-rw-r--r--lib/python/qmk/cli/lint.py15
-rw-r--r--lib/python/qmk/cli/migrate.py5
-rw-r--r--lib/python/qmk/info.py46
8 files changed, 66 insertions, 39 deletions
diff --git a/lib/chibios-contrib b/lib/chibios-contrib
-Subproject da78eb3759b8d1779b237657c7667baa4aa95ca
+Subproject 9d7a7f904ed135e3459cf6d602db56a26872df6
diff --git a/lib/python/qmk/cli/format/json.py b/lib/python/qmk/cli/format/json.py
index 283513254c..87a3837d10 100755
--- a/lib/python/qmk/cli/format/json.py
+++ b/lib/python/qmk/cli/format/json.py
@@ -92,8 +92,8 @@ def format_json(cli):
output = json.dumps(json_data, cls=json_encoder, sort_keys=True)
if cli.args.inplace:
- with open(cli.args.json_file, 'w+', encoding='utf-8') as outfile:
- outfile.write(output)
+ with open(cli.args.json_file, 'w+', encoding='utf-8', newline='\n') as outfile:
+ outfile.write(output + '\n')
# Display the results if print was set
# We don't operate in-place by default, so also display to stdout
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py
index 00fb1d9585..fc681300a3 100755
--- a/lib/python/qmk/cli/generate/config_h.py
+++ b/lib/python/qmk/cli/generate/config_h.py
@@ -108,6 +108,8 @@ def generate_config_items(kb_info_json, config_h_lines):
elif key_type.startswith('array'):
config_h_lines.append(generate_define(config_key, f'{{ {", ".join(map(str, config_value))} }}'))
elif key_type == 'bool':
+ config_h_lines.append(generate_define(config_key, 'true' if config_value else 'false'))
+ elif key_type == 'flag':
if config_value:
config_h_lines.append(generate_define(config_key))
elif key_type == 'mapping':
diff --git a/lib/python/qmk/cli/generate/keyboard_c.py b/lib/python/qmk/cli/generate/keyboard_c.py
index f010341613..5a6c967486 100755
--- a/lib/python/qmk/cli/generate/keyboard_c.py
+++ b/lib/python/qmk/cli/generate/keyboard_c.py
@@ -9,21 +9,25 @@ from qmk.path import normpath
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
-def _gen_led_config(info_data):
+def _gen_led_configs(info_data):
+ lines = []
+
+ if 'layout' in info_data.get('rgb_matrix', {}):
+ lines.extend(_gen_led_config(info_data, 'rgb_matrix'))
+
+ if 'layout' in info_data.get('led_matrix', {}):
+ lines.extend(_gen_led_config(info_data, 'led_matrix'))
+
+ return lines
+
+
+def _gen_led_config(info_data, config_type):
"""Convert info.json content to g_led_config
"""
cols = info_data['matrix_size']['cols']
rows = info_data['matrix_size']['rows']
- config_type = None
- if 'layout' in info_data.get('rgb_matrix', {}):
- config_type = 'rgb_matrix'
- elif 'layout' in info_data.get('led_matrix', {}):
- config_type = 'led_matrix'
-
lines = []
- if not config_type:
- return lines
matrix = [['NO_LED'] * cols for _ in range(rows)]
pos = []
@@ -53,6 +57,7 @@ def _gen_led_config(info_data):
lines.append(f' {{ {", ".join(flags)} }},')
lines.append('};')
lines.append('#endif')
+ lines.append('')
return lines
@@ -98,7 +103,7 @@ def generate_keyboard_c(cli):
# Build the layouts.h file.
keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '']
- keyboard_h_lines.extend(_gen_led_config(kb_info_json))
+ keyboard_h_lines.extend(_gen_led_configs(kb_info_json))
keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json))
# Show the results
diff --git a/lib/python/qmk/cli/git/submodule.py b/lib/python/qmk/cli/git/submodule.py
index ef116ea124..1cbfd74e88 100644
--- a/lib/python/qmk/cli/git/submodule.py
+++ b/lib/python/qmk/cli/git/submodule.py
@@ -1,8 +1,8 @@
import shutil
+from pathlib import Path
from milc import cli
-from qmk.path import normpath
from qmk import submodules
REMOVE_DIRS = [
@@ -40,12 +40,12 @@ def git_submodule(cli):
remove_dirs = REMOVE_DIRS
if cli.config.git_submodule.force:
# Also trash everything that isnt marked as "safe"
- for path in normpath('lib').iterdir():
+ for path in Path('lib').iterdir():
if not any(ignore in path.as_posix() for ignore in IGNORE_DIRS):
remove_dirs.append(path)
- for folder in map(normpath, remove_dirs):
- if normpath(folder).is_dir():
+ for folder in map(Path, remove_dirs):
+ if folder.is_dir():
print(f"Removing '{folder}'")
shutil.rmtree(folder)
diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py
index a7c85b5643..7ebb0cf9c4 100644
--- a/lib/python/qmk/cli/lint.py
+++ b/lib/python/qmk/cli/lint.py
@@ -13,6 +13,7 @@ from qmk.git import git_get_ignored_files
from qmk.c_parse import c_source_files
CHIBIOS_CONF_CHECKS = ['chconf.h', 'halconf.h', 'mcuconf.h', 'board.h']
+INVALID_KB_FEATURES = set(['encoder_map', 'dip_switch_map', 'combo', 'tap_dance', 'via'])
def _list_defaultish_keymaps(kb):
@@ -69,6 +70,17 @@ def _handle_json_errors(kb, info):
return ok
+def _handle_invalid_features(kb, info):
+ """Check for features that should never be enabled at the keyboard level
+ """
+ ok = True
+ features = set(info.get('features', []))
+ for found in features & INVALID_KB_FEATURES:
+ ok = False
+ cli.log.error(f'{kb}: Invalid keyboard level feature detected - {found}')
+ return ok
+
+
def _chibios_conf_includenext_check(target):
"""Check the ChibiOS conf.h for the correct inclusion of the next conf.h
"""
@@ -154,6 +166,9 @@ def keyboard_check(kb):
ok = False
# Additional checks
+ if not _handle_invalid_features(kb, kb_info):
+ ok = False
+
rules_mk_assignment_errors = _rules_mk_assignment_only(kb)
if rules_mk_assignment_errors:
ok = False
diff --git a/lib/python/qmk/cli/migrate.py b/lib/python/qmk/cli/migrate.py
index c1b1ad1ea9..0bab5c1949 100644
--- a/lib/python/qmk/cli/migrate.py
+++ b/lib/python/qmk/cli/migrate.py
@@ -47,9 +47,12 @@ def migrate(cli):
files = _candidate_files(cli.args.keyboard)
# Filter down keys if requested
- keys = info_map.keys()
+ keys = list(filter(lambda key: info_map[key].get("to_json", True), info_map.keys()))
if cli.args.filter:
keys = list(set(keys) & set(cli.args.filter))
+ rejected = set(cli.args.filter) - set(keys)
+ for key in rejected:
+ cli.log.info(f'{{fg_yellow}}Skipping {key} as migration not possible...')
cli.log.info(f'{{fg_green}}Migrating keyboard {{fg_cyan}}{cli.args.keyboard}{{fg_green}}.{{fg_reset}}')
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index d42ba5c660..13588abdb8 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -233,6 +233,9 @@ def _extract_features(info_data, rules):
key = '_'.join(key.split('_')[:-1]).lower()
value = True if value.lower() in true_values else False if value.lower() in false_values else value
+ if key in ['lto']:
+ continue
+
if 'config_h_features' not in info_data:
info_data['config_h_features'] = {}
@@ -524,6 +527,9 @@ def _config_to_json(key_type, config_value):
"""Convert config value using spec
"""
if key_type.startswith('array'):
+ if key_type.count('.') > 1:
+ raise Exception(f"Conversion of {key_type} not possible")
+
if '.' in key_type:
key_type, array_type = key_type.split('.', 1)
else:
@@ -536,7 +542,7 @@ def _config_to_json(key_type, config_value):
else:
return list(map(str.strip, config_value.split(',')))
- elif key_type == 'bool':
+ elif key_type in ['bool', 'flag']:
if isinstance(config_value, bool):
return config_value
return config_value in true_values
@@ -706,27 +712,23 @@ def _extract_led_config(info_data, keyboard):
cols = info_data['matrix_size']['cols']
rows = info_data['matrix_size']['rows']
- # Determine what feature owns g_led_config
- features = info_data.get("features", {})
- feature = None
- if features.get("rgb_matrix", False):
- feature = "rgb_matrix"
- elif features.get("led_matrix", False):
- feature = "led_matrix"
-
- if feature:
- # Process
- for file in find_keyboard_c(keyboard):
- try:
- ret = find_led_config(file, cols, rows)
- if ret:
- info_data[feature] = info_data.get(feature, {})
- info_data[feature]["layout"] = ret
- except Exception as e:
- _log_warning(info_data, f'led_config: {file.name}: {e}')
-
- if info_data[feature].get("layout", None) and not info_data[feature].get("led_count", None):
- info_data[feature]["led_count"] = len(info_data[feature]["layout"])
+ for feature in ['rgb_matrix', 'led_matrix']:
+ if info_data.get('features', {}).get(feature, False) or feature in info_data:
+
+ # Only attempt search if dd led config is missing
+ if 'layout' not in info_data.get(feature, {}):
+ # Process
+ for file in find_keyboard_c(keyboard):
+ try:
+ ret = find_led_config(file, cols, rows)
+ if ret:
+ info_data[feature] = info_data.get(feature, {})
+ info_data[feature]['layout'] = ret
+ except Exception as e:
+ _log_warning(info_data, f'led_config: {file.name}: {e}')
+
+ if info_data[feature].get('layout', None) and not info_data[feature].get('led_count', None):
+ info_data[feature]['led_count'] = len(info_data[feature]['layout'])
return info_data