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 use OpenBSD::Pledge;
10 use OpenBSD::Unveil;
12 my $jobs = $ENV{'MAKE_JOBS'} // 1;
14 my $poll = IO::Poll->new();
15 for (1..$jobs) {
16 say STDERR "pe: spawning job #$_";
17 open(my $kid, '|-', './mexp') or die "can't exec ./mexp: $!";
18 $poll->mask($kid => POLLOUT);
19 }
21 sub process {
22 die "poll: $!" if $poll->poll() == -1;
23 my @handles = $poll->handles(POLLOUT) or die "no procs ready?";
24 my $handle = $handles[int(rand(@handles))];
25 say $handle $_ foreach @_;
26 }
28 unveil("./mexp", "rx") or die "unveil mexp: $!";
29 pledge("stdio proc exec") or die "pledge: $!";
31 my @thread;
32 while (<>) {
33 print; # continue the pipeline
34 chomp;
36 m/^([^ ]+) <([^>]+)> (.+)(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) <([^>]+)> (.*)/;
37 die "can't parse: $_" unless defined $1;
39 my $level = length($3) - 1;
40 $level = 10 if $3 =~ m/\.\.\d{2}\.\./;
42 if ($level == 0 && @thread) {
43 process @thread;
44 @thread = ();
45 }
47 push @thread, $_;
48 }
50 process @thread if @thread;