diff options
Diffstat (limited to 'lib/python/qmk/cli')
| -rw-r--r-- | lib/python/qmk/cli/generate/community_modules.py | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/lib/python/qmk/cli/generate/community_modules.py b/lib/python/qmk/cli/generate/community_modules.py index 61e24077d3..1f37b760ca 100644 --- a/lib/python/qmk/cli/generate/community_modules.py +++ b/lib/python/qmk/cli/generate/community_modules.py | |||
| @@ -278,33 +278,32 @@ def generate_community_modules_c(cli): | |||
| 278 | dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True) | 278 | dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True) |
| 279 | 279 | ||
| 280 | 280 | ||
| 281 | def _generate_include_per_module(cli, include_file_name): | ||
| 282 | """Generates C code to include "<module_path>/include_file_name" for each module.""" | ||
| 283 | if cli.args.output and cli.args.output.name == '-': | ||
| 284 | cli.args.output = None | ||
| 285 | |||
| 286 | lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE] | ||
| 287 | |||
| 288 | for module in get_modules(cli.args.keyboard, cli.args.filename): | ||
| 289 | full_path = f'{find_module_path(module)}/{include_file_name}' | ||
| 290 | lines.append('') | ||
| 291 | lines.append(f'#if __has_include("{full_path}")') | ||
| 292 | lines.append(f'#include "{full_path}"') | ||
| 293 | lines.append(f'#endif // __has_include("{full_path}")') | ||
| 294 | |||
| 295 | dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True) | ||
| 296 | |||
| 297 | |||
| 281 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') | 298 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') |
| 282 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | 299 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
| 283 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate community_modules.c for.') | 300 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate community_modules_introspection.h for.') |
| 284 | @cli.argument('filename', nargs='?', type=qmk.path.FileType('r'), arg_only=True, completer=FilesCompleter('.json'), help='Configurator JSON file') | 301 | @cli.argument('filename', nargs='?', type=qmk.path.FileType('r'), arg_only=True, completer=FilesCompleter('.json'), help='Configurator JSON file') |
| 285 | @cli.subcommand('Creates a community_modules_introspection.h from a keymap.json file.') | 302 | @cli.subcommand('Creates a community_modules_introspection.h from a keymap.json file.') |
| 286 | def generate_community_modules_introspection_h(cli): | 303 | def generate_community_modules_introspection_h(cli): |
| 287 | """Creates a community_modules_introspection.h from a keymap.json file | 304 | """Creates a community_modules_introspection.h from a keymap.json file |
| 288 | """ | 305 | """ |
| 289 | if cli.args.output and cli.args.output.name == '-': | 306 | _generate_include_per_module(cli, 'introspection.h') |
| 290 | cli.args.output = None | ||
| 291 | |||
| 292 | lines = [ | ||
| 293 | GPL2_HEADER_C_LIKE, | ||
| 294 | GENERATED_HEADER_C_LIKE, | ||
| 295 | '', | ||
| 296 | ] | ||
| 297 | |||
| 298 | modules = get_modules(cli.args.keyboard, cli.args.filename) | ||
| 299 | if len(modules) > 0: | ||
| 300 | for module in modules: | ||
| 301 | module_path = find_module_path(module) | ||
| 302 | lines.append(f'#if __has_include("{module_path}/introspection.h")') | ||
| 303 | lines.append(f'#include "{module_path}/introspection.h"') | ||
| 304 | lines.append(f'#endif // __has_include("{module_path}/introspection.h")') | ||
| 305 | lines.append('') | ||
| 306 | |||
| 307 | dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True) | ||
| 308 | 307 | ||
| 309 | 308 | ||
| 310 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') | 309 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') |
| @@ -315,22 +314,26 @@ def generate_community_modules_introspection_h(cli): | |||
| 315 | def generate_community_modules_introspection_c(cli): | 314 | def generate_community_modules_introspection_c(cli): |
| 316 | """Creates a community_modules_introspection.c from a keymap.json file | 315 | """Creates a community_modules_introspection.c from a keymap.json file |
| 317 | """ | 316 | """ |
| 318 | if cli.args.output and cli.args.output.name == '-': | 317 | _generate_include_per_module(cli, 'introspection.c') |
| 319 | cli.args.output = None | ||
| 320 | 318 | ||
| 321 | lines = [ | ||
| 322 | GPL2_HEADER_C_LIKE, | ||
| 323 | GENERATED_HEADER_C_LIKE, | ||
| 324 | '', | ||
| 325 | ] | ||
| 326 | 319 | ||
| 327 | modules = get_modules(cli.args.keyboard, cli.args.filename) | 320 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') |
| 328 | if len(modules) > 0: | 321 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
| 329 | for module in modules: | 322 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate led_matrix_community_modules.inc for.') |
| 330 | module_path = find_module_path(module) | 323 | @cli.argument('filename', nargs='?', type=qmk.path.FileType('r'), arg_only=True, completer=FilesCompleter('.json'), help='Configurator JSON file') |
| 331 | lines.append(f'#if __has_include("{module_path}/introspection.c")') | 324 | @cli.subcommand('Creates an led_matrix_community_modules.inc from a keymap.json file.') |
| 332 | lines.append(f'#include "{module_path}/introspection.c"') | 325 | def generate_led_matrix_community_modules_inc(cli): |
| 333 | lines.append(f'#endif // __has_include("{module_path}/introspection.c")') | 326 | """Creates an led_matrix_community_modules.inc from a keymap.json file |
| 334 | lines.append('') | 327 | """ |
| 328 | _generate_include_per_module(cli, 'led_matrix_module.inc') | ||
| 335 | 329 | ||
| 336 | dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True) | 330 | |
| 331 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') | ||
| 332 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | ||
| 333 | @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate rgb_matrix_community_modules.inc for.') | ||
| 334 | @cli.argument('filename', nargs='?', type=qmk.path.FileType('r'), arg_only=True, completer=FilesCompleter('.json'), help='Configurator JSON file') | ||
| 335 | @cli.subcommand('Creates an rgb_matrix_community_modules.inc from a keymap.json file.') | ||
| 336 | def generate_rgb_matrix_community_modules_inc(cli): | ||
| 337 | """Creates an rgb_matrix_community_modules.inc from a keymap.json file | ||
| 338 | """ | ||
| 339 | _generate_include_per_module(cli, 'rgb_matrix_module.inc') | ||
