summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/generate/version_h.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/generate/version_h.py')
-rw-r--r--lib/python/qmk/cli/generate/version_h.py42
1 files changed, 31 insertions, 11 deletions
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)