Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lnt/testing/util/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def get_cc_info(path, cc_flags=[]):
logger.error("unable to find compiler version: %r: %r" %
(cc, cc_version))
else:
m = re.match(r'(.*) version ([^ ]*) +(\([^(]*\))(.*)', version_ln)
m = re.match(r'(.*) version ([^ ]*) (?:[0-9]+ )?+(\([^(]*\))(.*)',
version_ln)
if m is not None:
cc_name, cc_version_num, cc_build_string, cc_extra = m.groups()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you never care about the date group, how about just making the regexp a non-capturing group instead

        m = re.match(r'(.*) version ([^ ]*) (?:[0-9]+ )?+(\([^(]*\))(.*)',
                     version_ln)

That way you don't need the change on line 82. But looks good with or without that change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Yeah that's a good idea, will add

else:
Expand Down Expand Up @@ -104,15 +105,17 @@ def get_cc_info(path, cc_flags=[]):
cc_src_tag = cc_version_num

elif cc_name == 'gcc' and (cc_extra == '' or
cc_extra == '(GCC)' or
re.match(r' \(dot [0-9]+\)', cc_extra)):
cc_norm_name = 'gcc'
m = re.match(r'\(Apple Inc. build ([0-9]*)\)', cc_build_string)
if m:
cc_build = 'PROD'
cc_src_tag, = m.groups()
elif 'experimental' in cc_build_string:
cc_build = 'DEV'
else:
logger.error('unable to determine gcc build version: %r' %
cc_build_string)
cc_build = 'PROD'
elif (cc_name in ('clang', 'LLVM', 'Debian clang', 'Apple clang',
'Apple LLVM') and
(cc_extra == '' or 'based on LLVM' in cc_extra or
Expand Down
22 changes: 22 additions & 0 deletions tests/SharedInputs/FakeCompilers/fakecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ def print_verbose_info(self):
"%s" "-cc1" "-E" ... more boring stuff here ...""" % (
g_program,), file=sys.stderr)

class GCCDebian(FakeCompiler):
compiler_name = "gcc-debian"

def print_verbose_info(self):
print("""\
Target: x86_64-linux-gnu
gcc version 12.2.0 (Debian 12.2.0-14+deb12u1)""", file=sys.stderr)

def print_dumpmachine(self):
print("x86_64-linux-gnu")

class GCCTrunk(FakeCompiler):
compiler_name = "gcc-trunk"

def print_verbose_info(self):
print("""\
Target: x86_64-linux-gnu
gcc version 16.0.0 20250807 (experimental) (GCC)""", file=sys.stderr)

def print_dumpmachine(self):
print("x86_64-linux-gnu")


fake_compilers = dict((value.compiler_name, value)
for key, value in locals().items()
Expand Down
1 change: 1 addition & 0 deletions tests/SharedInputs/FakeCompilers/gcc-debian
1 change: 1 addition & 0 deletions tests/SharedInputs/FakeCompilers/gcc-trunk
16 changes: 16 additions & 0 deletions tests/testing/Compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ def get_info(name):
pprint.pprint(info)
assert info['cc_name'] == 'clang'
assert info['cc_version_number'] == '3.2'

# Check a GCC packaged from Debian.
info = get_info("gcc-debian")
pprint.pprint(info)
assert info['cc_name'] == 'gcc'
assert info['cc_build'] == 'PROD'
assert info['cc_version_number'] == '12.2.0'
assert info['cc_target'] == 'x86_64-linux-gnu'

# Check a GCC built from trunk.
info = get_info("gcc-trunk")
pprint.pprint(info)
assert info['cc_name'] == 'gcc'
assert info['cc_build'] == 'DEV'
assert info['cc_version_number'] == '16.0.0'
assert info['cc_target'] == 'x86_64-linux-gnu'