From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 37A001F68D for ; Fri, 27 Oct 2023 22:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698445277; bh=ZizJElwe4C/gc+4csw8yCLSly5T41cF/k53Z/vonlj0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OaHWqoV6X6b4x1OQD/kyA9m3tSbMJd2Q7wBv+YlvPG8vIYMx4YHEcmP/o3cPof5Sl 7cKFfvAMsVakZUUkubjis2jmLNzxREvyFdG50WfGRVseVBYKtgmtHCR5cHS7cvLLUk 6/MEvkKMJOJQBL0poTwcDBNnakXdpzfraWCmM0dI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/10] gcf2: simplify pkg-config and Inline::C setup Date: Fri, 27 Oct 2023 22:21:12 +0000 Message-ID: <20231027222116.4034363-7-e@80x24.org> In-Reply-To: <20231027222116.4034363-1-e@80x24.org> References: <20231027222116.4034363-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can use run_qx and try_cat to make the build setup simpler. --- lib/PublicInbox/Gcf2.pm | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/PublicInbox/Gcf2.pm b/lib/PublicInbox/Gcf2.pm index 4f163cde..502bf33a 100644 --- a/lib/PublicInbox/Gcf2.pm +++ b/lib/PublicInbox/Gcf2.pm @@ -5,11 +5,11 @@ # other libgit2 stuff may go here, too. package PublicInbox::Gcf2; use v5.12; -use PublicInbox::Spawn qw(which popen_rd); # may set PERL_INLINE_DIRECTORY +use PublicInbox::Spawn qw(which run_qx); # may set PERL_INLINE_DIRECTORY use Fcntl qw(SEEK_SET); use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); use IO::Handle; # autoflush -use PublicInbox::Git qw(read_all); +use PublicInbox::Git; use PublicInbox::Lock; BEGIN { @@ -27,29 +27,16 @@ BEGIN { my $pc = which($ENV{PKG_CONFIG} // 'pkg-config') // die "pkg-config missing for libgit2"; my ($dir) = (__FILE__ =~ m!\A(.+?)/[^/]+\z!); - open my $err, '+>', "$inline_dir/.public-inbox.pkg-config.err"; my $vals = {}; - my $rdr = { 2 => $err }; + my $rdr = { 2 => \(my $err) }; my @switches = qw(modversion cflags libs); for my $k (@switches) { - my $rd = popen_rd([$pc, "--$k", 'libgit2'], undef, $rdr); - chomp(my $val = do { local $/; <$rd> }); - CORE::close($rd) or last; # checks for error and sets $? + chomp(my $val = run_qx([$pc, "--$k", 'libgit2'], undef, $rdr)); + die "E: libgit2 not installed: $err\n" if $?; $vals->{$k} = $val; } - if (!$?) { - # note: we name C source files .h to prevent - # ExtUtils::MakeMaker from automatically trying to - # build them. - my $f = "$dir/gcf2_libgit2.h"; - open my $src, '<', $f; - $c_src = read_all($src); - } - unless ($c_src) { - seek($err, 0, SEEK_SET); - $err = read_all($err); - die "E: libgit2 not installed: $err\n"; - } + my $f = "$dir/gcf2_libgit2.h"; + $c_src = PublicInbox::Git::try_cat($f) or die "cat $f: $!"; # append pkg-config results to the source to ensure Inline::C # can rebuild if there's changes (it doesn't seem to detect # $CFG{CCFLAGSEX} nor $CFG{CPPFLAGS} changes)