From b6e85e2cf16f762fec461198183103506f2be087 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Wed, 13 Aug 2025 13:15:01 +0800 Subject: [PATCH 1/2] Handle non-Apple packaged GCC versions Currently if you use a version of GCC packaged from a Linux distro or built from trunk, you'll get an inferred machine name of something like "foo__gcc_None__riscv64". The None is supposed to be the cc_build part of the inferred version info, but currently we only handle this for Apple packaged GCC versions. This teaches the version handling to handle these other types of GCC, which will have a version string like gcc version 16.0.0 20250807 (experimental) (GCC) or gcc version 12.2.0 (Debian 12.2.0-14+deb12u1) --- lnt/testing/util/compilers.py | 11 ++++++---- .../FakeCompilers/fakecompiler.py | 22 +++++++++++++++++++ tests/SharedInputs/FakeCompilers/gcc-debian | 1 + tests/SharedInputs/FakeCompilers/gcc-trunk | 1 + tests/testing/Compilers.py | 16 ++++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 120000 tests/SharedInputs/FakeCompilers/gcc-debian create mode 120000 tests/SharedInputs/FakeCompilers/gcc-trunk diff --git a/lnt/testing/util/compilers.py b/lnt/testing/util/compilers.py index a232632a..af45680d 100644 --- a/lnt/testing/util/compilers.py +++ b/lnt/testing/util/compilers.py @@ -76,9 +76,10 @@ 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() + cc_name, cc_version_num, _, cc_build_string, cc_extra = m.groups() else: # If that didn't match, try a more basic pattern. m = re.match(r'(.*) version ([^ ]*)', version_ln) @@ -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 diff --git a/tests/SharedInputs/FakeCompilers/fakecompiler.py b/tests/SharedInputs/FakeCompilers/fakecompiler.py index 1df93baa..5fe1970f 100755 --- a/tests/SharedInputs/FakeCompilers/fakecompiler.py +++ b/tests/SharedInputs/FakeCompilers/fakecompiler.py @@ -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() diff --git a/tests/SharedInputs/FakeCompilers/gcc-debian b/tests/SharedInputs/FakeCompilers/gcc-debian new file mode 120000 index 00000000..1b836b13 --- /dev/null +++ b/tests/SharedInputs/FakeCompilers/gcc-debian @@ -0,0 +1 @@ +fakecompiler.py \ No newline at end of file diff --git a/tests/SharedInputs/FakeCompilers/gcc-trunk b/tests/SharedInputs/FakeCompilers/gcc-trunk new file mode 120000 index 00000000..1b836b13 --- /dev/null +++ b/tests/SharedInputs/FakeCompilers/gcc-trunk @@ -0,0 +1 @@ +fakecompiler.py \ No newline at end of file diff --git a/tests/testing/Compilers.py b/tests/testing/Compilers.py index 901c4a02..6aacc667 100644 --- a/tests/testing/Compilers.py +++ b/tests/testing/Compilers.py @@ -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' From 5c2e2c145c75d228cd67337c543d8c4419c5d01b Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Wed, 13 Aug 2025 15:37:12 +0800 Subject: [PATCH 2/2] Use non-capturing group --- lnt/testing/util/compilers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnt/testing/util/compilers.py b/lnt/testing/util/compilers.py index af45680d..574f4ffc 100644 --- a/lnt/testing/util/compilers.py +++ b/lnt/testing/util/compilers.py @@ -76,10 +76,10 @@ 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 ([^ ]*) ([0-9]+ )?+(\([^(]*\))(.*)', + 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() + cc_name, cc_version_num, cc_build_string, cc_extra = m.groups() else: # If that didn't match, try a more basic pattern. m = re.match(r'(.*) version ([^ ]*)', version_ln)