From 7b018f097db2d219908f74eb7a406ae5f7f93f46 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 22 Dec 2021 05:44:47 +1100 Subject: Use the PR title rather than parsing the commit message. (#15537) --- lib/python/qmk/cli/generate/develop_pr_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/develop_pr_list.py b/lib/python/qmk/cli/generate/develop_pr_list.py index 07e46752a6..fab0262773 100755 --- a/lib/python/qmk/cli/generate/develop_pr_list.py +++ b/lib/python/qmk/cli/generate/develop_pr_list.py @@ -97,7 +97,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): -- cgit v1.2.3 From 1a8a842cfb3e87a82afb57ba29ca59c5fa6fe97b Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 29 Dec 2021 21:35:35 +0000 Subject: Fix compilation-database command under MSYS (#15652) * Fix compilation-database command under MSYS * Add comment --- lib/python/qmk/cli/generate/compilation_database.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 602635270c..7ac0f740fe 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -26,7 +26,8 @@ def system_libs(binary: str) -> List[Path]: # Actually query xxxxxx-gcc to find its include paths. if binary.endswith("gcc") or binary.endswith("g++"): - result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, input='\n') + # (TODO): Remove 'stdin' once 'input' no longer causes issues under MSYS + result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, stdin=None, input='\n') paths = [] for line in result.stderr.splitlines(): if line.startswith(" "): -- cgit v1.2.3 From c72ed7c02473dec4da6cb263c1e0fb2ca4856b94 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 17 Jan 2022 08:44:34 +1100 Subject: CLI: Parse USB device version BCD (#14580) * CLI: Parse USB device version BCD * Apply suggestions --- lib/python/qmk/cli/generate/config_h.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index f16dca1de8..6b1012fae7 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -108,6 +108,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}') -- cgit v1.2.3 From db43e450771f4eefe27821a88cc86df46c1006c1 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 4 Feb 2022 07:36:02 +1100 Subject: Ensure `version.h` is recreated each build. (#16188) --- lib/python/qmk/cli/generate/version_h.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index b8e52588c4..69341e36f0 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -20,6 +20,9 @@ def generate_version_h(cli): version_h = create_version_h(cli.args.skip_git, cli.args.skip_all) 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(version_h) if not cli.args.quiet: -- cgit v1.2.3 From 8fd8b2dc92a01b86a8e9ff3c37baeba760312140 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sat, 5 Feb 2022 07:36:57 +1100 Subject: Skip categorisation of PR if it's only for code formatting. (#16215) --- lib/python/qmk/cli/generate/develop_pr_list.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/develop_pr_list.py b/lib/python/qmk/cli/generate/develop_pr_list.py index fab0262773..09236a7c42 100755 --- a/lib/python/qmk/cli/generate/develop_pr_list.py +++ b/lib/python/qmk/cli/generate/develop_pr_list.py @@ -12,6 +12,14 @@ 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 + def _get_pr_info(cache, gh, pr_num): pull = cache.get(f'pull:{pr_num}') @@ -81,7 +89,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) -- cgit v1.2.3 From f30f963a0b6ccaa151fe83dd8302fa1f6829086e Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 22 Feb 2022 02:47:44 +1100 Subject: Internal docs generation updates (#16411) --- lib/python/qmk/cli/generate/docs.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/python/qmk/cli/generate') 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) -- cgit v1.2.3 From cf31355f08dca311a013168eb3eb995e2fc6a3d1 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 23 Feb 2022 17:33:08 +0000 Subject: Changelog 2022q1 (#16380) * Initial changelog pass * update generate-develop-pr-list content * Fix bad word-ness * Fix generate-develop-pr-list ignores * Update docs/ChangeLog/20220226.md Co-authored-by: Sergey Vlasov Co-authored-by: Sergey Vlasov --- lib/python/qmk/cli/generate/develop_pr_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/develop_pr_list.py b/lib/python/qmk/cli/generate/develop_pr_list.py index 09236a7c42..549db5b185 100755 --- a/lib/python/qmk/cli/generate/develop_pr_list.py +++ b/lib/python/qmk/cli/generate/develop_pr_list.py @@ -18,7 +18,8 @@ ignored_titles = ["Format code according to conventions"] def _is_ignored(title): for ignore in ignored_titles: if ignore in title: - return + return True + return False def _get_pr_info(cache, gh, pr_num): -- cgit v1.2.3 From 779c7debcfff1a4a3ad578a0c12bdd50cba11039 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 27 Feb 2022 12:39:24 +0000 Subject: Fix issues with data driven split keyboards (#16457) --- lib/python/qmk/cli/generate/config_h.py | 36 ++++++++++++++++++--------------- lib/python/qmk/cli/generate/layouts.py | 16 ++++++--------- lib/python/qmk/cli/generate/rules_mk.py | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index 6b1012fae7..24bbbdf517 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -21,18 +21,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 +31,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 +57,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. """ @@ -183,6 +185,8 @@ def generate_config_h(cli): 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'])) diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py index e44266e1c8..a21311bd49 100755 --- a/lib/python/qmk/cli/generate/layouts.py +++ b/lib/python/qmk/cli/generate/layouts.py @@ -40,16 +40,12 @@ def generate_layouts(cli): # 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 + 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']: diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 5d8d7cc8a7..ce824f6378 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -29,7 +29,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()]) -- cgit v1.2.3 From e5823b56501598c39d3f57719cf32f344212ede6 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 18 Mar 2022 01:09:29 +0000 Subject: [CLI] Add common util for dumping generated content (#16674) --- lib/python/qmk/cli/generate/config_h.py | 18 +++---------- lib/python/qmk/cli/generate/dfu_header.py | 18 +++---------- lib/python/qmk/cli/generate/keyboard_h.py | 18 +++---------- lib/python/qmk/cli/generate/layouts.py | 19 +++----------- lib/python/qmk/cli/generate/rules_mk.py | 14 +++-------- lib/python/qmk/cli/generate/version_h.py | 42 +++++++++++++++++++++++-------- 6 files changed, 51 insertions(+), 78 deletions(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index 24bbbdf517..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): @@ -181,7 +183,7 @@ 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) @@ -194,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/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/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(".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 a21311bd49..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,7 +39,7 @@ 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'] + 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) @@ -86,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 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) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 69341e36f0..be9646748e 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.commands import get_git_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,15 +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.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(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 = get_git_version(current_time) + chibios_version = get_git_version(current_time, "chibios", "os") + chibios_contrib_version = get_git_version(current_time, "chibios-contrib", "os") + + # 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) -- cgit v1.2.3 From ed773ab73cab83b842dc62ff94ffb337ec66a5f3 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 18 Mar 2022 16:02:24 +0000 Subject: Relocate CLI git interactions (#16682) --- lib/python/qmk/cli/generate/version_h.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/python/qmk/cli/generate') diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index be9646748e..a75702c529 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -6,7 +6,7 @@ from milc import cli from qmk.path import normpath from qmk.commands import dump_lines -from qmk.commands import get_git_version +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' @@ -33,9 +33,9 @@ def generate_version_h(cli): chibios_version = "NA" chibios_contrib_version = "NA" else: - git_version = get_git_version(current_time) - chibios_version = get_git_version(current_time, "chibios", "os") - chibios_contrib_version = get_git_version(current_time, "chibios-contrib", "os") + 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'] -- cgit v1.2.3