diff options
| author | Zach White <skullydazed@gmail.com> | 2020-12-30 10:27:37 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-30 10:27:37 -0800 |
| commit | 47b9b110097a864d6ab76516b2213afd59948527 (patch) | |
| tree | 44c4e034c71b361af0cf865b735e09162bbc9656 /lib/python/qmk/cli/generate/rules_mk.py | |
| parent | f231f24ddaac9781201a4ec9d0171c65af788839 (diff) | |
| download | qmk_firmware-47b9b110097a864d6ab76516b2213afd59948527.tar.gz qmk_firmware-47b9b110097a864d6ab76516b2213afd59948527.zip | |
Configure keyboard matrix from info.json (#10817)
* Make parameters from info.json available to the build system
* move all clueboard settings to info.json
* code formatting
* make flake8 happy
* make flake8 happy
* make qmk lint happy
* Add support for specifying led indicators in json
* move led indicators to the clueboard info.json
* Apply suggestions from code review
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
* add missing docstring
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk/cli/generate/rules_mk.py')
| -rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py new file mode 100755 index 000000000..4268ae047 --- /dev/null +++ b/lib/python/qmk/cli/generate/rules_mk.py | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | """Used by the make system to generate a rules.mk | ||
| 2 | """ | ||
| 3 | from milc import cli | ||
| 4 | |||
| 5 | from qmk.decorators import automagic_keyboard, automagic_keymap | ||
| 6 | from qmk.info import info_json | ||
| 7 | from qmk.path import is_keyboard, normpath | ||
| 8 | |||
| 9 | |||
| 10 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') | ||
| 11 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | ||
| 12 | @cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.') | ||
| 13 | @cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) | ||
| 14 | @automagic_keyboard | ||
| 15 | @automagic_keymap | ||
| 16 | def generate_rules_mk(cli): | ||
| 17 | """Generates a rules.mk file from info.json. | ||
| 18 | """ | ||
| 19 | # Determine our keyboard(s) | ||
| 20 | if not cli.config.generate_rules_mk.keyboard: | ||
| 21 | cli.log.error('Missing paramater: --keyboard') | ||
| 22 | cli.subcommands['info'].print_help() | ||
| 23 | return False | ||
| 24 | |||
| 25 | if not is_keyboard(cli.config.generate_rules_mk.keyboard): | ||
| 26 | cli.log.error('Invalid keyboard: "%s"', cli.config.generate_rules_mk.keyboard) | ||
| 27 | return False | ||
| 28 | |||
| 29 | # Build the info.json file | ||
| 30 | kb_info_json = info_json(cli.config.generate_rules_mk.keyboard) | ||
| 31 | rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', ''] | ||
| 32 | |||
| 33 | # Find features that should be enabled | ||
| 34 | if 'features' in kb_info_json: | ||
| 35 | for feature, enabled in kb_info_json['features'].items(): | ||
| 36 | feature = feature.upper() | ||
| 37 | enabled = 'yes' if enabled else 'no' | ||
| 38 | rules_mk_lines.append(f'{feature}_ENABLE := {enabled}') | ||
| 39 | |||
| 40 | # Add community layouts | ||
| 41 | if 'community_layouts' in kb_info_json: | ||
| 42 | rules_mk_lines.append(f'LAYOUTS = {" ".join(kb_info_json["community_layouts"])}') | ||
| 43 | |||
| 44 | # Show the results | ||
| 45 | rules_mk = '\n'.join(rules_mk_lines) + '\n' | ||
| 46 | |||
| 47 | if cli.args.output: | ||
| 48 | cli.args.output.parent.mkdir(parents=True, exist_ok=True) | ||
| 49 | if cli.args.output.exists(): | ||
| 50 | cli.args.output.replace(cli.args.output.name + '.bak') | ||
| 51 | cli.args.output.write_text(rules_mk) | ||
| 52 | |||
| 53 | if cli.args.quiet: | ||
| 54 | print(cli.args.output) | ||
| 55 | else: | ||
| 56 | cli.log.info('Wrote info_config.h to %s.', cli.args.output) | ||
| 57 | |||
| 58 | else: | ||
| 59 | print(rules_mk) | ||
