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, T_SCC_BODY_TEXT_LINE 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 078911F518 for ; Mon, 13 Nov 2023 13:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1699881353; bh=mqcFiVZPEOtniVykGNLM/CJaJUfvXVofVcrXoDfwwIo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=2KWK76M2vEwK2xbdi4VdEaL5pbe6nbBdxCWM9pJS4yql6oNcJEysDVGti4WQVOKXM X3W2aU6298v7Xgoka5iw5lezkvhgqM4oKLIjun562tLBW1H8WsTqL/wrSfbhZ3FUo+ ukPrrW34vA59bnNdMM2i/YTZO6naFE92NLvTd5F8= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/18] xap_helper_cxx: use write_file helper Date: Mon, 13 Nov 2023 13:15:37 +0000 Message-Id: <20231113131551.843230-5-e@80x24.org> In-Reply-To: <20231113131551.843230-1-e@80x24.org> References: <20231113131551.843230-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: PublicInbox::IO already gets loaded by PublicInbox::Spawn, so there's no avoiding it even if we want fast startup time :< But startup time for this piece will be less relevant in the near future... --- lib/PublicInbox/XapHelperCxx.pm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm index 908a71f4..0891074d 100644 --- a/lib/PublicInbox/XapHelperCxx.pm +++ b/lib/PublicInbox/XapHelperCxx.pm @@ -8,6 +8,7 @@ package PublicInbox::XapHelperCxx; use v5.12; use PublicInbox::Spawn qw(run_qx which); +use PublicInbox::IO qw(read_all write_file); use PublicInbox::Search; use Fcntl qw(SEEK_SET); use Config; @@ -39,11 +40,11 @@ EOM sub needs_rebuild () { open my $fh, '<', "$dir/XFLAGS" or return 1; - chomp(my $prev = <$fh>); + chomp(my $prev = read_all($fh)); return 1 if $prev ne $xflags; open $fh, '<', "$dir/xap_modversion" or return 1; - chomp($prev = <$fh>); + chomp($prev = read_all($fh)); $prev or return 1; $xap_modversion = xap_cfg('--modversion'); @@ -66,7 +67,7 @@ sub build () { for (@srcs) { say $fh qq(# line 1 "$_"); open my $rfh, '<', $_; - print $fh PublicInbox::IO::read_all $rfh; + print $fh read_all($rfh); } print $fh PublicInbox::Search::generate_cxx(); print $fh PublicInbox::CodeSearch::generate_cxx(); @@ -86,13 +87,8 @@ sub build () { my $cmd = "$cxx $src $fl $xflags -o $tmp/$prog"; system($cmd) and die "$cmd failed: \$?=$?"; - open $fh, '>', "$tmp/XFLAGS"; - say $fh $xflags; - close $fh; - - open $fh, '>', "$tmp/xap_modversion"; - say $fh $xap_modversion; - close $fh; + write_file '>', "$tmp/XFLAGS", $xflags, "\n"; + write_file '>', "$tmp/xap_modversion", $xap_modversion, "\n"; undef $xap_modversion; # do we ever build() twice? # not quite atomic, but close enough :P rename("$tmp/$_", "$dir/$_") for ($prog, qw(XFLAGS xap_modversion));