Skip to content

Commit

Permalink
Merge 309931a into 0216b47
Browse files Browse the repository at this point in the history
  • Loading branch information
zmughal committed Oct 12, 2022
2 parents 0216b47 + 309931a commit fff7601
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
uses: PDLPorters/devops/github-actions/ci-dist@master
with:
target-install-dist-perl-deps: true
dist-perl-deps-configure: ExtUtils::MakeMaker Devel::CheckLib
dist-perl-deps-configure: ExtUtils::MakeMaker Devel::CheckLib File::Which

- name: 'ci-dist: target-test-release-testing'
uses: PDLPorters/devops/github-actions/ci-dist@master
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
uname -a
yum -y install perl perl-App-cpanminus gcc bzip2 patch
- run: perl -V
- run: cpanm -n ExtUtils::MakeMaker Devel::CheckLib && cpanm -n --installdeps . || cat ~/.cpanm/build.log
- run: cpanm -n ExtUtils::MakeMaker Devel::CheckLib File::Which && cpanm -n --installdeps . || cat ~/.cpanm/build.log
- name: Run tests
env:
HARNESS_OPTIONS: j4
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
run: |
export PATH="/cygdrive/c/cx/bin:$PATH"
cd $( cygpath -u $GITHUB_WORKSPACE )
cpanm -n Devel::CheckLib && cpanm -n --installdeps . || cat ~/.cpanm/build.log
cpanm -n Devel::CheckLib File::Which && cpanm -n --installdeps . || cat ~/.cpanm/build.log
- name: Run tests (no coverage)
env:
HARNESS_OPTIONS: j4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/downstream-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: PDLPorters/devops
ref: master
ref: config-dep-file-which
path: .github/devops
- run: make -C .github/devops/docker -f Makefile.docker docker.pdl PATH_TO_PDL=$(pwd)
- run: docker save pdl:latest --output pdl-latest.tar
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: PDLPorters/devops
ref: master
ref: config-dep-file-which
path: .github/devops
- uses: perl-actions/install-with-cpanm@v1
- run: |
Expand Down
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- allow [o] on OtherPars (#362)
- fix conv2d to allow complex arguments (#407) - thanks @wlmb
- Add complex support to interpolate (#408) - thanks @KJ7LNW
- Refactor PDL::IO::Browser curses detection to additionally use ncurses*-config (#412)
- Add File::Which as a configure dependency (previously runtime only) (#412)

2.080 2022-05-28
- make IO::STL work on big-endian systems (#394) - thanks @sebastic for report
Expand Down
86 changes: 73 additions & 13 deletions IO/Browser/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use warnings;
use ExtUtils::MakeMaker;
use File::Spec;
eval { require Devel::CheckLib; Devel::CheckLib->import; };
eval { require File::Which; };

my @pack = (["browser.pd", qw(Browser PDL::IO::Browser)]);

Expand All @@ -20,29 +21,88 @@ $hash{'clean'}{FILES} .= ' browse$(OBJ_EXT) browse$(EXE_EXT) Browser.c Browser.p
# (4) confirm configuration
# (5) write Makefile or dummy as appropriate

my $incstring;
foreach my $incl ( qw( curses.h ncurses/curses.h ncurses.h ncurses/ncurses.h ncursesw/ncurses.h ) ) {
sub _read_pipe {
my (@command) = @_;
open( my $fh, '-|', @command) or die "Unable to run @command: $!";
chomp(my $output = do { local $/; <$fh> });
$output;
}

my @possible_headers = qw( curses.h ncurses/curses.h ncurses.h ncurses/ncurses.h ncursesw/ncurses.h );
my $found_header;
foreach my $incl (@possible_headers) {
if (eval { check_lib(header=>$incl) }) {
$incstring = $incl;
$found_header = $incl;
last;
}
};
$hash{DEFINE} .= ' -DCURSES=' . '\\"' . $incstring . '\\"' if defined $incstring;

my $libstring;
foreach my $libr ( qw( curses ncurses ncursesw ) ) {
if (eval { check_lib(lib=>$libr) }) {
$libstring = '-l' . $libr;
last;
}

sub conf_via_ncurses_config {
return () unless $found_header;
# NOTE the ncurses*-config executables are shell scripts so `sh` is
# required.
return () unless File::Which::which('sh');

my @nc_configs = qw(
ncurses6-config
ncursesw6-config
ncurses5-config
ncursesw5-config
);
for my $nc_conf (@nc_configs) {
local $ENV{NCURSES_CONFIG_PROG} = $nc_conf;
# NOTE which() can not find the script on Windows because it does have
# have a PATHEXT suffix. For now, just try to run it anyway.
next unless File::Which::which($nc_conf) || $^O eq 'MSWin32';
if( eval { (my $version = _read_pipe(qw(sh -c), '$NCURSES_CONFIG_PROG --version')) =~ / \A [0-9.]+ \Z /x } ) {
my $cflags = _read_pipe(qw(sh -c), '$NCURSES_CONFIG_PROG --cflags');
my $libs = _read_pipe(qw(sh -c), '$NCURSES_CONFIG_PROG --libs');
return (
header => $found_header,
inc => $cflags,
libs => $libs,
);
}
}
return ();
}

sub conf_via_checklib {
return () unless $found_header;

my $libstring;
foreach my $libr ( qw( curses ncurses ncursesw ) ) {
if (eval { check_lib(lib=>$libr) }) {
$libstring = '-l' . $libr;
last;
}
}

if( defined $libstring ) {
return (
header => $found_header,
inc => '',
libs => $libstring,
);
}

return ();
}

my %conf_data;
%conf_data = conf_via_ncurses_config();
%conf_data = conf_via_checklib() unless %conf_data;
if( %conf_data ) {
$hash{DEFINE} .= ' -DCURSES=' . '\\"' . $conf_data{header} . '\\"';
$hash{INC} .= ' ' . $conf_data{inc} if $conf_data{inc};
push @{$hash{LIBS}} , $conf_data{libs};
}
push @{$hash{LIBS}} , $libstring if defined $libstring;

# Add genpp rule
undef &MY::postamble; # suppress warning
*MY::postamble = sub { pdlpp_postamble_int(@pack); };

if (defined($incstring) && defined($libstring)) {
if ( %conf_data ) {
WriteMakefile(%hash);
} else {
write_dummy_make("Curses capable library not found, not building PDL::IO::Browser");
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ my %makefile_hash = (
LICENSE => 'perl',
CONFIGURE_REQUIRES => {
'Devel::CheckLib' => '1.01',
'File::Which' => 0,
'Carp' => 1.20, # EU::MM seems to need this not to crash
'ExtUtils::MakeMaker' => '7.12', # working .g.c
'File::Path' => 0,
Expand Down

0 comments on commit fff7601

Please sign in to comment.