Skip to content

Commit 37a5ba2

Browse files
committed
Reapply "Handle non-Apple packaged GCC versions (#34)" (#36)
This reverts commit 0d5b979, with a fix included for the regex. We had the + quantifier for the space between cc_version_num and cc_build_string in the wrong place which Python 3.10 complained about (but later versions mysteriously silently accepted?)
1 parent 0d5b979 commit 37a5ba2

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

lnt/testing/util/compilers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def get_cc_info(path, cc_flags=[]):
7676
logger.error("unable to find compiler version: %r: %r" %
7777
(cc, cc_version))
7878
else:
79-
m = re.match(r'(.*) version ([^ ]*) +(\([^(]*\))(.*)', version_ln)
79+
m = re.match(r'(.*) version ([^ ]*) +(?:[0-9]+ +)?(\([^(]*\))(.*)',
80+
version_ln)
8081
if m is not None:
8182
cc_name, cc_version_num, cc_build_string, cc_extra = m.groups()
8283
else:
@@ -104,15 +105,17 @@ def get_cc_info(path, cc_flags=[]):
104105
cc_src_tag = cc_version_num
105106

106107
elif cc_name == 'gcc' and (cc_extra == '' or
108+
cc_extra == '(GCC)' or
107109
re.match(r' \(dot [0-9]+\)', cc_extra)):
108110
cc_norm_name = 'gcc'
109111
m = re.match(r'\(Apple Inc. build ([0-9]*)\)', cc_build_string)
110112
if m:
111113
cc_build = 'PROD'
112114
cc_src_tag, = m.groups()
115+
elif 'experimental' in cc_build_string:
116+
cc_build = 'DEV'
113117
else:
114-
logger.error('unable to determine gcc build version: %r' %
115-
cc_build_string)
118+
cc_build = 'PROD'
116119
elif (cc_name in ('clang', 'LLVM', 'Debian clang', 'Apple clang',
117120
'Apple LLVM') and
118121
(cc_extra == '' or 'based on LLVM' in cc_extra or

tests/SharedInputs/FakeCompilers/fakecompiler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ def print_verbose_info(self):
178178
"%s" "-cc1" "-E" ... more boring stuff here ...""" % (
179179
g_program,), file=sys.stderr)
180180

181+
class GCCDebian(FakeCompiler):
182+
compiler_name = "gcc-debian"
183+
184+
def print_verbose_info(self):
185+
print("""\
186+
Target: x86_64-linux-gnu
187+
gcc version 12.2.0 (Debian 12.2.0-14+deb12u1)""", file=sys.stderr)
188+
189+
def print_dumpmachine(self):
190+
print("x86_64-linux-gnu")
191+
192+
class GCCTrunk(FakeCompiler):
193+
compiler_name = "gcc-trunk"
194+
195+
def print_verbose_info(self):
196+
print("""\
197+
Target: x86_64-linux-gnu
198+
gcc version 16.0.0 20250807 (experimental) (GCC)""", file=sys.stderr)
199+
200+
def print_dumpmachine(self):
201+
print("x86_64-linux-gnu")
202+
181203

182204
fake_compilers = dict((value.compiler_name, value)
183205
for key, value in locals().items()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fakecompiler.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fakecompiler.py

tests/testing/Compilers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,19 @@ def get_info(name):
6666
pprint.pprint(info)
6767
assert info['cc_name'] == 'clang'
6868
assert info['cc_version_number'] == '3.2'
69+
70+
# Check a GCC packaged from Debian.
71+
info = get_info("gcc-debian")
72+
pprint.pprint(info)
73+
assert info['cc_name'] == 'gcc'
74+
assert info['cc_build'] == 'PROD'
75+
assert info['cc_version_number'] == '12.2.0'
76+
assert info['cc_target'] == 'x86_64-linux-gnu'
77+
78+
# Check a GCC built from trunk.
79+
info = get_info("gcc-trunk")
80+
pprint.pprint(info)
81+
assert info['cc_name'] == 'gcc'
82+
assert info['cc_build'] == 'DEV'
83+
assert info['cc_version_number'] == '16.0.0'
84+
assert info['cc_target'] == 'x86_64-linux-gnu'

0 commit comments

Comments
 (0)