Blob


1 #!/usr/bin/env perl
3 use open ":std", ":encoding(UTF-8)";
4 use strict;
5 use warnings;
6 use v5.32;
7 use IO::Poll qw(POLLOUT);
9 my $jobs = $ENV{'MAKE_JOBS'} // 1;
11 my $poll = IO::Poll->new();
12 for (1..$jobs) {
13 say STDERR "pe: spawning job #$_";
14 open(my $kid, '|-', './mexp') or die "can't exec ./mexp: $!";
15 $poll->mask($kid => POLLOUT);
16 }
18 sub process {
19 die "poll: $!" if $poll->poll() == -1;
20 my @handles = $poll->handles(POLLOUT) or die "no procs ready?";
21 my $handle = $handles[int(rand(@handles))];
22 say $handle $_ foreach @_;
23 }
25 my @thread;
26 while (<>) {
27 print; # continue the pipeline
28 chomp;
30 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
31 die "can't parse: $_" unless defined $1;
33 my $level = length($3) - 1;
34 $level = 10 if $3 =~ m/\.\.\d{2}\.\./;
36 if ($level == 0 && @thread) {
37 process @thread;
38 @thread = ();
39 }
41 push @thread, $_;
42 }
44 process @thread if @thread;