Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commit info to version.h #19542

Merged
merged 8 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/python/qmk/cli/generate/version_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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'
Expand All @@ -29,23 +29,30 @@ def generate_version_h(cli):
current_time = strftime(TIME_FMT)

if cli.args.skip_git:
git_dirty = False
git_version = "NA"
git_qmk_hash = "NA"
chibios_version = "NA"
chibios_contrib_version = "NA"
else:
git_dirty = git_is_dirty()
git_version = git_get_version() or current_time
git_qmk_hash = git_get_qmk_hash()
elpekenin marked this conversation as resolved.
Show resolved Hide resolved
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"""
version_h_lines.append(
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}"
""")
"""
)

# Show the results
dump_lines(cli.args.output, version_h_lines, cli.args.quiet)
8 changes: 8 additions & 0 deletions lib/python/qmk/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ def git_get_ignored_files(check_dir='.'):
if invalid.returncode != 0:
return []
return invalid.stdout.strip().splitlines()


def git_get_qmk_hash():
output = cli.run(['git', 'rev-parse', '--short', 'HEAD'])
if output.returncode != 0:
return "Unknown"
elpekenin marked this conversation as resolved.
Show resolved Hide resolved

return output.stdout.strip()