summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate/rules_mk.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/generate/rules_mk.py')
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py
index ce824f6378..29a1130f99 100755
--- a/lib/python/qmk/cli/generate/rules_mk.py
+++ b/lib/python/qmk/cli/generate/rules_mk.py
@@ -9,7 +9,9 @@ from qmk.info import info_json
from qmk.json_schema import json_load, validate
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.keymap import locate_keymap
+from qmk.commands import dump_lines
from qmk.path import normpath
+from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE
def process_mapping_rule(kb_info_json, rules_key, info_dict):
@@ -55,7 +57,7 @@ def generate_rules_mk(cli):
kb_info_json = dotty(info_json(cli.args.keyboard))
info_rules_map = json_load(Path('data/mappings/info_rules.json'))
- rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', '']
+ rules_mk_lines = [GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE]
# Iterate through the info_rules map to generate basic rules
for rules_key, info_dict in info_rules_map.items():
@@ -83,14 +85,9 @@ def generate_rules_mk(cli):
rules_mk_lines.append('CUSTOM_MATRIX ?= yes')
# Show the results
- rules_mk = '\n'.join(rules_mk_lines) + '\n'
+ dump_lines(cli.args.output, rules_mk_lines)
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.parent / (cli.args.output.name + '.bak'))
- cli.args.output.write_text(rules_mk)
-
if cli.args.quiet:
if cli.args.escape:
print(cli.args.output.as_posix().replace(' ', '\\ '))
@@ -98,6 +95,3 @@ def generate_rules_mk(cli):
print(cli.args.output)
else:
cli.log.info('Wrote rules.mk to %s.', cli.args.output)
-
- else:
- print(rules_mk)