dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 3/5] xap_helper_cxx: drop chdir usage in build
Date: Thu,  7 Dec 2023 11:42:44 +0000	[thread overview]
Message-ID: <20231207114246.3614375-3-e@80x24.org> (raw)
In-Reply-To: <20231207114246.3614375-1-e@80x24.org>

While chdir simplifies path manipulation on our end, its use
falls over when PERL5LIB/@INC contains relative paths which need
to be made absolute.  It's fewer lines of code to get eliminate
chdir usage than it is to keep using relative paths in most
places.
---
 lib/PublicInbox/XapHelperCxx.pm | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm
index 1aa75f2a..17f988ee 100644
--- a/lib/PublicInbox/XapHelperCxx.pm
+++ b/lib/PublicInbox/XapHelperCxx.pm
@@ -60,17 +60,12 @@ sub build () {
 	}
 	require PublicInbox::CodeSearch;
 	require PublicInbox::Lock;
-	require PublicInbox::OnDestroy;
 	my ($prog) = ($bin =~ m!/([^/]+)\z!);
 	my $lk = PublicInbox::Lock->new("$dir/$prog.lock")->lock_for_scope;
 	write_file '>', "$dir/$prog.cpp", qq{#include "xap_helper.h"\n},
 			PublicInbox::Search::generate_cxx(),
 			PublicInbox::CodeSearch::generate_cxx();
 
-	opendir my $dh, '.';
-	my $restore = PublicInbox::OnDestroy->new(\&chdir, $dh);
-	chdir $dir;
-
 	# xap_modversion may be set by needs_rebuild
 	$xap_modversion //= xap_cfg('--modversion');
 	my $fl = xap_cfg(qw(--libs --cflags));
@@ -83,15 +78,15 @@ sub build () {
 	$^O eq 'netbsd' and $fl =~ s/(\A|[ \t])\-L([^ \t]+)([ \t]|\z)/
 				"$1-L$2 -Wl,-rpath=$2$3"/egsx;
 	my @xflags = split(' ', "$fl $xflags"); # ' ' awk-mode eats leading WS
-	my @cflags = grep(!/\A-(?:Wl|l|L)/, @xflags);
-	run_die([$cxx, '-c', "$prog.cpp", '-I', $srcpfx, @cflags]);
-	run_die([$cxx, '-o', "$prog.tmp", "$prog.o", @xflags]);
-	unlink "$prog.cpp", "$prog.o";
-	write_file '>', 'XFLAGS.tmp', $xflags, "\n";
-	write_file '>', 'xap_modversion.tmp', $xap_modversion, "\n";
+	my @cflags = ('-I', $srcpfx, grep(!/\A-(?:Wl|l|L)/, @xflags));
+	run_die([$cxx, '-o', "$dir/$prog.o", '-c', "$dir/$prog.cpp", @cflags]);
+	run_die([$cxx, '-o', "$dir/$prog.tmp", "$dir/$prog.o", @xflags]);
+	unlink "$dir/$prog.cpp", "$dir/$prog.o";
+	write_file '>', "$dir/XFLAGS.tmp", $xflags, "\n";
+	write_file '>', "$dir/xap_modversion.tmp", $xap_modversion, "\n";
 	undef $xap_modversion; # do we ever build() twice?
 	# not quite atomic, but close enough :P
-	rename("$_.tmp", $_) for ($prog, qw(XFLAGS xap_modversion));
+	rename("$dir/$_.tmp", "$dir/$_") for ($prog, qw(XFLAGS xap_modversion));
 }
 
 sub check_build () {

  parent reply	other threads:[~2023-12-07 11:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 11:42 [PATCH 1/5] *search: simplify handling of Xapian term iterators Eric Wong
2023-12-07 11:42 ` [PATCH 2/5] *search: favor wantarray form of xap_terms Eric Wong
2023-12-07 11:42 ` Eric Wong [this message]
2023-12-07 11:42 ` [PATCH 4/5] makefile: add `check-build' target Eric Wong
2023-12-07 11:42 ` [PATCH 5/5] xap_helper: support term length limit 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=20231207114246.3614375-3-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).