From 5fbdfa0891c470df553d7787330739d76213c971 Mon Sep 17 00:00:00 2001 From: Nick Logan Date: Mon, 29 Apr 2024 17:48:51 -0500 Subject: [PATCH] Stage distribution in a separate process --- lib/Zef/Client.rakumod | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/Zef/Client.rakumod b/lib/Zef/Client.rakumod index fe33e16a..67736800 100644 --- a/lib/Zef/Client.rakumod +++ b/lib/Zef/Client.rakumod @@ -1087,13 +1087,31 @@ class Zef::Client { }); my Str @includes = $staging-repo.path-spec; $_.dist.metainfo = @includes; - $staging-repo.install($_.dist, :precompile($!precompile-install)); - self.logger.emit({ - level => INFO, - stage => STAGING, - phase => AFTER, - message => "Staging [OK] for {$_.dist.identity}", - }); + + # Spawn a new process to run CompUnit::Repository::Staging.install(...) to ensure we have a clean slate. + # We turn the Zef::Distribution::Local into a Distribution::Hash so the new process doesn't need to have + # a repo path pointing to Zef::Distribution::Local. + my $bare-dist = Distribution::Hash.new($_.dist.meta, :prefix($_.dist.path.IO)); + my $staged := try so Zef::zrun(:!out, :!err, :cwd($_.dist.path), $*EXECUTABLE, '-e', "{$staging-repo.raku}.install({$bare-dist.raku}, :precompile({$!precompile-install}))"); + + if $staged { + self.logger.emit({ + level => INFO, + stage => STAGING, + phase => AFTER, + message => "Staging [OK] for {$_.dist.identity}", + }); + } + else { + self.logger.emit({ + level => ERROR, + stage => STAGING, + phase => AFTER, + candi => $_, + message => "Staging [FAIL]: {$_.dist.?identity // $_.as} from {$_.uri}", + }); + die("Aborting due to staging failure: {$_.dist.?identity // $_.uri}"); + } $_; });