Skip to content

Commit 4281ae9

Browse files
committed
Cleanup get_compiler() code
1 parent ad75107 commit 4281ae9

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

‎Tools/build/generate_getbuildinfo.py‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def run_command(cmd, *, check=True):
125125
return proc.stdout.rstrip()
126126

127127

128-
def get_compiler():
128+
def _get_compiler():
129129
makefile_vars = get_makefile_vars()
130130

131131
# Run _getcompiler program
@@ -151,9 +151,23 @@ def get_compiler():
151151
# Get the first line
152152
return output.splitlines()[0]
153153

154-
# Default compiler name when everything else failed
155-
# (see Programs/_getcompiler.c)
156-
return 'C'
154+
return None
155+
156+
157+
def get_compiler(compiler):
158+
if not compiler:
159+
compiler = _get_compiler()
160+
if not compiler:
161+
# Default compiler name when everything else failed
162+
# (see Programs/_getcompiler.c)
163+
compiler = 'C'
164+
165+
# Make verbose Clang version shorter: strip the prefix and URL
166+
match = CLANG_VERBOSE_VERSION.search(compiler)
167+
if match:
168+
compiler = match.group(1)
169+
170+
return f'[{compiler}]'
157171

158172

159173
def main():
@@ -166,7 +180,6 @@ def main():
166180
git_version = args.git_version
167181
git_tag = args.git_tag
168182
git_branch = args.git_branch
169-
compiler = args.compiler
170183
free_threading = args.free_threading
171184

172185
if not output_filename:
@@ -175,13 +188,7 @@ def main():
175188
if not platform:
176189
platform = "unknown"
177190

178-
if not compiler:
179-
compiler = get_compiler()
180-
181-
# Make verbose Clang version shorter: strip the prefix and URL
182-
match = CLANG_VERBOSE_VERSION.search(compiler)
183-
if match:
184-
compiler = match.group(1)
191+
compiler = get_compiler(args.compiler)
185192

186193
build_info, git_id = get_build_info(git_tag, git_branch, git_version)
187194

@@ -192,9 +199,9 @@ def main():
192199
free_threading = get_gil_disable()
193200

194201
if free_threading:
195-
version = f"{PY_VERSION} free-threading build ({build_info}) [{compiler}]"
202+
version = f"{PY_VERSION} free-threading build ({build_info}) {compiler}"
196203
else:
197-
version = f"{PY_VERSION} ({build_info}) [{compiler}]"
204+
version = f"{PY_VERSION} ({build_info}) {compiler}"
198205

199206
new_filename = output_filename + ".new"
200207
with open(new_filename, "w", encoding="utf8") as fp:
@@ -204,7 +211,7 @@ def write_macro(name, value):
204211
print(f'// Header file auto-generated by {SCRIPT_FULLNAME}', file=fp)
205212
print(file=fp)
206213
write_macro('PLATFORM', platform)
207-
write_macro('COMPILER', f'[{compiler}]')
214+
write_macro('COMPILER', compiler)
208215
write_macro('GIT_VERSION', git_version)
209216
write_macro('GIT_IDENTIFIER', git_id)
210217
write_macro('BUILD_INFO', build_info)

0 commit comments

Comments
 (0)