2021-06-26 18:29:02 +02:00
|
|
|
"""Used by the make system to generate version.h for use in code.
|
|
|
|
"""
|
2022-03-18 02:09:29 +01:00
|
|
|
from time import strftime
|
|
|
|
|
2021-06-26 18:29:02 +02:00
|
|
|
from milc import cli
|
|
|
|
|
|
|
|
from qmk.path import normpath
|
2022-03-18 02:09:29 +01:00
|
|
|
from qmk.commands import dump_lines
|
2023-02-02 19:23:27 +01:00
|
|
|
from qmk.git import git_get_qmk_hash, git_get_version, git_is_dirty
|
2022-03-18 02:09:29 +01:00
|
|
|
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
|
|
|
|
|
|
|
TIME_FMT = '%Y-%m-%d-%H:%M:%S'
|
2021-06-26 18:29:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
@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)
|
|
|
|
def generate_version_h(cli):
|
|
|
|
"""Generates the version.h file.
|
|
|
|
"""
|
|
|
|
if cli.args.skip_all:
|
|
|
|
cli.args.skip_git = True
|
|
|
|
|
2022-03-18 02:09:29 +01:00
|
|
|
if cli.args.skip_all:
|
|
|
|
current_time = "1970-01-01-00:00:00"
|
|
|
|
else:
|
|
|
|
current_time = strftime(TIME_FMT)
|
2021-06-26 18:29:02 +02:00
|
|
|
|
2022-03-18 02:09:29 +01:00
|
|
|
if cli.args.skip_git:
|
2023-02-02 19:23:27 +01:00
|
|
|
git_dirty = False
|
2022-03-18 02:09:29 +01:00
|
|
|
git_version = "NA"
|
2023-02-02 19:23:27 +01:00
|
|
|
git_qmk_hash = "NA"
|
2022-03-18 02:09:29 +01:00
|
|
|
chibios_version = "NA"
|
|
|
|
chibios_contrib_version = "NA"
|
2021-06-26 18:29:02 +02:00
|
|
|
else:
|
2023-02-02 19:23:27 +01:00
|
|
|
git_dirty = git_is_dirty()
|
2022-03-18 17:02:24 +01:00
|
|
|
git_version = git_get_version() or current_time
|
2023-02-02 19:23:27 +01:00
|
|
|
git_qmk_hash = git_get_qmk_hash() or "Unknown"
|
2022-03-18 17:02:24 +01:00
|
|
|
chibios_version = git_get_version("chibios", "os") or current_time
|
|
|
|
chibios_contrib_version = git_get_version("chibios-contrib", "os") or current_time
|
2022-03-18 02:09:29 +01:00
|
|
|
|
|
|
|
# Build the version.h file.
|
|
|
|
version_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once']
|
|
|
|
|
2023-02-02 19:23:27 +01:00
|
|
|
version_h_lines.append(
|
|
|
|
f"""
|
2022-03-18 02:09:29 +01:00
|
|
|
#define QMK_VERSION "{git_version}"
|
|
|
|
#define QMK_BUILDDATE "{current_time}"
|
2023-02-02 19:23:27 +01:00
|
|
|
#define QMK_GIT_HASH "{git_qmk_hash}{'*' if git_dirty else ''}"
|
2022-03-18 02:09:29 +01:00
|
|
|
#define CHIBIOS_VERSION "{chibios_version}"
|
|
|
|
#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"
|
2023-02-02 19:23:27 +01:00
|
|
|
"""
|
|
|
|
)
|
2022-03-18 02:09:29 +01:00
|
|
|
|
|
|
|
# Show the results
|
|
|
|
dump_lines(cli.args.output, version_h_lines, cli.args.quiet)
|