From 75afe8d6f440cf64fafa8f08ee71cad7f7ca3ec2 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 9 Jun 2021 22:32:14 +1000 Subject: [PATCH 01/12] CLI: Add subcommand to generate version.h --- lib/python/qmk/cli/generate/version_h.py | 78 ++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lib/python/qmk/cli/generate/version_h.py diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py new file mode 100644 index 000000000000..67dde5c8ddf5 --- /dev/null +++ b/lib/python/qmk/cli/generate/version_h.py @@ -0,0 +1,78 @@ +"""Used by the make system to generate version.h for use in code. +""" +from milc import cli + +from qmk.constants import QMK_FIRMWARE +from qmk.path import normpath + +from datetime import datetime + +today = datetime.today().strftime('%Y-%m-%d-%H:%M:%S') + +@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('--force', arg_only=True, action='store_true', help='Overwrite if file already exists') +@cli.argument('--skip-git', arg_only=True, action='store_true', help='Skip Git operations') +@cli.argument('--skip-all', arg_only=True, action='store_true', help='Use placeholder values for all defines (implies --skip-git)') +@cli.subcommand('Used by the make system to generate version.h for use in code', hidden=True) +def generate_version_h(cli): + """Generates the version.h file. + """ + version_h_lines = [ + '/* This file was generated by `qmk generate-version-h`. Do not edit or copy.', + ' */', + '', + '#pragma once', + '' + ] + + if cli.args.skip_all: + cli.args.skip_git = True + + if cli.args.skip_git: + qmk_version = 'NA' + chibios_version = 'NA' + chibios_contrib_version = 'NA' + else: + qmk_version = get_git_version() + chibios_version = get_git_version('chibios') + chibios_contrib_version = get_git_version('chibios-contrib') + + if cli.args.skip_all: + build_date = '2020-01-01-00:00:00' + else: + build_date = today + + version_h_lines.append(f'#define QMK_VERSION "{qmk_version}"') + version_h_lines.append(f'#define QMK_BUILDDATE "{build_date}"') + version_h_lines.append(f'#define CHIBIOS_VERSION "{chibios_version}"') + version_h_lines.append(f'#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"') + version_h = '\n'.join(version_h_lines) + + if cli.args.output: + cli.args.output.parent.mkdir(parents=True, exist_ok=True) + if cli.args.output.exists() and not cli.args.force: + 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: + cli.log.info('Wrote version.h to %s', cli.args.output) + + else: + print(version_h) + +def get_git_version(submodule_name=None): + """Get a version string using `git describe`, or the current build time. + If submodule_name is specified, the target is the given submodule. + """ + git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags'] + + if submodule_name is not None: + git_version = cli.run(git_describe_cmd, cwd=(QMK_FIRMWARE / 'lib' / submodule_name)) + else: + git_version = cli.run(git_describe_cmd) + + if git_version.returncode != 0: + return today + + return git_version.stdout.rstrip() From 28f1bde3ec16d03eba5f162c3ad0c0132122cd0b Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 9 Jun 2021 22:39:31 +1000 Subject: [PATCH 02/12] Format pass --- lib/python/qmk/cli/generate/version_h.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 67dde5c8ddf5..fcbcc4951b40 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -9,6 +9,7 @@ today = datetime.today().strftime('%Y-%m-%d-%H:%M:%S') + @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('--force', arg_only=True, action='store_true', help='Overwrite if file already exists') @@ -18,16 +19,10 @@ def generate_version_h(cli): """Generates the version.h file. """ - version_h_lines = [ - '/* This file was generated by `qmk generate-version-h`. Do not edit or copy.', - ' */', - '', - '#pragma once', - '' - ] + version_h_lines = ['/* This file was generated by `qmk generate-version-h`. Do not edit or copy.', ' */', '', '#pragma once', ''] if cli.args.skip_all: - cli.args.skip_git = True + cli.args.skip_git = True if cli.args.skip_git: qmk_version = 'NA' @@ -61,6 +56,7 @@ def generate_version_h(cli): else: print(version_h) + def get_git_version(submodule_name=None): """Get a version string using `git describe`, or the current build time. If submodule_name is specified, the target is the given submodule. From 4c1c956125e16036a5e549ddb9f9b92d1c239846 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 9 Jun 2021 22:42:39 +1000 Subject: [PATCH 03/12] Add simple test --- lib/python/qmk/tests/test_cli_commands.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index afdbc8142917..41fc3339309b 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -257,6 +257,11 @@ def test_generate_rules_mk(): assert 'BOOTLOADER ?= atmel-dfu' in result.stdout assert 'MCU ?= atmega32u4' in result.stdout +def test_generate_version_h(): + result = check_subcommand('generate-version-h') + check_returncode(result) + assert '#define QMK_VERSION' in result.stdout + def test_generate_layouts(): result = check_subcommand('generate-layouts', '-kb', 'handwired/pytest/basic') From d6ee385c0c8847043f4617ce1c463c482c1e5bf4 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 9 Jun 2021 22:44:56 +1000 Subject: [PATCH 04/12] Bleh --- lib/python/qmk/tests/test_cli_commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 41fc3339309b..b341e1c91214 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -257,6 +257,7 @@ def test_generate_rules_mk(): assert 'BOOTLOADER ?= atmel-dfu' in result.stdout assert 'MCU ?= atmega32u4' in result.stdout + def test_generate_version_h(): result = check_subcommand('generate-version-h') check_returncode(result) From 15284625dc3ade9240ebfca6e9e9e9c60594223d Mon Sep 17 00:00:00 2001 From: fauxpark Date: Wed, 9 Jun 2021 23:01:03 +1000 Subject: [PATCH 05/12] Update Makefile to use new subcommand --- Makefile | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index e007ae3679c7..a9e297de1a97 100644 --- a/Makefile +++ b/Makefile @@ -548,29 +548,14 @@ git-submodule: git submodule sync --recursive git submodule update --init --recursive --progress -ifdef SKIP_VERSION -SKIP_GIT := yes -endif - # Generate the version.h file -ifndef SKIP_GIT - GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") - CHIBIOS_VERSION := $(shell cd lib/chibios && git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") - CHIBIOS_CONTRIB_VERSION := $(shell cd lib/chibios-contrib && git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") -else - GIT_VERSION := NA - CHIBIOS_VERSION := NA - CHIBIOS_CONTRIB_VERSION := NA +ifdef SKIP_GIT +VERSION_H_FLAGS := --skip-git endif -ifndef SKIP_VERSION -BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") -else -BUILD_DATE := 2020-01-01-00:00:00 +ifdef SKIP_VERSION +VERSION_H_FLAGS := --skip-all +SKIP_GIT := yes endif - -$(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h) -$(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(ROOT_DIR)/quantum/version.h) -$(shell echo '#define CHIBIOS_VERSION "$(CHIBIOS_VERSION)"' >> $(ROOT_DIR)/quantum/version.h) -$(shell echo '#define CHIBIOS_CONTRIB_VERSION "$(CHIBIOS_CONTRIB_VERSION)"' >> $(ROOT_DIR)/quantum/version.h) +$(shell $(QMK_BIN) generate-version-h -o $(ROOT_DIR)/quantum/version.h --force -q $(VERSION_H_FLAGS)) include $(ROOT_DIR)/testlist.mk From a967360557b98268cc3c92d361df67739bd90dc3 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sat, 19 Jun 2021 04:35:59 +1000 Subject: [PATCH 06/12] Rework --- Makefile | 2 +- lib/python/qmk/cli/generate/version_h.py | 61 +---------------------- lib/python/qmk/commands.py | 53 +++++++++++++------- lib/python/qmk/tests/test_cli_commands.py | 3 +- 4 files changed, 40 insertions(+), 79 deletions(-) diff --git a/Makefile b/Makefile index a9e297de1a97..d0be59ac7a53 100644 --- a/Makefile +++ b/Makefile @@ -556,6 +556,6 @@ ifdef SKIP_VERSION VERSION_H_FLAGS := --skip-all SKIP_GIT := yes endif -$(shell $(QMK_BIN) generate-version-h -o $(ROOT_DIR)/quantum/version.h --force -q $(VERSION_H_FLAGS)) +$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS)) include $(ROOT_DIR)/testlist.mk diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index fcbcc4951b40..908f478a84c7 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -2,73 +2,16 @@ """ from milc import cli -from qmk.constants import QMK_FIRMWARE -from qmk.path import normpath +from qmk.commands import write_version_h -from datetime import datetime -today = datetime.today().strftime('%Y-%m-%d-%H:%M:%S') - - -@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('--force', arg_only=True, action='store_true', help='Overwrite if file already exists') @cli.argument('--skip-git', arg_only=True, action='store_true', help='Skip Git operations') @cli.argument('--skip-all', arg_only=True, action='store_true', help='Use placeholder values for all defines (implies --skip-git)') @cli.subcommand('Used by the make system to generate version.h for use in code', hidden=True) def generate_version_h(cli): """Generates the version.h file. """ - version_h_lines = ['/* This file was generated by `qmk generate-version-h`. Do not edit or copy.', ' */', '', '#pragma once', ''] - if cli.args.skip_all: cli.args.skip_git = True - if cli.args.skip_git: - qmk_version = 'NA' - chibios_version = 'NA' - chibios_contrib_version = 'NA' - else: - qmk_version = get_git_version() - chibios_version = get_git_version('chibios') - chibios_contrib_version = get_git_version('chibios-contrib') - - if cli.args.skip_all: - build_date = '2020-01-01-00:00:00' - else: - build_date = today - - version_h_lines.append(f'#define QMK_VERSION "{qmk_version}"') - version_h_lines.append(f'#define QMK_BUILDDATE "{build_date}"') - version_h_lines.append(f'#define CHIBIOS_VERSION "{chibios_version}"') - version_h_lines.append(f'#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"') - version_h = '\n'.join(version_h_lines) - - if cli.args.output: - cli.args.output.parent.mkdir(parents=True, exist_ok=True) - if cli.args.output.exists() and not cli.args.force: - 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: - cli.log.info('Wrote version.h to %s', cli.args.output) - - else: - print(version_h) - - -def get_git_version(submodule_name=None): - """Get a version string using `git describe`, or the current build time. - If submodule_name is specified, the target is the given submodule. - """ - git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags'] - - if submodule_name is not None: - git_version = cli.run(git_describe_cmd, cwd=(QMK_FIRMWARE / 'lib' / submodule_name)) - else: - git_version = cli.run(git_describe_cmd) - - if git_version.returncode != 0: - return today - - return git_version.stdout.rstrip() + write_version_h(cli.args.skip_git, cli.args.skip_all) diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 3a35c11031c2..1bcfdb13a713 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -86,11 +86,17 @@ def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars): return create_make_target(':'.join(make_args), parallel, **env_vars) -def get_git_version(repo_dir='.', check_dir='.'): +def get_git_version(current_time, repo_dir='.', check_dir='.'): """Returns the current git version for a repo, or the current time. """ git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags'] + if repo_dir != '.': + repo_dir = Path('lib') / repo_dir + + if check_dir != '.': + check_dir = repo_dir / check_dir + if Path(check_dir).exists(): git_describe = cli.run(git_describe_cmd, stdin=DEVNULL, cwd=repo_dir) @@ -100,23 +106,43 @@ def get_git_version(repo_dir='.', check_dir='.'): else: cli.log.warn(f'"{" ".join(git_describe_cmd)}" returned error code {git_describe.returncode}') print(git_describe.stderr) - return strftime(time_fmt) + return current_time - return strftime(time_fmt) + return current_time -def write_version_h(git_version, build_date, chibios_version, chibios_contrib_version): +def write_version_h(skip_git=False, skip_all=False): """Generate and write quantum/version.h """ - version_h = [ + if skip_all: + current_time = "2020-01-01-00:00:00" + else: + current_time = strftime(time_fmt) + + if skip_git: + git_version = "NA" + 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") + + version_h_lines = [ + '/* This file was automatically generated. Do not edit or copy.', + ' */', + '', + '#pragma once', + '', f'#define QMK_VERSION "{git_version}"', - f'#define QMK_BUILDDATE "{build_date}"', + f'#define QMK_BUILDDATE "{current_time}"', f'#define CHIBIOS_VERSION "{chibios_version}"', f'#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"', + '', ] - version_h_file = Path('quantum/version.h') - version_h_file.write_text('\n'.join(version_h)) + version_h = Path('quantum/version.h') + version_h.write_text('\n'.join(version_h_lines)) def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_vars): @@ -150,12 +176,7 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va keymap_c.write_text(c_text) # Write the version.h file - git_version = get_git_version() - build_date = strftime('%Y-%m-%d-%H:%M:%S') - chibios_version = get_git_version("lib/chibios", "lib/chibios/os") - chibios_contrib_version = get_git_version("lib/chibios-contrib", "lib/chibios-contrib/os") - - write_version_h(git_version, build_date, chibios_version, chibios_contrib_version) + write_version_h() # Return a command that can be run to make the keymap and flash if given verbose = 'true' if cli.config.general.verbose else 'false' @@ -181,10 +202,6 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va make_command.append(f'{key}={value}') make_command.extend([ - f'GIT_VERSION={git_version}', - f'BUILD_DATE={build_date}', - f'CHIBIOS_VERSION={chibios_version}', - f'CHIBIOS_CONTRIB_VERSION={chibios_contrib_version}', f'KEYBOARD={user_keymap["keyboard"]}', f'KEYMAP={user_keymap["keymap"]}', f'KEYBOARD_FILESAFE={keyboard_filesafe}', diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index b341e1c91214..784df57ef73d 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -1,4 +1,5 @@ import platform +from pathlib import Path from subprocess import DEVNULL from milc import cli @@ -261,7 +262,7 @@ def test_generate_rules_mk(): def test_generate_version_h(): result = check_subcommand('generate-version-h') check_returncode(result) - assert '#define QMK_VERSION' in result.stdout + assert Path('quantum/version.h').isfile() def test_generate_layouts(): From 94ff6299885ce5b54e633de5999937431f74b9cf Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sat, 19 Jun 2021 04:40:27 +1000 Subject: [PATCH 07/12] Reregister subcommand --- lib/python/qmk/cli/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 32da1a9b52e6..11e51e8f7776 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py @@ -48,6 +48,7 @@ 'qmk.cli.generate.layouts', 'qmk.cli.generate.rgb_breathe_table', 'qmk.cli.generate.rules_mk', + 'qmk.cli.generate.version_h', 'qmk.cli.hello', 'qmk.cli.info', 'qmk.cli.json2c', From e91f213d8cc8f4e3472dde02de2b31a736313212 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sat, 19 Jun 2021 04:46:01 +1000 Subject: [PATCH 08/12] Wrong function name --- lib/python/qmk/tests/test_cli_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 784df57ef73d..d5e6e8f1487f 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -262,7 +262,7 @@ def test_generate_rules_mk(): def test_generate_version_h(): result = check_subcommand('generate-version-h') check_returncode(result) - assert Path('quantum/version.h').isfile() + assert Path('quantum/version.h').is_file() def test_generate_layouts(): From 59332988fd5704d18db2221a7fb3a5ead460448e Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 20 Jun 2021 07:25:52 +1000 Subject: [PATCH 09/12] Use heredoc, set placeholder timestamp to Unix epoch --- lib/python/qmk/commands.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 1bcfdb13a713..c9abad215c07 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -115,7 +115,7 @@ def write_version_h(skip_git=False, skip_all=False): """Generate and write quantum/version.h """ if skip_all: - current_time = "2020-01-01-00:00:00" + current_time = "1970-01-01-00:00:00" else: current_time = strftime(time_fmt) @@ -128,21 +128,19 @@ def write_version_h(skip_git=False, skip_all=False): chibios_version = get_git_version(current_time, "chibios", "os") chibios_contrib_version = get_git_version(current_time, "chibios-contrib", "os") - version_h_lines = [ - '/* This file was automatically generated. Do not edit or copy.', - ' */', - '', - '#pragma once', - '', - f'#define QMK_VERSION "{git_version}"', - f'#define QMK_BUILDDATE "{current_time}"', - f'#define CHIBIOS_VERSION "{chibios_version}"', - f'#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"', - '', - ] + version_h_lines = f"""/* This file was automatically generated. Do not edit or copy. + */ + +#pragma once + +#define QMK_VERSION "{git_version}" +#define QMK_BUILDDATE "{current_time}" +#define CHIBIOS_VERSION "{chibios_version}" +#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}" +""" version_h = Path('quantum/version.h') - version_h.write_text('\n'.join(version_h_lines)) + version_h.write_text(version_h_lines) def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_vars): From db5227c3b9abd00bfcc472e94c6e7acfb4c5cb3b Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 27 Jun 2021 02:07:03 +1000 Subject: [PATCH 10/12] Refactor to allow output to stdout or specific file --- Makefile | 2 +- lib/python/qmk/cli/generate/version_h.py | 15 +++++++++++++-- lib/python/qmk/commands.py | 11 +++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index d0be59ac7a53..6ba49dfc0f84 100644 --- a/Makefile +++ b/Makefile @@ -556,6 +556,6 @@ ifdef SKIP_VERSION VERSION_H_FLAGS := --skip-all SKIP_GIT := yes endif -$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS)) +$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS)) -q -o quantum/version.h include $(ROOT_DIR)/testlist.mk diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 908f478a84c7..b8e52588c454 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -2,9 +2,12 @@ """ from milc import cli -from qmk.commands import write_version_h +from qmk.commands import create_version_h +from qmk.path import 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('--skip-git', arg_only=True, action='store_true', help='Skip Git operations') @cli.argument('--skip-all', arg_only=True, action='store_true', help='Use placeholder values for all defines (implies --skip-git)') @cli.subcommand('Used by the make system to generate version.h for use in code', hidden=True) @@ -14,4 +17,12 @@ def generate_version_h(cli): if cli.args.skip_all: cli.args.skip_git = True - write_version_h(cli.args.skip_git, cli.args.skip_all) + 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 not cli.args.quiet: + cli.log.info('Wrote version.h to %s.', cli.args.output) + else: + print(version_h) diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index c9abad215c07..104c875457ac 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -111,8 +111,8 @@ def get_git_version(current_time, repo_dir='.', check_dir='.'): return current_time -def write_version_h(skip_git=False, skip_all=False): - """Generate and write quantum/version.h +def create_version_h(skip_git=False, skip_all=False): + """Generate version.h contents """ if skip_all: current_time = "1970-01-01-00:00:00" @@ -139,8 +139,7 @@ def write_version_h(skip_git=False, skip_all=False): #define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}" """ - version_h = Path('quantum/version.h') - version_h.write_text(version_h_lines) + return version_h_lines def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_vars): @@ -173,8 +172,8 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va keymap_dir.mkdir(exist_ok=True, parents=True) keymap_c.write_text(c_text) - # Write the version.h file - write_version_h() + version_h = Path('quantum/version.h') + version_h.write_text(create_version_h()) # Return a command that can be run to make the keymap and flash if given verbose = 'true' if cli.config.general.verbose else 'false' From 8dccaf2d01bbba6d22650d7187d6c46507ef2a86 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 27 Jun 2021 02:10:25 +1000 Subject: [PATCH 11/12] And fix the test --- lib/python/qmk/tests/test_cli_commands.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index d5e6e8f1487f..b341e1c91214 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -1,5 +1,4 @@ import platform -from pathlib import Path from subprocess import DEVNULL from milc import cli @@ -262,7 +261,7 @@ def test_generate_rules_mk(): def test_generate_version_h(): result = check_subcommand('generate-version-h') check_returncode(result) - assert Path('quantum/version.h').is_file() + assert '#define QMK_VERSION' in result.stdout def test_generate_layouts(): From d8a733da35ee487f0a4a6153a9c8090f7ce5fe98 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 27 Jun 2021 02:17:15 +1000 Subject: [PATCH 12/12] Parentheses! --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6ba49dfc0f84..866bcaaf3fd9 100644 --- a/Makefile +++ b/Makefile @@ -556,6 +556,6 @@ ifdef SKIP_VERSION VERSION_H_FLAGS := --skip-all SKIP_GIT := yes endif -$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS)) -q -o quantum/version.h +$(shell $(QMK_BIN) generate-version-h $(VERSION_H_FLAGS) -q -o quantum/version.h) include $(ROOT_DIR)/testlist.mk