From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 1/3] xap_helper_cxx: use write_file helper
Date: Sat, 11 Nov 2023 23:35:10 +0000 [thread overview]
Message-ID: <20231111233512.1678903-1-e@80x24.org> (raw)
PublicInbox::IO already gets loaded by PublicInbox::Spawn, so
there's no avoiding it even if we want fast startup time :<
---
lib/PublicInbox/XapHelperCxx.pm | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm
index 908a71f4..090ac9b7 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');
@@ -62,11 +63,11 @@ sub build () {
my ($prog) = ($bin =~ m!/([^/]+)\z!);
my $tmp = File::Temp->newdir(DIR => $dir) // die "newdir: $!";
my $src = "$tmp/$prog.cpp";
- open my $fh, '>', $src;
+ my $fh = write_file '>', $src;
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));
next reply other threads:[~2023-11-11 23:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-11 23:35 Eric Wong [this message]
2023-11-11 23:35 ` [PATCH 2/3] xap_helper_cxx: make the build process ccache-friendly Eric Wong
2023-11-11 23:35 ` [PATCH 3/3] xap_client: spawn C++ xap_helper directly Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231111233512.1678903-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).