diff --git a/lib/Zef/Client.rakumod b/lib/Zef/Client.rakumod index fe33e16a..98bfca2b 100644 --- a/lib/Zef/Client.rakumod +++ b/lib/Zef/Client.rakumod @@ -584,7 +584,7 @@ class Zef::Client { die "failed to create directory: {$tmp.absolute}" unless ($tmp.IO.e || mkdir($tmp)); - my $meta6-prefix = '' R// $!extractor.ls-files($candi).sort.first({ .IO.basename eq 'META6.json' }); + my $meta6-prefix = '' R// $!extractor.ls-files($candi, :$!logger).sort.first({ .IO.basename eq 'META6.json' }); self.logger.emit({ level => WARN, diff --git a/lib/Zef/Extract.rakumod b/lib/Zef/Extract.rakumod index a092122c..587f01f2 100644 --- a/lib/Zef/Extract.rakumod +++ b/lib/Zef/Extract.rakumod @@ -70,10 +70,12 @@ class Zef::Extract does Extractor does Pluggable { =head2 method ls-files - method ls-files(IO() $archive-file --> Array[Str]) + method ls-files(IO() $archive-file, Supplier :$logger --> Array[Str]) On success it returns an C of relative paths that are available to be extracted from C<$archive-file>. + An optional C<:$logger> can be supplied to receive events about what is occurring. + =end pod @@ -159,12 +161,22 @@ class Zef::Extract does Extractor does Pluggable { #| each string is a relative path representing a file that can be extracted from the given $candi.uri #| Note this differs from other 'Extract' adapters .extract() which take a $uri as the first #| parameter, not a $candi - method ls-files($candi --> Array[Str]) { + method ls-files($candi, Supplier :$logger --> Array[Str]) { + my $stdout = Supplier.new; + my $stderr = Supplier.new; + if ?$logger { + $stdout.Supply.act: -> $out { $logger.emit({ level => VERBOSE, stage => EXTRACT, phase => LIVE, candi => $candi, message => $out }) } + $stderr.Supply.act: -> $err { $logger.emit({ level => ERROR, stage => EXTRACT, phase => LIVE, candi => $candi, message => $err }) } + } + my $path := $candi.uri; my $extractors := self!extractors($path); - my $name-paths := $extractors.map(*.ls-files($path)).first(*.defined).map(*.IO); + my $name-paths := $extractors.map(*.ls-files($path, :$stdout, :$stderr)).first(*.defined).map(*.IO); my @files = $name-paths.map({ .is-absolute ?? $path.IO.child(.relative($path)).cleanup.relative($path) !! $_ }); + $stdout.done(); + $stderr.done(); + my Str @results = @files.map(*.Str); return @results; } diff --git a/lib/Zef/Service/Shell/DistributionBuilder.rakumod b/lib/Zef/Service/Shell/DistributionBuilder.rakumod index d55fa961..5b758110 100644 --- a/lib/Zef/Service/Shell/DistributionBuilder.rakumod +++ b/lib/Zef/Service/Shell/DistributionBuilder.rakumod @@ -106,12 +106,11 @@ class Zef::Service::Shell::DistributionBuilder does Builder { my @exec = |($*EXECUTABLE.absolute, |@includes.grep(*.defined).map({ "-I{$_}" }), '-e', "$cmd"); - $stdout.emit("Command: {@exec.join(' ')}"); - my $ENV := %*ENV; my $passed; react { my $proc = Zef::zrun-async(@exec, :w); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout.lines { $stdout.emit($_) } whenever $proc.stderr.lines { $stderr.emit($_) } whenever $proc.start(:$ENV, :cwd($dist.path)) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/LegacyBuild.rakumod b/lib/Zef/Service/Shell/LegacyBuild.rakumod index cfac3df9..8a6d535b 100644 --- a/lib/Zef/Service/Shell/LegacyBuild.rakumod +++ b/lib/Zef/Service/Shell/LegacyBuild.rakumod @@ -88,12 +88,11 @@ class Zef::Service::Shell::LegacyBuild does Builder { my $cmd = "require '$build-file'; ::('Build').new.build('$dist.path.IO.absolute()') ?? exit(0) !! exit(1);"; my @exec = |($*EXECUTABLE.absolute, |@includes.grep(*.defined).map({ "-I{$_}" }), '-e', "$cmd"); - $stdout.emit("Command: {@exec.join(' ')}"); - my $ENV := %*ENV; my $passed; react { my $proc = Zef::zrun-async(@exec); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout.lines { $stdout.emit($_) } whenever $proc.stderr.lines { $stderr.emit($_) } whenever $proc.start(:$ENV, :cwd($dist.path)) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/Test.rakumod b/lib/Zef/Service/Shell/Test.rakumod index 3a13248b..168d5da0 100644 --- a/lib/Zef/Service/Shell/Test.rakumod +++ b/lib/Zef/Service/Shell/Test.rakumod @@ -92,6 +92,7 @@ class Zef::Service::Shell::Test does Tester { my $passed; react { my $proc = Zef::zrun-async($*EXECUTABLE.absolute, @includes.map({ slip '-I', $_ }), $rel-test-file); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout.lines { $stdout.emit($_) } whenever $proc.stderr.lines { $stderr.emit($_) } whenever $proc.start(:cwd($path)) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/curl.rakumod b/lib/Zef/Service/Shell/curl.rakumod index 674490b2..774f7347 100644 --- a/lib/Zef/Service/Shell/curl.rakumod +++ b/lib/Zef/Service/Shell/curl.rakumod @@ -106,6 +106,7 @@ class Zef::Service::Shell::curl does Fetcher does Probeable { my $ENV := %*ENV; my $cmd := self!command(); my $proc = Zef::zrun-async($cmd, '--silent', '-L', '-z', $save-as.absolute, '-o', $save-as.absolute, $uri); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/git.rakumod b/lib/Zef/Service/Shell/git.rakumod index b6917f55..f184e56e 100644 --- a/lib/Zef/Service/Shell/git.rakumod +++ b/lib/Zef/Service/Shell/git.rakumod @@ -87,9 +87,10 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { =head2 method ls-files - method ls-files(IO() $repo-path --> Array[Str]) + method ls-files(IO() $repo-path, Supplier :$stdout, Supplier :$stderr --> Array[Str]) On success it returns an C of relative paths that are available to be extracted from C<$repo-path>. + A C can be supplied as C<:$stdout> and C<:$stderr> to receive any output. =end pod @@ -128,7 +129,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { #| Fetch the given url. #| First attempts to clone the repository, but if it already exists (or fails) it attempts to pull down new changes method fetch(Str() $uri, IO() $save-as, Supplier :$stdout, Supplier :$stderr --> IO::Path) { - return self!clone(self!repo-url($uri), $save-as) || self!pull($save-as); + return self!clone(self!repo-url($uri), $save-as, :$stdout, :$stderr) || self!pull($save-as, :$stdout, :$stderr); } #| Extracts the given path. @@ -137,7 +138,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { die "target repo directory {$repo-path.absolute} does not contain a .git/ folder" unless $repo-path.child('.git').d; - my $sha1 = self!rev-parse(self!fetch($repo-path)).head; + my $sha1 = self!rev-parse(self!fetch($repo-path, :$stdout, :$stderr), :$stdout, :$stderr).head; die "target repo directory {$repo-path.absolute} failed to locate checkout revision" unless $sha1; @@ -145,11 +146,11 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { die "target repo directory {$extract-to.absolute} does not exist and could not be created" unless ($checkout-to.e && $checkout-to.d) || mkdir($checkout-to); - return self!checkout($repo-path, $checkout-to, $sha1); + return self!checkout($repo-path, $checkout-to, $sha1, :$stdout, :$stderr); } #| Returns an array of strings, where each string is a relative path representing a file that can be extracted from the given $repo-path - method ls-files(IO() $repo-path --> Array[Str]) { + method ls-files(IO() $repo-path, Supplier :$stdout, Supplier :$stderr --> Array[Str]) { die "target repo directory {$repo-path.absolute} does not contain a .git/ folder" unless $repo-path.child('.git').d; @@ -159,6 +160,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { my $cwd := $repo-path.absolute; my $ENV := %*ENV; my $proc = Zef::zrun-async('git', 'ls-tree', '-r', '--name-only', self!checkout-name($repo-path)); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { $output.append($_) } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -171,7 +173,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { } #| On success returns an IO::Path to where a `git clone ...` has put files - method !clone($url, IO() $save-as --> IO::Path) { + method !clone($url, IO() $save-as, Supplier :$stdout, Supplier :$stderr --> IO::Path) { die "target download directory {$save-as.absolute} does not exist and could not be created" unless $save-as.d || mkdir($save-as); @@ -180,6 +182,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { my $cwd := $save-as.parent; my $ENV := %*ENV; my $proc = Zef::zrun-async('git', 'clone', $url, $save-as.basename, '--quiet'); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -189,7 +192,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { } #| Does a `git pull` on an existing local git repo - method !pull(IO() $repo-path --> IO::Path) { + method !pull(IO() $repo-path, Supplier :$stdout, Supplier :$stderr --> IO::Path) { die "target download directory {$repo-path.absolute} does not contain a .git/ folder" unless $repo-path.child('.git').d; @@ -198,6 +201,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { my $cwd := $repo-path.absolute; my $ENV := %*ENV; my $proc = Zef::zrun-async('git', 'pull', '--quiet'); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -207,7 +211,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { } #| Does a `git fetch` on an existing local git repo. Not really related to self.fetch(...) - method !fetch(IO() $repo-path --> IO::Path) { + method !fetch(IO() $repo-path, Supplier :$stdout, Supplier :$stderr --> IO::Path) { die "target download directory {$repo-path.absolute} does not contain a .git/ folder" unless $repo-path.child('.git').d; @@ -216,6 +220,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { my $cwd := $repo-path.absolute; my $ENV := %*ENV; my $proc = Zef::zrun-async('git', 'fetch', '--quiet'); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -225,12 +230,13 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { } #| Does a `git checkout ...`, allowing git source urls to have e.g. trailing @tag - method !checkout(IO() $repo-path, IO() $extract-to, $target --> IO::Path) { + method !checkout(IO() $repo-path, IO() $extract-to, $target, Supplier :$stdout, Supplier :$stderr --> IO::Path) { my $passed; react { my $cwd := $repo-path.absolute; my $ENV := %*ENV; my $proc = Zef::zrun-async('git', '--work-tree', $extract-to, 'checkout', $target, '.'); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -240,7 +246,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { } #| Does a `git rev-parse ...` (used to get a sha1 for saving a copy of a specific checkout) - method !rev-parse(IO() $save-as --> Array[Str]) { + method !rev-parse(IO() $save-as, Supplier :$stdout, Supplier :$stderr --> Array[Str]) { die "target repo directory {$save-as.absolute} does not contain a .git/ folder" unless $save-as.child('.git').d; @@ -250,6 +256,7 @@ class Zef::Service::Shell::git does Fetcher does Extractor does Probeable { my $cwd := $save-as.absolute; my $ENV := %*ENV; my $proc = Zef::zrun-async('git', 'rev-parse', self!checkout-name($save-as)); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { $output.append($_) } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/tar.rakumod b/lib/Zef/Service/Shell/tar.rakumod index cc1ec4f5..ba87a8c7 100644 --- a/lib/Zef/Service/Shell/tar.rakumod +++ b/lib/Zef/Service/Shell/tar.rakumod @@ -68,9 +68,10 @@ class Zef::Service::Shell::tar does Extractor { =head2 method ls-files - method ls-files(IO() $archive-file --> Array[Str]) + method ls-files(IO() $archive-file, Supplier :$stdout, Supplier :$stderr --> Array[Str]) On success it returns an C of relative paths that are available to be extracted from C<$archive-file>. + A C can be supplied as C<:$stdout> and C<:$stderr> to receive any output. =end pod @@ -121,6 +122,7 @@ class Zef::Service::Shell::tar does Extractor { my $cwd := $archive-file.parent; my $ENV := %*ENV; my $proc = Zef::zrun-async('tar', '-zxvf', $archive-file.basename, '-C', $extract-to.relative($cwd)); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -130,7 +132,7 @@ class Zef::Service::Shell::tar does Extractor { } #| Returns an array of strings, where each string is a relative path representing a file that can be extracted from the given $archive-file - method ls-files(IO() $archive-file) { + method ls-files(IO() $archive-file, Supplier :$stdout, Supplier :$stderr) { die "archive file does not exist: {$archive-file.absolute}" unless $archive-file.e && $archive-file.f; @@ -140,6 +142,7 @@ class Zef::Service::Shell::tar does Extractor { my $cwd := $archive-file.parent; my $ENV := %*ENV; my $proc = Zef::zrun-async('tar', '-zt', '-f', $archive-file.basename); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { $output.append($_) } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/unzip.rakumod b/lib/Zef/Service/Shell/unzip.rakumod index b70f65cc..04d7cffb 100644 --- a/lib/Zef/Service/Shell/unzip.rakumod +++ b/lib/Zef/Service/Shell/unzip.rakumod @@ -63,9 +63,10 @@ class Zef::Service::Shell::unzip does Extractor { =head2 method ls-files - method ls-files(IO() $archive-file --> Array[Str]) + method ls-files(IO() $archive-file, Supplier :$stdout, Supplier :$stderr --> Array[Str]) On success it returns an C of relative paths that are available to be extracted from C<$archive-file>. + A C can be supplied as C<:$stdout> and C<:$stderr> to receive any output. =end pod @@ -98,6 +99,7 @@ class Zef::Service::Shell::unzip does Extractor { my $cwd := $archive-file.parent; my $ENV := %*ENV; my $proc = Zef::zrun-async('unzip', '-o', '-qq', $archive-file.basename, '-d', $extract-to.absolute); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } @@ -107,7 +109,7 @@ class Zef::Service::Shell::unzip does Extractor { } #| Returns an array of strings, where each string is a relative path representing a file that can be extracted from the given $archive-file - method ls-files(IO() $archive-file) { + method ls-files(IO() $archive-file, Supplier :$stdout, Supplier :$stderr) { die "archive file does not exist: {$archive-file.absolute}" unless $archive-file.e && $archive-file.f; @@ -117,6 +119,7 @@ class Zef::Service::Shell::unzip does Extractor { my $cwd := $archive-file.parent; my $ENV := %*ENV; my $proc = Zef::zrun-async('unzip', '-Z', '-1', $archive-file.basename); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { $output.append($_) } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so } diff --git a/lib/Zef/Service/Shell/wget.rakumod b/lib/Zef/Service/Shell/wget.rakumod index dab119c6..b453811b 100644 --- a/lib/Zef/Service/Shell/wget.rakumod +++ b/lib/Zef/Service/Shell/wget.rakumod @@ -106,6 +106,7 @@ class Zef::Service::Shell::wget does Fetcher does Probeable { my $ENV := %*ENV; my $cmd := self!command(); my $proc = Zef::zrun-async($cmd, '-P', $cwd, '--quiet', $uri, '-O', $save-as.absolute); + $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } whenever $proc.start(:$ENV, :$cwd) { $passed = $_.so }