summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py60
-rwxr-xr-xlib/python/qmk/cli/generate/develop_pr_list.py15
-rw-r--r--lib/python/qmk/cli/generate/dfu_header.py18
-rw-r--r--lib/python/qmk/cli/generate/docs.py16
-rwxr-xr-xlib/python/qmk/cli/generate/keyboard_h.py18
-rwxr-xr-xlib/python/qmk/cli/generate/layouts.py37
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py16
-rw-r--r--lib/python/qmk/cli/generate/version_h.py39
8 files changed, 108 insertions, 111 deletions
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py
index f16dca1de8..fdc76b23d4 100755
--- a/lib/python/qmk/cli/generate/config_h.py
+++ b/lib/python/qmk/cli/generate/config_h.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_C_LIKE, GENERATED_HEADER_C_LIKE
def direct_pins(direct_pins, postfix):
@@ -21,18 +23,7 @@ def direct_pins(direct_pins, postfix):
cols = ','.join(map(str, [col or 'NO_PIN' for col in row]))
rows.append('{' + cols + '}')
- col_count = len(direct_pins[0])
- row_count = len(direct_pins)
-
return f"""
-#ifndef MATRIX_COLS{postfix}
-# define MATRIX_COLS{postfix} {col_count}
-#endif // MATRIX_COLS{postfix}
-
-#ifndef MATRIX_ROWS{postfix}
-# define MATRIX_ROWS{postfix} {row_count}
-#endif // MATRIX_ROWS{postfix}
-
#ifndef DIRECT_PINS{postfix}
# define DIRECT_PINS{postfix} {{ {", ".join(rows)} }}
#endif // DIRECT_PINS{postfix}
@@ -42,14 +33,9 @@ def direct_pins(direct_pins, postfix):
def pin_array(define, pins, postfix):
"""Return the config.h lines that set a pin array.
"""
- pin_num = len(pins)
pin_array = ', '.join(map(str, [pin or 'NO_PIN' for pin in pins]))
return f"""
-#ifndef {define}S{postfix}
-# define {define}S{postfix} {pin_num}
-#endif // {define}S{postfix}
-
#ifndef {define}_PINS{postfix}
# define {define}_PINS{postfix} {{ {pin_array} }}
#endif // {define}_PINS{postfix}
@@ -73,6 +59,24 @@ def matrix_pins(matrix_pins, postfix=''):
return '\n'.join(pins)
+def generate_matrix_size(kb_info_json, config_h_lines):
+ """Add the matrix size to the config.h.
+ """
+ if 'matrix_pins' in kb_info_json:
+ col_count = kb_info_json['matrix_size']['cols']
+ row_count = kb_info_json['matrix_size']['rows']
+
+ config_h_lines.append(f"""
+#ifndef MATRIX_COLS
+# define MATRIX_COLS {col_count}
+#endif // MATRIX_COLS
+
+#ifndef MATRIX_ROWS
+# define MATRIX_ROWS {row_count}
+#endif // MATRIX_ROWS
+""")
+
+
def generate_config_items(kb_info_json, config_h_lines):
"""Iterate through the info_config map to generate basic config values.
"""
@@ -108,6 +112,12 @@ def generate_config_items(kb_info_json, config_h_lines):
config_h_lines.append(f'#ifndef {key}')
config_h_lines.append(f'# define {key} {value}')
config_h_lines.append(f'#endif // {key}')
+ elif key_type == 'bcd_version':
+ (major, minor, revision) = config_value.split('.')
+ config_h_lines.append('')
+ config_h_lines.append(f'#ifndef {config_key}')
+ config_h_lines.append(f'# define {config_key} 0x{major.zfill(2)}{minor}{revision}')
+ config_h_lines.append(f'#endif // {config_key}')
else:
config_h_lines.append('')
config_h_lines.append(f'#ifndef {config_key}')
@@ -173,10 +183,12 @@ def generate_config_h(cli):
kb_info_json = dotty(info_json(cli.args.keyboard))
# Build the info_config.h file.
- config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.', ' */', '', '#pragma once']
+ config_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once']
generate_config_items(kb_info_json, config_h_lines)
+ generate_matrix_size(kb_info_json, config_h_lines)
+
if 'matrix_pins' in kb_info_json:
config_h_lines.append(matrix_pins(kb_info_json['matrix_pins']))
@@ -184,16 +196,4 @@ def generate_config_h(cli):
generate_split_config(kb_info_json, config_h_lines)
# Show the results
- config_h = '\n'.join(config_h_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(config_h)
-
- if not cli.args.quiet:
- cli.log.info('Wrote info_config.h to %s.', cli.args.output)
-
- else:
- print(config_h)
+ dump_lines(cli.args.output, config_h_lines, cli.args.quiet)
diff --git a/lib/python/qmk/cli/generate/develop_pr_list.py b/lib/python/qmk/cli/generate/develop_pr_list.py
index 07e46752a6..549db5b185 100755
--- a/lib/python/qmk/cli/generate/develop_pr_list.py
+++ b/lib/python/qmk/cli/generate/develop_pr_list.py
@@ -12,6 +12,15 @@ fix_expr = re.compile(r'fix', flags=re.IGNORECASE)
clean1_expr = re.compile(r'\[(develop|keyboard|keymap|core|cli|bug|docs|feature)\]', flags=re.IGNORECASE)
clean2_expr = re.compile(r'^(develop|keyboard|keymap|core|cli|bug|docs|feature):', flags=re.IGNORECASE)
+ignored_titles = ["Format code according to conventions"]
+
+
+def _is_ignored(title):
+ for ignore in ignored_titles:
+ if ignore in title:
+ return True
+ return False
+
def _get_pr_info(cache, gh, pr_num):
pull = cache.get(f'pull:{pr_num}')
@@ -81,7 +90,9 @@ def generate_develop_pr_list(cli):
else:
normal_collection.append(info)
- if "dependencies" in commit_info['pr_labels']:
+ if _is_ignored(commit_info['title']):
+ return
+ elif "dependencies" in commit_info['pr_labels']:
fix_or_normal(commit_info, pr_list_bugs, pr_list_dependencies)
elif "core" in commit_info['pr_labels']:
fix_or_normal(commit_info, pr_list_bugs, pr_list_core)
@@ -97,7 +108,7 @@ def generate_develop_pr_list(cli):
match = git_expr.search(line)
if match:
pr_info = _get_pr_info(cache, gh, match.group("pr"))
- commit_info = {'hash': match.group("hash"), 'title': match.group("title"), 'pr_num': int(match.group("pr")), 'pr_labels': [label.name for label in pr_info.labels.items]}
+ commit_info = {'hash': match.group("hash"), 'title': pr_info['title'], 'pr_num': int(match.group("pr")), 'pr_labels': [label.name for label in pr_info.labels.items]}
_categorise_commit(commit_info)
def _dump_commit_list(name, collection):
diff --git a/lib/python/qmk/cli/generate/dfu_header.py b/lib/python/qmk/cli/generate/dfu_header.py
index 7fb585fc7d..e873117387 100644
--- a/lib/python/qmk/cli/generate/dfu_header.py
+++ b/lib/python/qmk/cli/generate/dfu_header.py
@@ -7,6 +7,8 @@ from qmk.decorators import automagic_keyboard
from qmk.info import info_json
from qmk.path import is_keyboard, normpath
from qmk.keyboard import keyboard_completer
+from qmk.commands import dump_lines
+from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
@@ -30,7 +32,7 @@ def generate_dfu_header(cli):
# Build the Keyboard.h file.
kb_info_json = dotty(info_json(cli.config.generate_dfu_header.keyboard))
- keyboard_h_lines = ['/* This file was generated by `qmk generate-dfu-header`. Do not edit or copy.', ' */', '', '#pragma once']
+ keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once']
keyboard_h_lines.append(f'#define MANUFACTURER {kb_info_json["manufacturer"]}')
keyboard_h_lines.append(f'#define PRODUCT {kb_info_json["keyboard_name"]} Bootloader')
@@ -45,16 +47,4 @@ def generate_dfu_header(cli):
keyboard_h_lines.append(f'#define QMK_SPEAKER {kb_info_json["qmk_lufa_bootloader.speaker"]}')
# Show the results
- keyboard_h = '\n'.join(keyboard_h_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(keyboard_h)
-
- if not cli.args.quiet:
- cli.log.info('Wrote Keyboard.h to %s.', cli.args.output)
-
- else:
- print(keyboard_h)
+ dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet)
diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py
index 749336fea5..74112d834d 100644
--- a/lib/python/qmk/cli/generate/docs.py
+++ b/lib/python/qmk/cli/generate/docs.py
@@ -7,7 +7,9 @@ from subprocess import DEVNULL
from milc import cli
DOCS_PATH = Path('docs/')
-BUILD_PATH = Path('.build/docs/')
+BUILD_PATH = Path('.build/')
+BUILD_DOCS_PATH = BUILD_PATH / 'docs'
+DOXYGEN_PATH = BUILD_PATH / 'doxygen'
@cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True)
@@ -18,10 +20,12 @@ def generate_docs(cli):
* [ ] Add a real build step... something static docs
"""
- if BUILD_PATH.exists():
- shutil.rmtree(BUILD_PATH)
+ if BUILD_DOCS_PATH.exists():
+ shutil.rmtree(BUILD_DOCS_PATH)
+ if DOXYGEN_PATH.exists():
+ shutil.rmtree(DOXYGEN_PATH)
- shutil.copytree(DOCS_PATH, BUILD_PATH)
+ shutil.copytree(DOCS_PATH, BUILD_DOCS_PATH)
# When not verbose we want to hide all output
args = {
@@ -34,6 +38,6 @@ def generate_docs(cli):
# Generate internal docs
cli.run(['doxygen', 'Doxyfile'], **args)
- cli.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args)
+ cli.run(['moxygen', '-q', '-g', '-o', BUILD_DOCS_PATH / 'internals_%s.md', DOXYGEN_PATH / 'xml'], **args)
- cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH)
+ cli.log.info('Successfully generated internal docs to %s.', BUILD_DOCS_PATH)
diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py
index f05178cede..2058865cbf 100755
--- a/lib/python/qmk/cli/generate/keyboard_h.py
+++ b/lib/python/qmk/cli/generate/keyboard_h.py
@@ -3,8 +3,10 @@
from milc import cli
from qmk.info import info_json
+from qmk.commands import dump_lines
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.path import normpath
+from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
def would_populate_layout_h(keyboard):
@@ -36,22 +38,10 @@ def generate_keyboard_h(cli):
has_layout_h = would_populate_layout_h(cli.args.keyboard)
# Build the layouts.h file.
- keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.', ' */', '', '#pragma once', '#include "quantum.h"']
+ keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "quantum.h"']
if not has_layout_h:
keyboard_h_lines.append('#pragma error("<keyboard>.h is only optional for data driven keyboards - kb.h == bad times")')
# Show the results
- keyboard_h = '\n'.join(keyboard_h_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.parent / (cli.args.output.name + '.bak'))
- cli.args.output.write_text(keyboard_h)
-
- if not cli.args.quiet:
- cli.log.info('Wrote keyboard_h to %s.', cli.args.output)
-
- else:
- print(keyboard_h)
+ dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet)
diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py
index e44266e1c8..193633baf6 100755
--- a/lib/python/qmk/cli/generate/layouts.py
+++ b/lib/python/qmk/cli/generate/layouts.py
@@ -2,11 +2,12 @@
"""
from milc import cli
-from qmk.constants import COL_LETTERS, ROW_LETTERS
+from qmk.constants import COL_LETTERS, ROW_LETTERS, GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.info import info_json
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.path import is_keyboard, normpath
+from qmk.commands import dump_lines
usb_properties = {
'vid': 'VENDOR_ID',
@@ -38,18 +39,14 @@ def generate_layouts(cli):
kb_info_json = info_json(cli.config.generate_layouts.keyboard)
# Build the layouts.h file.
- layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.', ' */', '', '#pragma once']
-
- if 'matrix_pins' in kb_info_json:
- if 'direct' in kb_info_json['matrix_pins']:
- col_num = len(kb_info_json['matrix_pins']['direct'][0])
- row_num = len(kb_info_json['matrix_pins']['direct'])
- elif 'cols' in kb_info_json['matrix_pins'] and 'rows' in kb_info_json['matrix_pins']:
- col_num = len(kb_info_json['matrix_pins']['cols'])
- row_num = len(kb_info_json['matrix_pins']['rows'])
- else:
- cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard)
- return False
+ layouts_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once']
+
+ if 'matrix_size' not in kb_info_json:
+ cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard)
+ return False
+
+ col_num = kb_info_json['matrix_size']['cols']
+ row_num = kb_info_json['matrix_size']['rows']
for layout_name in kb_info_json['layouts']:
if kb_info_json['layouts'][layout_name]['c_macro']:
@@ -90,16 +87,4 @@ def generate_layouts(cli):
layouts_h_lines.append('#endif')
# Show the results
- layouts_h = '\n'.join(layouts_h_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.parent / (cli.args.output.name + '.bak'))
- cli.args.output.write_text(layouts_h)
-
- if not cli.args.quiet:
- cli.log.info('Wrote info_config.h to %s.', cli.args.output)
-
- else:
- print(layouts_h)
+ dump_lines(cli.args.output, layouts_h_lines, cli.args.quiet)
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py
index 5d8d7cc8a7..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):
@@ -29,7 +31,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
if key_type in ['array', 'list']:
return f'{rules_key} ?= {" ".join(rules_value)}'
elif key_type == 'bool':
- return f'{rules_key} ?= {"on" if rules_value else "off"}'
+ return f'{rules_key} ?= {"yes" if rules_value else "no"}'
elif key_type == 'mapping':
return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()])
@@ -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)
diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py
index b8e52588c4..a75702c529 100644
--- a/lib/python/qmk/cli/generate/version_h.py
+++ b/lib/python/qmk/cli/generate/version_h.py
@@ -1,9 +1,15 @@
"""Used by the make system to generate version.h for use in code.
"""
+from time import strftime
+
from milc import cli
-from qmk.commands import create_version_h
from qmk.path import normpath
+from qmk.commands import dump_lines
+from qmk.git import git_get_version
+from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
+
+TIME_FMT = '%Y-%m-%d-%H:%M:%S'
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
@@ -17,12 +23,29 @@ def generate_version_h(cli):
if cli.args.skip_all:
cli.args.skip_git = True
- version_h = create_version_h(cli.args.skip_git, cli.args.skip_all)
-
- if cli.args.output:
- cli.args.output.write_text(version_h)
+ if cli.args.skip_all:
+ current_time = "1970-01-01-00:00:00"
+ else:
+ current_time = strftime(TIME_FMT)
- if not cli.args.quiet:
- cli.log.info('Wrote version.h to %s.', cli.args.output)
+ if cli.args.skip_git:
+ git_version = "NA"
+ chibios_version = "NA"
+ chibios_contrib_version = "NA"
else:
- print(version_h)
+ git_version = git_get_version() or current_time
+ chibios_version = git_get_version("chibios", "os") or current_time
+ chibios_contrib_version = git_get_version("chibios-contrib", "os") or current_time
+
+ # Build the version.h file.
+ version_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once']
+
+ version_h_lines.append(f"""
+#define QMK_VERSION "{git_version}"
+#define QMK_BUILDDATE "{current_time}"
+#define CHIBIOS_VERSION "{chibios_version}"
+#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"
+""")
+
+ # Show the results
+ dump_lines(cli.args.output, version_h_lines, cli.args.quiet)