From 06eb1211986901a74817d619bde855508c7cb7bd Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sun, 10 Sep 2023 12:49:39 +1000 Subject: [PATCH 1/2] _cc_is_clang: allow for a vendor prefix on the --version output Several distributions build clang with CLANG_VENDOR defined: https://github.com/llvm/llvm-project/blob/444abb39/clang/lib/Basic/Version.cpp#L96 For example: tony@enceladus:~$ grep PRETTY_NAME /etc/os-release PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" tony@enceladus:~$ clang --version | head -n1 Debian clang version 14.0.6 tony@enceladus:~$ grep PRETTY_NAME /etc/os-release PRETTY_NAME="Ubuntu 22.04.3 LTS" tony@enceladus:~$ clang --version | head -n1 Ubuntu clang version 14.0.0-1ubuntu1.1 openbsd69$ uname -a OpenBSD openbsd69.tony.develop-help.com 6.9 GENERIC#464 amd64 openbsd69$ cc --version | head -n1 OpenBSD clang version 10.0.1 enceladus:~$ clang-15 --version | head -n1 Alpine clang version 15.0.7 enceladus:~$ clang --version | head -n1 Alpine clang version 15.0.7 enceladus:~$ grep PRETTY_NAME /etc/os-release PRETTY_NAME="Alpine Linux v3.17" From https://trac.macports.org/wiki/XcodeVersionInfo : Apple clang version 14.0.0 (clang-1400.0.29.202) so adjust the regexp to allow a leading vendor. It's possible for the vendor to contain spaces, but I haven't found any examples of that in the wild. Keep the match tight by checking for the following " version". --- lib/ExtUtils/CppGuess.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExtUtils/CppGuess.pm b/lib/ExtUtils/CppGuess.pm index 0be5783..0a92fdf 100644 --- a/lib/ExtUtils/CppGuess.pm +++ b/lib/ExtUtils/CppGuess.pm @@ -405,7 +405,7 @@ sub _cc_is_clang { $self->{is_clang} = 0; my $cc_version = _capture( "$cc --version" ); if ( - $cc_version =~ m/\A(?:clang|apple llvm)/i + $cc_version =~ m/\A(?:(?:\S+ )?clang version|apple llvm)/i || $cc eq 'clang' # because why would they lie? || (($self->_config->{gccversion} || '') =~ /Clang|Apple LLVM/), ) { From 5e475041d53fa09b55b1e357cd4ba4590d0d6a20 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sun, 10 Sep 2023 13:40:55 +1000 Subject: [PATCH 2/2] 002_iccp.t: mock some --version output to test clang changes --- t/002_icpp.t | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/t/002_icpp.t b/t/002_icpp.t index 90b42a6..2d9b0d0 100644 --- a/t/002_icpp.t +++ b/t/002_icpp.t @@ -95,6 +95,61 @@ my @METHODS = qw( run_test(@$_) for @DATA; +# mock some compiler output +my $old_capture = \&ExtUtils::CppGuess::_capture; +our $CAPTURES; +{ + no warnings "redefine"; + *ExtUtils::CppGuess::_capture = + sub { + my @cmd = @_; + if (my $result = $CAPTURES->{"@cmd"}) { + note "Mocking output of @cmd: $result"; + return $result; + } + goto &$old_capture; + }; +} +my @CAPS = + ( + [ + { cc => "cc", config => { ccflags => '' } }, + { + is_sunstudio => 0, + is_msvc => undef, is_gcc => undef, is_clang => 1, + compiler_command => 'clang++ -xc++ -Wno-reserved-user-defined-literal', + linker_flags => '-lstdc++', + }, + { "cc --version" => "OpenBSD clang version 10.0.1" }, + ], + [ + { cc => "clang-15", config => { ccflags => '' } }, + { + is_sunstudio => 0, + is_msvc => undef, is_gcc => undef, is_clang => 1, + compiler_command => 'clang++ -xc++ -Wno-reserved-user-defined-literal', + linker_flags => '-lstdc++', + }, + { "clang-15 --version" => "Debian clang version 15.0.7" }, + ], + [ + { cc => "cc", config => { ccflags => '' } }, + { + is_sunstudio => 0, + is_msvc => undef, is_gcc => 1, is_clang => 0, + compiler_command => 'g++ -xc++', + linker_flags => '-lstdc++', + }, + { "cc --version" => "cc (Debian 12.2.0-14) 12.2.0" }, + ], + ); + +for my $test (@CAPS) { + my ($args, $expect, $cap) = @$test; + local $CAPTURES = $cap; + run_test($args, $expect); +} + done_testing; sub run_test {