1
0
Fork 0

Generate version.h when compiling json files (#11581)

* generate version.h when compiling json files

* make flake8 happy

* fix formatting and verbose

* quiet up the compile output
This commit is contained in:
Zach White 2021-01-17 09:33:29 -08:00 committed by GitHub
parent f0f6174136
commit da40242dbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,12 +7,15 @@ import subprocess
import shlex import shlex
import shutil import shutil
from pathlib import Path from pathlib import Path
from time import strftime
from milc import cli from milc import cli
import qmk.keymap import qmk.keymap
from qmk.constants import KEYBOARD_OUTPUT_PREFIX from qmk.constants import KEYBOARD_OUTPUT_PREFIX
time_fmt = '%Y-%m-%d-%H:%M:%S'
def _find_make(): def _find_make():
"""Returns the correct make command for this environment. """Returns the correct make command for this environment.
@ -62,6 +65,39 @@ def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars):
return [make_cmd, '-j', str(parallel), *env, ':'.join(make_args)] return [make_cmd, '-j', str(parallel), *env, ':'.join(make_args)]
def get_git_version(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 Path(check_dir).exists():
git_describe = cli.run(git_describe_cmd, cwd=repo_dir)
if git_describe.returncode == 0:
return git_describe.stdout.strip()
else:
cli.args.warn(f'"{" ".join(git_describe_cmd)}" returned error code {git_describe.returncode}')
print(git_describe.stderr)
return strftime(time_fmt)
return strftime(time_fmt)
def write_version_h(git_version, build_date, chibios_version, chibios_contrib_version):
"""Generate and write quantum/version.h
"""
version_h = [
f'#define QMK_VERSION "{git_version}"',
f'#define QMK_BUILD_DATE "{build_date}"',
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))
def compile_configurator_json(user_keymap, parallel=1, **env_vars): def compile_configurator_json(user_keymap, parallel=1, **env_vars):
"""Convert a configurator export JSON file into a C file and then compile it. """Convert a configurator export JSON file into a C file and then compile it.
@ -92,23 +128,39 @@ def compile_configurator_json(user_keymap, parallel=1, **env_vars):
keymap_dir.mkdir(exist_ok=True, parents=True) keymap_dir.mkdir(exist_ok=True, parents=True)
keymap_c.write_text(c_text) 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)
# Return a command that can be run to make the keymap and flash if given # Return a command that can be run to make the keymap and flash if given
verbose = 'true' if cli.config.general.verbose else 'false' verbose = 'true' if cli.config.general.verbose else 'false'
color = 'true' if cli.config.general.color else 'false' color = 'true' if cli.config.general.color else 'false'
make_command = [ make_command = [_find_make()]
_find_make(),
if not cli.config.general.verbose:
make_command.append('-s')
make_command.extend([
'-j', '-j',
str(parallel), str(parallel),
'-r', '-r',
'-R', '-R',
'-f', '-f',
'build_keyboard.mk', 'build_keyboard.mk',
] ])
for key, value in env_vars.items(): for key, value in env_vars.items():
make_command.append(f'{key}={value}') make_command.append(f'{key}={value}')
make_command.extend([ 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'KEYBOARD={user_keymap["keyboard"]}',
f'KEYMAP={user_keymap["keymap"]}', f'KEYMAP={user_keymap["keymap"]}',
f'KEYBOARD_FILESAFE={keyboard_filesafe}', f'KEYBOARD_FILESAFE={keyboard_filesafe}',