Skip to content

Commit b036e72

Browse files
committed
Keep the vendor (Android or Apple) in Clang version
1 parent aa9a4aa commit b036e72

3 files changed

Lines changed: 45 additions & 36 deletions

File tree

‎Lib/test/test_tools/test_getbuildinfo.py‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests Tools/build/generate_getbuildinfo.py."""
1+
"""Test Tools/build/generate_getbuildinfo.py."""
22

33
import locale
44
import os
@@ -71,11 +71,11 @@ def test_get_compiler(self):
7171
MOCK_COMPILER = 'MOCK_COMPILER'
7272

7373
for hostrunner in ('', 'node'):
74+
makefile_vars = {
75+
'HOSTRUNNER': hostrunner,
76+
'CC': 'gcc -std=c11',
77+
}
7478
for use_cc in (False, True):
75-
makefile_vars = {
76-
'HOSTRUNNER': hostrunner,
77-
'CC': 'gcc -std=c11',
78-
}
7979
with mock.patch.object(generate_getbuildinfo,
8080
'get_makefile_vars',
8181
return_value=makefile_vars):
@@ -101,22 +101,22 @@ def test_get_compiler(self):
101101
else:
102102
mock_run_command.assert_called_once_with(cmd, check=False)
103103

104-
def test_shorter_clang_version(self):
105-
shorter_clang_version = generate_getbuildinfo.shorter_clang_version
104+
def test_compact_compiler(self):
105+
compact_compiler = generate_getbuildinfo.compact_compiler
106106

107107
def check(compiler, expected):
108-
self.assertEqual(shorter_clang_version(compiler), expected)
108+
self.assertEqual(compact_compiler(compiler), expected)
109109

110110
def check_unchanged(compiler):
111-
self.assertEqual(shorter_clang_version(compiler), compiler)
111+
self.assertEqual(compact_compiler(compiler), compiler)
112112

113113
compiler = (
114114
'Android (13691557, +pgo, +bolt, +lto, +mlgo, based on r522817d) '
115115
'clang version 18.0.4 '
116116
'(https://android.googlesource.com/toolchain/llvm-project'
117117
' d8003a456d14a3deb8054cdaa529ffbf02d9b262)'
118118
)
119-
check(compiler, 'Clang 18.0.4')
119+
check(compiler, 'Android Clang 18.0.4')
120120

121121
compiler = (
122122
'Clang 18.0.4 '
@@ -132,8 +132,16 @@ def check_unchanged(compiler):
132132
)
133133
check(compiler, 'Clang 24.0.0git')
134134

135-
check_unchanged('Clang 21.0.0 (clang-2100.1.1.101)')
136-
check_unchanged('Apple clang version 21.0.0 (clang-2100.1.1.101)')
135+
check('Clang 21.0.0 (clang-2100.1.1.101)',
136+
'Clang 21.0.0')
137+
check('Apple clang version 21.0.0 (clang-2100.1.1.101)',
138+
'Apple Clang 21.0.0')
139+
check('Custom Vendor (something) Clang 22.1.0+dev',
140+
'Custom Vendor Clang 22.1.0+dev')
141+
142+
check_unchanged('GCC 16.2.1 20260819 (Red Hat 16.2.1-2)')
143+
check_unchanged('GCC 15.2.0')
144+
check_unchanged('MSC v.1951 32 bit (Intel)')
137145

138146
def test_functional(self):
139147
old_locale = locale.setlocale(locale.LC_ALL)

‎PCbuild/pcbuild.sln‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 18
3-
VisualStudioVersion = 18.10.12224.181 stable
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.8.34525.116
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}"
66
ProjectSection(SolutionItems) = preProject

‎Tools/build/generate_getbuildinfo.py‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
# Get PY_VERSION from Include/patchlevel.h
1818
PY_VERSION_REGEX = re.compile(r'^#define PY_VERSION +"(.*)"$', re.MULTILINE)
1919

20-
# Parse verbose Clang version (truncated here with '...'):
21-
# 'Clang 24.0.0git (https:/github.com/llvm/llvm-project a06...8bf)'
22-
# 'Android (13691557, +pgo, ...) clang version 18.0.4 (https://android.googlesource.com/toolchain/llvm-project d80...262)'
23-
CLANG_VERBOSE_VERSION = re.compile(r'(Clang .*|clang version .*) \(https:/.*\)')
24-
25-
# Parse short Clang version: 'clang version 18.0.4'
26-
CLANG_SHORT_VERSION = re.compile(r'clang version (.*)')
20+
# Parse Clang version (truncated examples using '...'):
21+
# 'Clang 21.0.0 (clang-2100.1.1.101)'
22+
# 'clang version 18.0.4'
23+
# 'Apple clang version 21.0.0 (clang-2100.1.1.101)'
24+
# 'Clang 18.0.4 (https://android.googlesource.com/toolchain/llvm-project d80...62)'
25+
CLANG_VERSION_REGEX = re.compile(
26+
r'(?:([A-Za-z_-][A-Za-z_ -]+) .*)?' # Vendor name: 'Android' or 'Apple'
27+
r'(?:Clang|clang version) ' # 'Clang' or 'clang version'
28+
r'([0-9]+\.[0-9a-z.+]+)' # version
29+
)
2730

2831

2932
def exit_error(msg):
@@ -48,7 +51,7 @@ def get_makefile_vars():
4851
return sysconfig.__main__._parse_makefile(makefile)
4952

5053

51-
def get_gil_disable():
54+
def get_gil_disabled():
5255
# Look in the current working directory
5356
pyconfig_h = 'pyconfig.h'
5457
with open(pyconfig_h, encoding="utf-8") as fp:
@@ -83,8 +86,7 @@ def get_build_info(git_tag, git_branch, git_version):
8386
git_id = "main"
8487

8588
sep = ":" if git_version else ""
86-
87-
build_info = f"{git_id}{sep}{git_version}, {build_date:.20s}, {build_time:.9s}"
89+
build_info = f"{git_id}{sep}{git_version}, {build_date}, {build_time}"
8890
return (build_info, git_id)
8991

9092

@@ -140,7 +142,7 @@ def _get_compiler():
140142
if compiler:
141143
return compiler
142144

143-
# Running _getcompiler failed, run directly the compiler (--version)
145+
# Running _getcompiler failed, run the compiler with --version
144146
CC = makefile_vars.get('CC')
145147
if not CC:
146148
exit_error(f"ERROR: Unable to locate CC in Makefile")
@@ -154,16 +156,15 @@ def _get_compiler():
154156
return None
155157

156158

157-
def shorter_clang_version(compiler):
158-
# Make verbose Clang version shorter: strip the prefix and URL
159-
match = CLANG_VERBOSE_VERSION.search(compiler)
159+
def compact_compiler(compiler):
160+
match = CLANG_VERSION_REGEX.search(compiler)
160161
if match:
161-
compiler = match.group(1)
162-
163-
# Use a full match: don't replace 'Apple clang version 21.0.0' for example
164-
match = CLANG_SHORT_VERSION.fullmatch(compiler)
165-
if match:
166-
compiler = 'Clang ' + match.group(1)
162+
vendor = match.group(1)
163+
version = match.group(2)
164+
if vendor:
165+
compiler = f'{vendor} Clang {version}'
166+
else:
167+
compiler = f'Clang {version}'
167168

168169
return compiler
169170

@@ -176,7 +177,7 @@ def get_compiler(compiler):
176177
# (see Programs/_getcompiler.c)
177178
compiler = 'C'
178179

179-
compiler = shorter_clang_version(compiler)
180+
compiler = compact_compiler(compiler)
180181

181182
return f'[{compiler}]'
182183

@@ -208,7 +209,7 @@ def main():
208209

209210
if free_threading is None:
210211
# Get Py_GIL_DISABLED macro from pyconfig.h
211-
free_threading = get_gil_disable()
212+
free_threading = get_gil_disabled()
212213

213214
if free_threading:
214215
version = f"{PY_VERSION} free-threading build ({build_info}) {compiler}"

0 commit comments

Comments
 (0)