From ce99ac972b3df2349562b1b0fd76021d6e9221e9 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Sun, 8 Jan 2023 13:12:00 +0100 Subject: [PATCH 1/8] Initial commit --- lib/python/qmk/cli/generate/version_h.py | 7 ++++++- lib/python/qmk/git.py | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index a75702c529a3..39be88735efc 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -6,7 +6,7 @@ from qmk.path import normpath from qmk.commands import dump_lines -from qmk.git import git_get_version +from qmk.git import git_get_commit_hash, git_is_dirty, git_get_version from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE TIME_FMT = '%Y-%m-%d-%H:%M:%S' @@ -29,10 +29,14 @@ def generate_version_h(cli): current_time = strftime(TIME_FMT) if cli.args.skip_git: + git_dirty = "" # so that it evaluates as False + git_commit = "NA" git_version = "NA" chibios_version = "NA" chibios_contrib_version = "NA" else: + git_dirty = git_is_dirty() + git_commit = git_get_commit_hash() 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 @@ -45,6 +49,7 @@ def generate_version_h(cli): #define QMK_BUILDDATE "{current_time}" #define CHIBIOS_VERSION "{chibios_version}" #define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}" +#define GIT_COMMIT "{git_commit}{'*' if git_dirty else ''}" """) # Show the results diff --git a/lib/python/qmk/git.py b/lib/python/qmk/git.py index 7fa0306f5cf5..cef84838bafa 100644 --- a/lib/python/qmk/git.py +++ b/lib/python/qmk/git.py @@ -136,3 +136,11 @@ def git_get_ignored_files(check_dir='.'): if invalid.returncode != 0: return [] return invalid.stdout.strip().splitlines() + + +def git_get_commit_hash(): + output = cli.run(['git', 'rev-parse', '--short', 'HEAD']) + if output.returncode != 0: + print("Unknown") + + return output.stdout.strip() From 6acea1a02b1c876f8eafefd1fe677ec5ec4e0ae4 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Sun, 8 Jan 2023 13:22:41 +0100 Subject: [PATCH 2/8] Fix import order --- lib/python/qmk/cli/generate/version_h.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 39be88735efc..f59f774a48d5 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -6,7 +6,7 @@ from qmk.path import normpath from qmk.commands import dump_lines -from qmk.git import git_get_commit_hash, git_is_dirty, git_get_version +from qmk.git import git_get_commit_hash, git_get_version, git_is_dirty from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE TIME_FMT = '%Y-%m-%d-%H:%M:%S' From 8aa8d6ed358bea34180042babe2ba71cc2cfb4f1 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Sun, 8 Jan 2023 13:24:23 +0100 Subject: [PATCH 3/8] Fix deleted code instead of debug print line --- lib/python/qmk/git.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/git.py b/lib/python/qmk/git.py index cef84838bafa..4f54bab83cec 100644 --- a/lib/python/qmk/git.py +++ b/lib/python/qmk/git.py @@ -141,6 +141,6 @@ def git_get_ignored_files(check_dir='.'): def git_get_commit_hash(): output = cli.run(['git', 'rev-parse', '--short', 'HEAD']) if output.returncode != 0: - print("Unknown") + return "Unknown" return output.stdout.strip() From 6ad7887bdefe3c124f06995922060d67c4c66576 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Sun, 8 Jan 2023 14:01:00 +0100 Subject: [PATCH 4/8] Format --- lib/python/qmk/cli/generate/version_h.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index f59f774a48d5..3d92b4e2b6ad 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -44,13 +44,15 @@ def generate_version_h(cli): # Build the version.h file. version_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once'] - version_h_lines.append(f""" + 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}" #define GIT_COMMIT "{git_commit}{'*' if git_dirty else ''}" -""") +""" + ) # Show the results dump_lines(cli.args.output, version_h_lines, cli.args.quiet) From 87b338b788d1c174ca25d0d902b9f868c929f1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Sun, 8 Jan 2023 14:05:51 +0100 Subject: [PATCH 5/8] Update lib/python/qmk/cli/generate/version_h.py Co-authored-by: Ryan --- lib/python/qmk/cli/generate/version_h.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 3d92b4e2b6ad..3fb725382d90 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -29,7 +29,7 @@ def generate_version_h(cli): current_time = strftime(TIME_FMT) if cli.args.skip_git: - git_dirty = "" # so that it evaluates as False + git_dirty = False git_commit = "NA" git_version = "NA" chibios_version = "NA" From 937d5da2c137721b0e8f065379e1a1ebf8b797af Mon Sep 17 00:00:00 2001 From: elpekenin Date: Mon, 9 Jan 2023 10:58:42 +0100 Subject: [PATCH 6/8] Renaming --- lib/python/qmk/cli/generate/version_h.py | 8 ++++---- lib/python/qmk/git.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 3fb725382d90..2ce9af12e14c 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -6,7 +6,7 @@ from qmk.path import normpath from qmk.commands import dump_lines -from qmk.git import git_get_commit_hash, git_get_version, git_is_dirty +from qmk.git import git_get_qmk_hash, git_get_version, git_is_dirty from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE TIME_FMT = '%Y-%m-%d-%H:%M:%S' @@ -30,14 +30,14 @@ def generate_version_h(cli): if cli.args.skip_git: git_dirty = False - git_commit = "NA" git_version = "NA" + git_qmk_hash = "NA" chibios_version = "NA" chibios_contrib_version = "NA" else: git_dirty = git_is_dirty() - git_commit = git_get_commit_hash() git_version = git_get_version() or current_time + git_qmk_hash = git_get_qmk_hash() chibios_version = git_get_version("chibios", "os") or current_time chibios_contrib_version = git_get_version("chibios-contrib", "os") or current_time @@ -48,9 +48,9 @@ def generate_version_h(cli): f""" #define QMK_VERSION "{git_version}" #define QMK_BUILDDATE "{current_time}" +#define QMK_GIT_HASH "{git_qmk_hash}{'*' if git_dirty else ''}" #define CHIBIOS_VERSION "{chibios_version}" #define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}" -#define GIT_COMMIT "{git_commit}{'*' if git_dirty else ''}" """ ) diff --git a/lib/python/qmk/git.py b/lib/python/qmk/git.py index 4f54bab83cec..0bccc0db98ad 100644 --- a/lib/python/qmk/git.py +++ b/lib/python/qmk/git.py @@ -138,7 +138,7 @@ def git_get_ignored_files(check_dir='.'): return invalid.stdout.strip().splitlines() -def git_get_commit_hash(): +def git_get_qmk_hash(): output = cli.run(['git', 'rev-parse', '--short', 'HEAD']) if output.returncode != 0: return "Unknown" From 31d695f905f1f3620e0d61e3d423b9aaa4b97a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:35:32 +0100 Subject: [PATCH 7/8] Update lib/python/qmk/cli/generate/version_h.py Co-authored-by: Joel Challis --- lib/python/qmk/cli/generate/version_h.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/version_h.py b/lib/python/qmk/cli/generate/version_h.py index 2ce9af12e14c..fd87df361746 100644 --- a/lib/python/qmk/cli/generate/version_h.py +++ b/lib/python/qmk/cli/generate/version_h.py @@ -37,7 +37,7 @@ def generate_version_h(cli): else: git_dirty = git_is_dirty() git_version = git_get_version() or current_time - git_qmk_hash = git_get_qmk_hash() + git_qmk_hash = git_get_qmk_hash() or "Unknown" chibios_version = git_get_version("chibios", "os") or current_time chibios_contrib_version = git_get_version("chibios-contrib", "os") or current_time From b0e31f3fc4fb58ce424ac819e0f1196e6443f250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:35:38 +0100 Subject: [PATCH 8/8] Update lib/python/qmk/git.py Co-authored-by: Joel Challis --- lib/python/qmk/git.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/git.py b/lib/python/qmk/git.py index 0bccc0db98ad..b6c11edbfe8f 100644 --- a/lib/python/qmk/git.py +++ b/lib/python/qmk/git.py @@ -141,6 +141,6 @@ def git_get_ignored_files(check_dir='.'): def git_get_qmk_hash(): output = cli.run(['git', 'rev-parse', '--short', 'HEAD']) if output.returncode != 0: - return "Unknown" + return None return output.stdout.strip()