diff options
Diffstat (limited to 'lib/python/qmk/cli/generate/rules_mk.py')
| -rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 5291556109..cae9b07c3e 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py | |||
| @@ -6,12 +6,13 @@ from dotty_dict import dotty | |||
| 6 | from argcomplete.completers import FilesCompleter | 6 | from argcomplete.completers import FilesCompleter |
| 7 | from milc import cli | 7 | from milc import cli |
| 8 | 8 | ||
| 9 | from qmk.info import info_json | 9 | from qmk.info import info_json, get_modules |
| 10 | from qmk.json_schema import json_load | 10 | from qmk.json_schema import json_load |
| 11 | from qmk.keyboard import keyboard_completer, keyboard_folder | 11 | from qmk.keyboard import keyboard_completer, keyboard_folder |
| 12 | from qmk.commands import dump_lines, parse_configurator_json | 12 | from qmk.commands import dump_lines, parse_configurator_json |
| 13 | from qmk.path import normpath, FileType | 13 | from qmk.path import normpath, FileType |
| 14 | from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE | 14 | from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE |
| 15 | from qmk.community_modules import find_module_path, load_module_jsons | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | def generate_rule(rules_key, rules_value): | 18 | def generate_rule(rules_key, rules_value): |
| @@ -46,6 +47,42 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): | |||
| 46 | return generate_rule(rules_key, rules_value) | 47 | return generate_rule(rules_key, rules_value) |
| 47 | 48 | ||
| 48 | 49 | ||
| 50 | def generate_features_rules(features_dict): | ||
| 51 | lines = [] | ||
| 52 | for feature, enabled in features_dict.items(): | ||
| 53 | feature = feature.upper() | ||
| 54 | enabled = 'yes' if enabled else 'no' | ||
| 55 | lines.append(generate_rule(f'{feature}_ENABLE', enabled)) | ||
| 56 | return lines | ||
| 57 | |||
| 58 | |||
| 59 | def generate_modules_rules(keyboard, filename): | ||
| 60 | lines = [] | ||
| 61 | modules = get_modules(keyboard, filename) | ||
| 62 | if len(modules) > 0: | ||
| 63 | lines.append('') | ||
| 64 | lines.append('OPT_DEFS += -DCOMMUNITY_MODULES_ENABLE=TRUE') | ||
| 65 | for module in modules: | ||
| 66 | module_path = find_module_path(module) | ||
| 67 | if not module_path: | ||
| 68 | raise FileNotFoundError(f"Module '{module}' not found.") | ||
| 69 | lines.append('') | ||
| 70 | lines.append(f'COMMUNITY_MODULES += {module_path.name}') # use module_path here instead of module as it may be a subdirectory | ||
| 71 | lines.append(f'OPT_DEFS += -DCOMMUNITY_MODULE_{module_path.name.upper()}_ENABLE=TRUE') | ||
| 72 | lines.append(f'COMMUNITY_MODULE_PATHS += {module_path}') | ||
| 73 | lines.append(f'VPATH += {module_path}') | ||
| 74 | lines.append(f'SRC += $(wildcard {module_path}/{module_path.name}.c)') | ||
| 75 | lines.append(f'-include {module_path}/rules.mk') | ||
| 76 | |||
| 77 | module_jsons = load_module_jsons(modules) | ||
| 78 | for module_json in module_jsons: | ||
| 79 | if 'features' in module_json: | ||
| 80 | lines.append('') | ||
| 81 | lines.append(f'# Module: {module_json["module_name"]}') | ||
| 82 | lines.extend(generate_features_rules(module_json['features'])) | ||
| 83 | return lines | ||
| 84 | |||
| 85 | |||
| 49 | @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON to be compiled and flashed or a pre-compiled binary firmware file (bin/hex) to be flashed.') | 86 | @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON to be compiled and flashed or a pre-compiled binary firmware file (bin/hex) to be flashed.') |
| 50 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') | 87 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') |
| 51 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | 88 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
| @@ -80,10 +117,7 @@ def generate_rules_mk(cli): | |||
| 80 | 117 | ||
| 81 | # Iterate through features to enable/disable them | 118 | # Iterate through features to enable/disable them |
| 82 | if 'features' in kb_info_json: | 119 | if 'features' in kb_info_json: |
| 83 | for feature, enabled in kb_info_json['features'].items(): | 120 | rules_mk_lines.extend(generate_features_rules(kb_info_json['features'])) |
| 84 | feature = feature.upper() | ||
| 85 | enabled = 'yes' if enabled else 'no' | ||
| 86 | rules_mk_lines.append(generate_rule(f'{feature}_ENABLE', enabled)) | ||
| 87 | 121 | ||
| 88 | # Set SPLIT_TRANSPORT, if needed | 122 | # Set SPLIT_TRANSPORT, if needed |
| 89 | if kb_info_json.get('split', {}).get('transport', {}).get('protocol') == 'custom': | 123 | if kb_info_json.get('split', {}).get('transport', {}).get('protocol') == 'custom': |
| @@ -99,6 +133,8 @@ def generate_rules_mk(cli): | |||
| 99 | if converter: | 133 | if converter: |
| 100 | rules_mk_lines.append(generate_rule('CONVERT_TO', converter)) | 134 | rules_mk_lines.append(generate_rule('CONVERT_TO', converter)) |
| 101 | 135 | ||
| 136 | rules_mk_lines.extend(generate_modules_rules(cli.args.keyboard, cli.args.filename)) | ||
| 137 | |||
| 102 | # Show the results | 138 | # Show the results |
| 103 | dump_lines(cli.args.output, rules_mk_lines) | 139 | dump_lines(cli.args.output, rules_mk_lines) |
| 104 | 140 | ||
