summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate/rules_mk.py
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2020-12-30 10:27:37 -0800
committerGitHub <noreply@github.com>2020-12-30 10:27:37 -0800
commit47b9b110097a864d6ab76516b2213afd59948527 (patch)
tree44c4e034c71b361af0cf865b735e09162bbc9656 /lib/python/qmk/cli/generate/rules_mk.py
parentf231f24ddaac9781201a4ec9d0171c65af788839 (diff)
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-xlib/python/qmk/cli/generate/rules_mk.py59
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 0000000000..4268ae047b
--- /dev/null
+++ b/lib/python/qmk/cli/generate/rules_mk.py
@@ -0,0 +1,59 @@
+"""Used by the make system to generate a rules.mk
+"""
+from milc import cli
+
+from qmk.decorators import automagic_keyboard, automagic_keymap
+from qmk.info import info_json
+from qmk.path import is_keyboard, normpath
+
+
+@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
+@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
+@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.')
+@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
+@automagic_keyboard
+@automagic_keymap
+def generate_rules_mk(cli):
+ """Generates a rules.mk file from info.json.
+ """
+ # Determine our keyboard(s)
+ if not cli.config.generate_rules_mk.keyboard:
+ cli.log.error('Missing paramater: --keyboard')
+ cli.subcommands['info'].print_help()
+ return False
+
+ if not is_keyboard(cli.config.generate_rules_mk.keyboard):
+ cli.log.error('Invalid keyboard: "%s"', cli.config.generate_rules_mk.keyboard)
+ return False
+
+ # Build the info.json file
+ kb_info_json = info_json(cli.config.generate_rules_mk.keyboard)
+ rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', '']
+
+ # Find features that should be enabled
+ if 'features' in kb_info_json:
+ for feature, enabled in kb_info_json['features'].items():
+ feature = feature.upper()
+ enabled = 'yes' if enabled else 'no'
+ rules_mk_lines.append(f'{feature}_ENABLE := {enabled}')
+
+ # Add community layouts
+ if 'community_layouts' in kb_info_json:
+ rules_mk_lines.append(f'LAYOUTS = {" ".join(kb_info_json["community_layouts"])}')
+
+ # Show the results
+ rules_mk = '\n'.join(rules_mk_lines) + '\n'
+
+ if cli.args.output:
+ cli.args.output.parent.mkdir(parents=True, exist_ok=True)
+ if cli.args.output.exists():
+ cli.args.output.replace(cli.args.output.name + '.bak')
+ cli.args.output.write_text(rules_mk)
+
+ if cli.args.quiet:
+ print(cli.args.output)
+ else:
+ cli.log.info('Wrote info_config.h to %s.', cli.args.output)
+
+ else:
+ print(rules_mk)