aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-01-17 17:33:59 +0000
committerQMK Bot <hello@qmk.fm>2021-01-17 17:33:59 +0000
commit3a06e88566f7a12a0fa99b79fa1a762432578e86 (patch)
tree2ad0864a4bb3fb18ef0f7d24fb27a5e9b15ccda0 /lib/python/qmk
parent98b1cccd12cad68f34bddf83ed3a2db52ebcd0f9 (diff)
parentda40242dbc2b03437774a58bb7b8d35f4b59a2cd (diff)
downloadqmk_firmware-3a06e88566f7a12a0fa99b79fa1a762432578e86.tar.gz
qmk_firmware-3a06e88566f7a12a0fa99b79fa1a762432578e86.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk')
-rw-r--r--lib/python/qmk/commands.py58
1 files changed, 55 insertions, 3 deletions
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py
index ba225bf55..529c41c0c 100644
--- a/lib/python/qmk/commands.py
+++ b/lib/python/qmk/commands.py
@@ -7,12 +7,15 @@ import subprocess
7import shlex 7import shlex
8import shutil 8import shutil
9from pathlib import Path 9from pathlib import Path
10from time import strftime
10 11
11from milc import cli 12from milc import cli
12 13
13import qmk.keymap 14import qmk.keymap
14from qmk.constants import KEYBOARD_OUTPUT_PREFIX 15from qmk.constants import KEYBOARD_OUTPUT_PREFIX
15 16
17time_fmt = '%Y-%m-%d-%H:%M:%S'
18
16 19
17def _find_make(): 20def _find_make():
18 """Returns the correct make command for this environment. 21 """Returns the correct make command for this environment.
@@ -62,6 +65,39 @@ def create_make_command(keyboard, keymap, target=None, parallel=1, **env_vars):
62 return [make_cmd, '-j', str(parallel), *env, ':'.join(make_args)] 65 return [make_cmd, '-j', str(parallel), *env, ':'.join(make_args)]
63 66
64 67
68def get_git_version(repo_dir='.', check_dir='.'):
69 """Returns the current git version for a repo, or the current time.
70 """
71 git_describe_cmd = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags']
72
73 if Path(check_dir).exists():
74 git_describe = cli.run(git_describe_cmd, cwd=repo_dir)
75
76 if git_describe.returncode == 0:
77 return git_describe.stdout.strip()
78
79 else:
80 cli.args.warn(f'"{" ".join(git_describe_cmd)}" returned error code {git_describe.returncode}')
81 print(git_describe.stderr)
82 return strftime(time_fmt)
83
84 return strftime(time_fmt)
85
86
87def write_version_h(git_version, build_date, chibios_version, chibios_contrib_version):
88 """Generate and write quantum/version.h
89 """
90 version_h = [
91 f'#define QMK_VERSION "{git_version}"',
92 f'#define QMK_BUILD_DATE "{build_date}"',
93 f'#define CHIBIOS_VERSION "{chibios_version}"',
94 f'#define CHIBIOS_CONTRIB_VERSION "{chibios_contrib_version}"',
95 ]
96
97 version_h_file = Path('quantum/version.h')
98 version_h_file.write_text('\n'.join(version_h))
99
100
65def compile_configurator_json(user_keymap, parallel=1, **env_vars): 101def compile_configurator_json(user_keymap, parallel=1, **env_vars):
66 """Convert a configurator export JSON file into a C file and then compile it. 102 """Convert a configurator export JSON file into a C file and then compile it.
67 103
@@ -92,23 +128,39 @@ def compile_configurator_json(user_keymap, parallel=1, **env_vars):
92 keymap_dir.mkdir(exist_ok=True, parents=True) 128 keymap_dir.mkdir(exist_ok=True, parents=True)
93 keymap_c.write_text(c_text) 129 keymap_c.write_text(c_text)
94 130
131 # Write the version.h file
132 git_version = get_git_version()
133 build_date = strftime('%Y-%m-%d-%H:%M:%S')
134 chibios_version = get_git_version("lib/chibios", "lib/chibios/os")
135 chibios_contrib_version = get_git_version("lib/chibios-contrib", "lib/chibios-contrib/os")
136
137 write_version_h(git_version, build_date, chibios_version, chibios_contrib_version)
138
95 # Return a command that can be run to make the keymap and flash if given 139 # Return a command that can be run to make the keymap and flash if given
96 verbose = 'true' if cli.config.general.verbose else 'false' 140 verbose = 'true' if cli.config.general.verbose else 'false'
97 color = 'true' if cli.config.general.color else 'false' 141 color = 'true' if cli.config.general.color else 'false'
98 make_command = [ 142 make_command = [_find_make()]
99 _find_make(), 143
144 if not cli.config.general.verbose:
145 make_command.append('-s')
146
147 make_command.extend([
100 '-j', 148 '-j',
101 str(parallel), 149 str(parallel),
102 '-r', 150 '-r',
103 '-R', 151 '-R',
104 '-f', 152 '-f',
105 'build_keyboard.mk', 153 'build_keyboard.mk',
106 ] 154 ])
107 155
108 for key, value in env_vars.items(): 156 for key, value in env_vars.items():
109 make_command.append(f'{key}={value}') 157 make_command.append(f'{key}={value}')
110 158
111 make_command.extend([ 159 make_command.extend([
160 f'GIT_VERSION={git_version}',
161 f'BUILD_DATE={build_date}',
162 f'CHIBIOS_VERSION={chibios_version}',
163 f'CHIBIOS_CONTRIB_VERSION={chibios_contrib_version}',
112 f'KEYBOARD={user_keymap["keyboard"]}', 164 f'KEYBOARD={user_keymap["keyboard"]}',
113 f'KEYMAP={user_keymap["keymap"]}', 165 f'KEYMAP={user_keymap["keymap"]}',
114 f'KEYBOARD_FILESAFE={keyboard_filesafe}', 166 f'KEYBOARD_FILESAFE={keyboard_filesafe}',