diff --git a/Changes b/Changes index 078cfce4..9c8cd8a2 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Revision history for {{$dist->name}} {{$NEXT}} + - Alien::Base's Inline method once again returns only -I flags in + INC, with other compiler flags in CCFLAGSEX. Inline::C was quoting + the combined flags as a single argument, which broke Aliens that have + non -I flags in their cflags. ExtUtils::Depends, which only looks at + INC, still gets all of the compiler flags there (gh#430, gh#443) 2.88 2026-09-19 03:03:10 -0600 - Fixes for Solaris (gh#442) diff --git a/lib/Alien/Base.pm b/lib/Alien/Base.pm index 50b9e921..4599f8fc 100644 --- a/lib/Alien/Base.pm +++ b/lib/Alien/Base.pm @@ -915,18 +915,40 @@ sub inline_auto_include { $class->runtime_prop->{inline_auto_include} || $class->config('inline_auto_include') || [] } +sub _called_from_extutils_depends { + my $i = 0; + while(my $package = caller($i++)) { + return 1 if $package eq 'ExtUtils::Depends'; + } + 0; +} + sub Inline { my ($class, $language) = @_; return unless defined $language; return if $language !~ /^(C|CPP)$/; my $config = { - # INC should arguably be for -I flags only, but - # this improves compat with ExtUtils::Depends. - # see gh#107, gh#108 - INC => $class->cflags, LIBS => $class->libs, }; + if(_called_from_extutils_depends()) { + # ExtUtils::Depends piggybacks on this interface, but only + # looks at INC, LIBS and TYPEMAPS, so it needs all of the + # compiler flags in INC. see gh#107, gh#108 + $config->{INC} = $class->cflags; + } else { + # Inline::C quotes the whole of INC as a single argument if it + # contains spaces and anything other than -I flags. see gh#430 + # keep mode is used so that quotes and escapes survive the round trip. + my $cflags = $class->cflags; + $cflags = '' unless defined $cflags; + $cflags =~ s/^\s+//; + my @cflags = grep { defined $_ && length $_ } Text::ParseWords::parse_line('\s+', 1, $cflags); + $config->{INC} = join ' ', grep /^["']?-I/, @cflags; + my $ccflagsex = join ' ', grep !/^["']?-I/, @cflags; + $config->{CCFLAGSEX} = $ccflagsex if length $ccflagsex; + } + if (@{ $class->inline_auto_include } > 0) { $config->{AUTO_INCLUDE} = join "\n", map { "#include \"$_\"" } @{ $class->inline_auto_include }; } diff --git a/t/alien_base.t b/t/alien_base.t index 232846bf..f1356be5 100644 --- a/t/alien_base.t +++ b/t/alien_base.t @@ -325,6 +325,67 @@ subtest 'build flags' => sub { }; +subtest 'Inline' => sub { + + our $cflags; + + { + package Alien::InlineTest; + use parent 'Alien::Base'; + sub cflags { $cflags } + sub libs { '-L/foo/lib -lfoo' } + sub inline_auto_include { [] } + } + + { + package ExtUtils::Depends; + sub alien_base_test_load { Alien::InlineTest->Inline('C') } + } + + is( Alien::InlineTest->Inline('Perl'), U(), 'unsupported language' ); + + subtest 'include flags only' => sub { + local $cflags = '-I/foo/include'; + is( + Alien::InlineTest->Inline('C'), + { INC => '-I/foo/include', LIBS => '-L/foo/lib -lfoo' }, + ); + }; + + subtest 'mixed flags' => sub { + local $cflags = ' -I/foo/include -DBAR=1 -I/baz/include -O2 '; + is( + Alien::InlineTest->Inline('C'), + { INC => '-I/foo/include -I/baz/include', CCFLAGSEX => '-DBAR=1 -O2', LIBS => '-L/foo/lib -lfoo' }, + ); + is( + Alien::InlineTest->Inline('CPP'), + { INC => '-I/foo/include -I/baz/include', CCFLAGSEX => '-DBAR=1 -O2', LIBS => '-L/foo/lib -lfoo' }, + ); + }; + + subtest 'quotes and escapes are preserved' => sub { + local $cflags = q{-I"/foo bar/include" "-I/baz qux/include" -DSTR=\"x\" -IC:\foo\include}; + is( + Alien::InlineTest->Inline('C'), + { + INC => q{-I"/foo bar/include" "-I/baz qux/include" -IC:\foo\include}, + CCFLAGSEX => q{-DSTR=\"x\"}, + LIBS => '-L/foo/lib -lfoo', + }, + ); + }; + + subtest 'called from ExtUtils::Depends' => sub { + local $cflags = '-I/foo/include -DBAR=1'; + is( + ExtUtils::Depends::alien_base_test_load(), + { INC => '-I/foo/include -DBAR=1', LIBS => '-L/foo/lib -lfoo' }, + ); + }; + +}; + subtest 'ffi_name' => sub { require Alien::libfoo1;