Skip to content

Commit 232fe26

Browse files
committed
💥 Split Whateverable.pm6 into separate files
To make some things usable outside of whateverable repo. It made sense to keep everything together when there were just two bots, but now there are 17 and I'd like to reuse some parts for other things without subclassing Whateverable.
1 parent 1c67506 commit 232fe26

32 files changed

+947
-652
lines changed

bin/Benchable.p6

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

1919
use Whateverable;
20-
use Misc;
21-
22-
use IRC::Client;
20+
use Whateverable::Bits;
21+
use Whateverable::Builds;
22+
use Whateverable::Config;
23+
use Whateverable::Output;
24+
use Whateverable::Processing;
25+
use Whateverable::Running;
2326

2427
use File::Directory::Tree;
28+
use IRC::Client;
2529
use SVG::Plot;
2630
use SVG;
2731
use Stats;
@@ -76,8 +80,8 @@ multi method irc-to-me($msg where /^ \s* $<config>=([:i compare \s]? <.&commit-l
7680
method process($msg, $config, $code) {
7781
my $start-time = now;
7882
my $old-dir = $*CWD;
79-
my @commits = self.get-commits: $config;
80-
my $file = self.process-code: $code, $msg;
83+
my @commits = get-commits $config;
84+
my $file = process-code $code, $msg;
8185
LEAVE .unlink with $file;
8286

8387
my %graph;
@@ -89,12 +93,12 @@ method process($msg, $config, $code) {
8993
grumble «hit the total time limit of {TOTAL-TIME} seconds»
9094
}
9195
# convert to real ids so we can look up the builds
92-
my $full-commit = to-full-commit $commit;
93-
my $short-commit = self.get-short-commit: $commit;
96+
my $full-commit = to-full-commit $commit;
97+
my $short-commit = get-short-commit $commit;
9498
if not defined $full-commit {
9599
my @options = <HEAD v6.c releases all>;
96100
%times{$short-commit}<err> = Cannot find this revision
97-
~ (did you mean “{self.get-short-commit: self.get-similar: $commit, @options}”?)
101+
~ (did you mean “{get-short-commit get-similar $commit, @options}”?)
98102
# TODO why $commit is a match here when using compare?
99103
} elsif not build-exists $full-commit {
100104
%times{$short-commit}<err> = No build for this commit
@@ -126,12 +130,12 @@ Z: loop (my $x = 0; $x < @commits - 1; $x++) {
126130
next unless %times{@commits[$x]}:exists and %times{@commits[$x + 1]}:exists; # the commits have to have been run at all
127131
next if %times{@commits[$x]}<err>:exists or %times{@commits[$x + 1]}<err>:exists; # and without error
128132
if abs(%times{@commits[$x]}<min> - %times{@commits[$x + 1]}<min>) ≥ %times{@commits[$x]}<min> × 0.1 {
129-
my $result = get-output :cwd($RAKUDO), git, rev-list,
133+
my $result = get-output :cwd($CONFIG<rakudo>), git, rev-list,
130134
--bisect, --no-merges,
131135
@commits[$x] ~ ^.. ~ @commits[$x + 1];
132136
my $new-commit = $result<output>;
133137
if $result<exit-code> == 0 and defined $new-commit and $new-commit ne {
134-
my $short-commit = self.get-short-commit: $new-commit;
138+
my $short-commit = get-short-commit $new-commit;
135139
if not build-exists $new-commit {
136140
%times{$short-commit}<err> = No build for this commit
137141
} elsif %times{$short-commit}:!exists and $short-commit ne @commits[$x] and $short-commit ne @commits[$x + 1] { # actually run the code
@@ -144,7 +148,7 @@ Z: loop (my $x = 0; $x < @commits - 1; $x++) {
144148
}
145149
}
146150

147-
@commits .= map: { self.get-short-commit: $_ };
151+
@commits .= map: { get-short-commit $_ };
148152

149153
if @commits ≥ ITERATIONS {
150154
my $pfilename = plot.svg;

bin/Bisectable.p6

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020
use Whateverable;
21-
use Misc;
21+
use Whateverable::Bits;
22+
use Whateverable::Builds;
23+
use Whateverable::Config;
24+
use Whateverable::Output;
25+
use Whateverable::Processing;
26+
use Whateverable::Running;
2227

2328
use File::Directory::Tree;
2429
use File::Temp;
@@ -27,10 +32,6 @@ use Terminal::ANSIColor;
2732

2833
unit class Bisectable does Whateverable;
2934

30-
constant COMMIT-LINK = https://github.com/rakudo/rakudo/commit;
31-
constant BUILD-LOCK = ./lock.IO.absolute;
32-
constant TRIM-CHARS = 2000;
33-
3435
enum RevisionType <Old New Skip>;
3536

3637
method help($msg) {
@@ -70,7 +71,7 @@ method test-commit($code-file, :$old-exit-code, :$old-exit-signal, :$old-output,
7071
}
7172

7273
take »»»»» Script output:;
73-
my $short-output = shorten $result<output>, TRIM-CHARS;
74+
my $short-output = shorten $result<output>, $CONFIG<bisectable><trim-chars>;
7475
take $short-output;
7576
take »»»»» (output was trimmed because it is too large) if $short-output ne $result<output>;
7677

@@ -164,20 +165,20 @@ method process($msg, $code, $old, $new) {
164165
my $full-old = to-full-commit $old;
165166
without $full-old {
166167
grumble Cannot find revision “$old”
167-
~ (did you mean “{self.get-short-commit: self.get-similar: $old, @options}”?)
168+
~ (did you mean “{get-short-commit get-similar $old, @options}”?)
168169
}
169170
grumble No build for revision “$old” unless build-exists $full-old;
170-
my $short-old = self.get-short-commit: $old eq $full-old | HEAD ?? $full-old !! $old;
171+
my $short-old = get-short-commit $old eq $full-old | HEAD ?? $full-old !! $old;
171172

172173
my $full-new = to-full-commit $new;
173174
without $full-new {
174175
grumble Cannot find revision “$new”
175-
~ (did you mean “{self.get-short-commit: self.get-similar: $new, @options}”?)
176+
~ (did you mean “{get-short-commit get-similar $new, @options}”?)
176177
}
177178
grumble No build for revision “$new” unless build-exists $full-new;
178-
my $short-new = self.get-short-commit: $new eq HEAD ?? $full-new !! $new;
179+
my $short-new = get-short-commit $new eq HEAD ?? $full-new !! $new;
179180

180-
my $file = self.process-code: $code, $msg;
181+
my $file = process-code $code, $msg;
181182
LEAVE .unlink with $file;
182183

183184
my $old-result = run-snippet $full-old, $file;
@@ -209,7 +210,7 @@ method process($msg, $code, $old, $new) {
209210

210211
my $dir = tempdir :!unlink;
211212
LEAVE { rmtree $_ with $dir }
212-
run :out(Nil), :err(Nil), git, clone, $RAKUDO, $dir; # TODO check the result
213+
run :out(Nil), :err(Nil), <git clone>, $CONFIG<rakudo>, $dir; # TODO check the result
213214

214215
my $bisect-start = get-output cwd => $dir, git, bisect, start;
215216
my $bisect-old = get-output cwd => $dir, git, bisect, old, $full-old;
@@ -255,7 +256,8 @@ method process($msg, $code, $old, $new) {
255256
grumble ‘bisect run’ failure. See the log for more details
256257
}
257258
my $link-msg = get-output(:cwd($dir), git, show, --quiet, --date=short,
258-
--pretty=(%cd) {COMMIT-LINK}/%H, bisect/new)<output>;
259+
--pretty=(%cd) $CONFIG<bisectable><commit-link>/%H,
260+
bisect/new)<output>;
259261
$msg.reply: $link-msg;
260262
if $link-msg.ends-with: 07fecb52eb1fd07397659f19a5cf36dc61f84053 {
261263
grumble The result looks a bit unrealistic, doesn't it? Most probably the output is different on every commit (e.g. 「bisect: say rand」)

bin/Bloatable.p6

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020
use Whateverable;
21-
use Misc;
21+
use Whateverable::Bits;
22+
use Whateverable::Builds;
23+
use Whateverable::Config;
24+
use Whateverable::Output;
25+
use Whateverable::Running;
2226

2327
use IRC::Client;
2428

@@ -66,23 +70,23 @@ method did-you-mean($out) {
6670
}
6771

6872
method process($msg, $config, $sources is copy) {
69-
my @commits = self.get-commits: $config, repo => MOARVM;
73+
my @commits = get-commits $config, repo => $CONFIG<moarvm>;
7074
my %files;
7175
my @processed;
7276
for @commits -> $commit {
7377
my %prev = @processed.tail if @processed;
7478
my %cur;
7579
# convert to real ids so we can look up the builds
76-
%cur<full-commit> = to-full-commit $commit, repo => MOARVM;
80+
%cur<full-commit> = to-full-commit $commit, repo => $CONFIG<moarvm>;
7781
if not defined %cur<full-commit> {
7882
%cur<error> = Cannot find revision $commit;
7983
my @options = <HEAD v6.c releases all>;
80-
%cur<error> ~= (did you mean “{self.get-short-commit: self.get-similar: $commit, @options, repo => MOARVM}”?)
84+
%cur<error> ~= (did you mean “{get-short-commit get-similar $commit, @options, repo => $CONFIG<moarvm>}”?)
8185
} elsif not build-exists %cur<full-commit>, :backend<moarvm> {
8286
%cur<error> = No build for this commit
8387
}
84-
%cur<short-commit> = self.get-short-commit: $commit;
85-
%cur<short-commit> ~= ({self.get-short-commit: %cur<full-commit>}) if $commit eq HEAD;
88+
%cur<short-commit> = get-short-commit $commit;
89+
%cur<short-commit> ~= ({get-short-commit %cur<full-commit>}) if $commit eq HEAD;
8690
if %prev {
8791
my $filename = result-{(1 + %files).fmt: %05d};
8892
my $result = Comparing %prev<short-commit> → %cur<short-commit>\n;

bin/Committable.p6

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020
use Whateverable;
21-
use Misc;
21+
use Whateverable::Bits;
22+
use Whateverable::Builds;
23+
use Whateverable::Processing;
24+
use Whateverable::Running;
2225

2326
use IRC::Client;
2427

@@ -62,13 +65,13 @@ multi method irc-to-me($msg where /^ \s* [ @<envs>=((<[\w-]>+)‘=’(\S*)) ]* %
6265

6366
method process-commit($commit, $filename, :%ENV) {
6467
# convert to real ids so we can look up the builds
65-
my $full-commit = to-full-commit $commit;
66-
my $short-commit = self.get-short-commit: $commit;
67-
$short-commit ~= ({self.get-short-commit: $full-commit}) if $commit eq HEAD;
68+
my $full-commit = to-full-commit $commit;
69+
my $short-commit = get-short-commit $commit;
70+
$short-commit ~= ({get-short-commit $full-commit}) if $commit eq HEAD;
6871

6972
without $full-commit {
7073
return $short-commit R=> Cannot find this revision (did you mean “ ~
71-
self.get-short-commit(self.get-similar: $commit, <HEAD v6.c releases all>) ~
74+
get-short-commit(get-similar $commit, <HEAD v6.c releases all>) ~
7275
”?)
7376
}
7477
$short-commit R=> subprocess-commit $commit, $filename, $full-commit, :%ENV;
@@ -81,8 +84,8 @@ method process($msg, $config is copy, $code is copy, :%ENV) {
8184
$code = $config $code;
8285
$config = v6.c
8386
}
84-
my @commits = self.get-commits: $config;
85-
my $file = self.process-code: $code, $msg;
87+
my @commits = get-commits $config;
88+
my $file = process-code $code, $msg;
8689
LEAVE .unlink with $file;
8790

8891
my @outputs; # unlike %shas this is ordered

bin/Coverable.p6

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

1919
use Whateverable;
20-
use Misc;
20+
use Whateverable::Bits;
21+
use Whateverable::Builds;
22+
use Whateverable::Config;
23+
use Whateverable::Processing;
24+
use Whateverable::Running;
2125

2226
use IRC::Client;
2327

@@ -55,10 +59,10 @@ method process($msg, $config is copy, $grep is copy, $code) {
5559
$config = HEAD
5660
}
5761

58-
my @commits = self.get-commits: $config;
62+
my @commits = get-commits $config;
5963
grumble Coverable only works with one commit if @commits > 1;
6064

61-
my $file = self.process-code: $code, $msg;
65+
my $file = process-code $code, $msg;
6266
LEAVE .unlink with $file;
6367

6468
my $result;
@@ -71,7 +75,7 @@ method process($msg, $config is copy, $grep is copy, $code) {
7175
if not defined $full-commit {
7276
$output = Cannot find this revision;
7377
my @options = <HEAD>;
74-
$output ~= (did you mean “{self.get-short-commit: self.get-similar: $commit, @options}”?)
78+
$output ~= (did you mean “{get-short-commit get-similar $commit, @options}”?)
7579
} elsif not build-exists $full-commit {
7680
$output = No build for this commit
7781
} else { # actually run the code
@@ -94,8 +98,8 @@ method process($msg, $config is copy, $grep is copy, $code) {
9498
$output ~= «exit signal = {Signal($result<signal>)} ($result<signal>)» if $result<signal> ≠ 0
9599
}
96100
}
97-
my $short-commit = self.get-short-commit: $commit;
98-
$short-commit ~= ({self.get-short-commit: $full-commit}) if $commit eq HEAD;
101+
my $short-commit = get-short-commit $commit;
102+
$short-commit ~= ({get-short-commit $full-commit}) if $commit eq HEAD;
99103

100104
if now - $start-time > TOTAL-TIME {
101105
grumble «hit the total time limit of {TOTAL-TIME} seconds»
@@ -121,10 +125,10 @@ method process($msg, $config is copy, $grep is copy, $code) {
121125
$cover-report ~= | [$fname#$ln]($url/$fname#$ln) |;
122126
my $sed-range = {$l.min},{$l.max}p;
123127
# ⚠ TODO don't do this ↓ for every line, do it for every *file*. It will be much faster.
124-
my $proc = run :out, :cwd($RAKUDO), git, show, $full-commit:$fname;
128+
my $proc = run :out, :cwd($CONFIG<rakudo>), <git show>, $full-commit:$fname;
125129
# TODO So we are using RAKUDO ↑, but RAKUDO may not know about some commits *yet*, while
126130
# they may be accessible if you give a hash directly.
127-
my $code = run(:out, :in($proc.out), sed, -n, $sed-range).out.slurp-rest.trim; # TODO trim? or just chomp?
131+
my $code = run(:out, :in($proc.out), <sed -n>, $sed-range).out.slurp-rest.trim; # TODO trim? or just chomp?
128132
$code .= subst: :g, \n, ```<br>```; # TODO multiline code blocks using github markdown?
129133
$code .= subst: :g, |, \|; # TODO really?
130134
$cover-report ~= ```$code``` |\n; # TODO close properly (see how many ``` are there already)

bin/Evalable.p6

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020
use Whateverable;
21-
use Misc;
21+
use Whateverable::Bits;
22+
use Whateverable::Builds;
23+
use Whateverable::Config;
24+
use Whateverable::Processing;
2225
use Whateverable::Replaceable;
26+
use Whateverable::Running;
2327

2428
use IRC::Client;
2529
use Terminal::ANSIColor;
2630

27-
unit class Evalable does Whateverable does Replaceable;
28-
29-
constant SHORT-MESSAGE-LIMIT = MESSAGE-LIMIT ÷ 2;
31+
unit class Evalable does Whateverable does Whateverable::Replaceable;
3032

3133
method help($msg) {
3234
Like this: {$msg.server.current-nick}: say ‘hello’; say ‘world’
@@ -51,7 +53,7 @@ multi method irc-privmsg-channel($msg) {
5153

5254
method process($msg, $code, :$good-only?) {
5355
my $commit = %*BOT-ENV<commit>;
54-
my $file = self.process-code: $code, $msg;
56+
my $file = process-code $code, $msg;
5557
LEAVE .unlink with $file;
5658

5759
# convert to real id so we can look up the build
@@ -85,15 +87,16 @@ method process($msg, $code, :$good-only?) {
8587

8688
my $reply-start = rakudo-moar $short-commit: OUTPUT: «$extra;
8789
my $reply-end = »;
88-
if MESSAGE-LIMIT ≥ ($reply-start, $output, $reply-end).map(*.encode.elems).sum {
90+
if $CONFIG<message-limit> ≥ ($reply-start, $output, $reply-end).map(*.encode.elems).sum {
8991
return $reply-start ~ $output ~ $reply-end # no gist
9092
}
9193
$reply-end = ~ $reply-end;
9294
my $extra-size = ($reply-start, $reply-end).map(*.encode.elems).sum;
9395
my $output-size = 0;
96+
my $SHORT-MESSAGE-LIMIT = $CONFIG<message-limit> ÷ 2;
9497
my $output-cut = $output.comb.grep({
9598
$output-size += .encode.elems;
96-
$output-size + $extra-size < SHORT-MESSAGE-LIMIT
99+
$output-size + $extra-size < $SHORT-MESSAGE-LIMIT
97100
})[0..*-2].join;
98101
$msg.reply: $reply-start ~ $output-cut ~ $reply-end;
99102
sleep 0.02;

bin/Greppable.p6

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
# You should have received a copy of the GNU Affero General Public License
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

20-
use Misc;
2120
use Whateverable;
21+
use Whateverable::Bits;
22+
use Whateverable::Output;
23+
use Whateverable::Running;
2224

23-
use IRC::Client;
2425
use Config::INI;
26+
use IRC::Client;
2527

2628
unit class Greppable does Whateverable;
2729

bin/Nativecallable.p6

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env perl6
2+
23
use Whateverable;
3-
use Misc;
4+
use Whateverable::Bits;
5+
use Whateverable::Output;
6+
use Whateverable::Processing;
47

58
unit class Nativecallable does Whateverable;
69

@@ -11,7 +14,7 @@ method help($msg) {
1114
sub run-gptrixie($header-file) {
1215
my %ENV = %*ENV.clone;
1316
%ENV<PATH> = join :, /home/bisectable/.rakudobrew/bin, %ENV<PATH>; # TODO
14-
my %output = get-output :%ENV, gptrixie, --all, --silent, $header-file;
17+
my %output = get-output :%ENV, gptrixie, '--silent', --all, --castxml=c99, $header-file;
1518
if %output<output>.lines > 20 {
1619
return but FileStore(%(GPTrixiefied.pm6 => "#Generated by App::GPTrixie\n" ~ %output<output>))
1720
}
@@ -21,14 +24,15 @@ sub run-gptrixie($header-file) {
2124
return (@pruned-output.map: {.subst(/\s+/, " ", :g)}).join: \n;
2225
}
2326
my $definitive-output //= %output<output>;
24-
but FileStore(%(GPTrixified.pm6 => "#Generated by App::GPTrixie\n" ~ $definitive-output))
27+
but FileStore(%(result.pm6 => "#Generated by App::GPTrixie\n" ~ $definitive-output))
2528
}
2629

2730
multi method irc-to-me($msg where /^ \s* $<code>=.+ /) {
28-
my $file = self.process-code: $<code>, $msg;
31+
my $file = process-code $<code>, $msg;
2932
my $code = slurp $file;
3033
$file.unlink;
31-
my $header-file = write-code \n#include <stddef.h>\n#include <stdbool.h>\n ~ $code;
34+
my $header-file = '/tmp/gptnc.h';
35+
spurt $header-file, \n#include <stddef.h>\n#include <stdbool.h>\n ~ $code;
3236
LEAVE unlink $_ with $header-file;
3337
run-gptrixie($header-file)
3438
}

0 commit comments

Comments
 (0)