]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xap_helper: PERL_INLINE_DIRECTORY fallback for JAOT build
authorEric Wong <e@80x24.org>
Wed, 24 Apr 2024 09:39:36 +0000 (09:39 +0000)
committerEric Wong <e@80x24.org>
Wed, 24 Apr 2024 21:34:48 +0000 (21:34 +0000)
systemd setups may use role accounts (e.g. `news') with
XDG_CACHE_HOME unset and a non-existent HOME directory
which the user has no permission to create.

In those cases, fallback to using PERL_INLINE_DIRECTORY if
available for building the just-ahead-of-time C++ binary.

lib/PublicInbox/XapHelperCxx.pm

index eafe61a85cf9da7d88b38be4c65d3e72538f3895..74852ad19ac5b4ad86afe4fd193c9cc7d5c3ece7 100644 (file)
@@ -16,8 +16,15 @@ use autodie;
 my $cxx = which($ENV{CXX} // 'c++') // which('clang') // die 'no C++ compiler';
 my $dir = substr("$cxx-$Config{archname}", 1); # drop leading '/'
 $dir =~ tr!/!-!;
-my $idir = ($ENV{XDG_CACHE_HOME} //
-       (($ENV{HOME} // die('HOME unset')).'/.cache')).'/public-inbox/jaot';
+my $idir;
+if ((defined($ENV{XDG_CACHE_HOME}) && -d $ENV{XDG_CACHE_HOME}) ||
+                       (defined($ENV{HOME}) && -d $ENV{HOME})) {
+       $idir = ($ENV{XDG_CACHE_HOME} //
+                       (($ENV{HOME} // die('HOME unset')).'/.cache')
+               ).'/public-inbox/jaot';
+}
+$idir //= $ENV{PERL_INLINE_DIRECTORY} //
+       die 'HOME and PERL_INLINE_DIRECTORY unset';
 substr($dir, 0, 0) = "$idir/";
 my $bin = "$dir/xap_helper";
 my ($srcpfx) = (__FILE__ =~ m!\A(.+/)[^/]+\z!);
@@ -58,7 +65,11 @@ sub needs_rebuild () {
 sub build () {
        if (!-d $dir) {
                require File::Path;
-               File::Path::make_path($dir);
+               eval { File::Path::make_path($dir) };
+               if (!-d $dir && defined($ENV{PERL_INLINE_DIRECTORY})) {
+                       $dir = $ENV{PERL_INLINE_DIRECTORY};
+                       File::Path::make_path($dir);
+               }
        }
        require PublicInbox::CodeSearch;
        require PublicInbox::Lock;