Permalink
Browse files

πŸ’₯ 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.
  • Loading branch information...
AlexDaniel committed Sep 15, 2018
1 parent 1c67506 commit 232fe26a27f9da6290363c1d958531f319c562c7
@@ -17,11 +17,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Whateverable;
use Misc;
use IRC::Client;
use Whateverable::Bits;
use Whateverable::Builds;
use Whateverable::Config;
use Whateverable::Output;
use Whateverable::Processing;
use Whateverable::Running;
use File::Directory::Tree;
use IRC::Client;
use SVG::Plot;
use SVG;
use Stats;
@@ -76,8 +80,8 @@ multi method irc-to-me($msg where /^ \s* $<config>=([:i compare \s]? <.&commit-l
method process($msg, $config, $code) {
my $start-time = now;
my $old-dir = $*CWD;
my @commits = self.get-commits: $config;
my $file = self.process-code: $code, $msg;
my @commits = get-commits $config;
my $file = process-code $code, $msg;
LEAVE .unlink with $file;
my %graph;
@@ -89,12 +93,12 @@ method process($msg, $config, $code) {
grumble β€œΒ«hit the total time limit of {TOTAL-TIME} seconds»”
}
# convert to real ids so we can look up the builds
my $full-commit = to-full-commit $commit;
my $short-commit = self.get-short-commit: $commit;
my $full-commit = to-full-commit $commit;
my $short-commit = get-short-commit $commit;
if not defined $full-commit {
my @options = <HEAD v6.c releases all>;
%times{$short-commit}<err> = β€˜Cannot find this revision’
~ β€œ (did you mean β€œ{self.get-short-commit: self.get-similar: $commit, @options}”?)”
~ β€œ (did you mean β€œ{get-short-commit get-similar $commit, @options}”?)”
# TODO why $commit is a match here when using compare?
} elsif not build-exists $full-commit {
%times{$short-commit}<err> = β€˜No build for this commit’
@@ -126,12 +130,12 @@ Z: loop (my $x = 0; $x < @commits - 1; $x++) {
next unless %times{@commits[$x]}:exists and %times{@commits[$x + 1]}:exists; # the commits have to have been run at all
next if %times{@commits[$x]}<err>:exists or %times{@commits[$x + 1]}<err>:exists; # and without error
if abs(%times{@commits[$x]}<min> - %times{@commits[$x + 1]}<min>) β‰₯ %times{@commits[$x]}<min> Γ— 0.1 {
my $result = get-output :cwd($RAKUDO), β€˜git’, β€˜rev-list’,
my $result = get-output :cwd($CONFIG<rakudo>), β€˜git’, β€˜rev-list’,
β€˜--bisect’, β€˜--no-merges’,
@commits[$x] ~ β€˜^..’ ~ @commits[$x + 1];
my $new-commit = $result<output>;
if $result<exit-code> == 0 and defined $new-commit and $new-commit ne β€˜β€™ {
my $short-commit = self.get-short-commit: $new-commit;
my $short-commit = get-short-commit $new-commit;
if not build-exists $new-commit {
%times{$short-commit}<err> = β€˜No build for this commit’
} 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++) {
}
}
@commits .= map: { self.get-short-commit: $_ };
@commits .= map: { get-short-commit $_ };
if @commits β‰₯ ITERATIONS {
my $pfilename = β€˜plot.svg’;
@@ -18,7 +18,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Whateverable;
use Misc;
use Whateverable::Bits;
use Whateverable::Builds;
use Whateverable::Config;
use Whateverable::Output;
use Whateverable::Processing;
use Whateverable::Running;
use File::Directory::Tree;
use File::Temp;
@@ -27,10 +32,6 @@ use Terminal::ANSIColor;
unit class Bisectable does Whateverable;
constant COMMIT-LINK = β€˜https://github.com/rakudo/rakudo/commit’;
constant BUILD-LOCK = β€˜./lock’.IO.absolute;
constant TRIM-CHARS = 2000;
enum RevisionType <Old New Skip>;
method help($msg) {
@@ -70,7 +71,7 @@ method test-commit($code-file, :$old-exit-code, :$old-exit-signal, :$old-output,
}
take β€˜Β»Β»Β»Β»Β» Script output:’;
my $short-output = shorten $result<output>, TRIM-CHARS;
my $short-output = shorten $result<output>, $CONFIG<bisectable><trim-chars>;
take $short-output;
take β€œΒ»Β»Β»Β»Β» (output was trimmed because it is too large)” if $short-output ne $result<output>;
@@ -164,20 +165,20 @@ method process($msg, $code, $old, $new) {
my $full-old = to-full-commit $old;
without $full-old {
grumble β€œCannot find revision β€œ$old””
~ β€œ (did you mean β€œ{self.get-short-commit: self.get-similar: $old, @options}”?)”
~ β€œ (did you mean β€œ{get-short-commit get-similar $old, @options}”?)”
}
grumble β€œNo build for revision β€œ$old”” unless build-exists $full-old;
my $short-old = self.get-short-commit: $old eq $full-old | β€˜HEAD’ ?? $full-old !! $old;
my $short-old = get-short-commit $old eq $full-old | β€˜HEAD’ ?? $full-old !! $old;
my $full-new = to-full-commit $new;
without $full-new {
grumble β€œCannot find revision β€œ$new””
~ β€œ (did you mean β€œ{self.get-short-commit: self.get-similar: $new, @options}”?)”
~ β€œ (did you mean β€œ{get-short-commit get-similar $new, @options}”?)”
}
grumble β€œNo build for revision β€œ$new”” unless build-exists $full-new;
my $short-new = self.get-short-commit: $new eq β€˜HEAD’ ?? $full-new !! $new;
my $short-new = get-short-commit $new eq β€˜HEAD’ ?? $full-new !! $new;
my $file = self.process-code: $code, $msg;
my $file = process-code $code, $msg;
LEAVE .unlink with $file;
my $old-result = run-snippet $full-old, $file;
@@ -209,7 +210,7 @@ method process($msg, $code, $old, $new) {
my $dir = tempdir :!unlink;
LEAVE { rmtree $_ with $dir }
run :out(Nil), :err(Nil), β€˜git’, β€˜clone’, $RAKUDO, $dir; # TODO check the result
run :out(Nil), :err(Nil), <git clone>, $CONFIG<rakudo>, $dir; # TODO check the result
my $bisect-start = get-output cwd => $dir, β€˜git’, β€˜bisect’, β€˜start’;
my $bisect-old = get-output cwd => $dir, β€˜git’, β€˜bisect’, β€˜old’, $full-old;
@@ -255,7 +256,8 @@ method process($msg, $code, $old, $new) {
grumble ο½’β€˜bisect run’ failure. See the log for more detailsο½£
}
my $link-msg = get-output(:cwd($dir), β€˜git’, β€˜show’, β€˜--quiet’, β€˜--date=short’,
β€œ--pretty=(%cd) {COMMIT-LINK}/%H”, β€˜bisect/new’)<output>;
β€œ--pretty=(%cd) $CONFIG<bisectable><commit-link>/%H”,
β€˜bisect/new’)<output>;
$msg.reply: $link-msg;
if $link-msg.ends-with: β€˜07fecb52eb1fd07397659f19a5cf36dc61f84053’ {
grumble β€˜The result looks a bit unrealistic, doesn't it? Most probably the output is different on every commit (e.g. ο½’bisect: say randο½£)’
@@ -18,7 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Whateverable;
use Misc;
use Whateverable::Bits;
use Whateverable::Builds;
use Whateverable::Config;
use Whateverable::Output;
use Whateverable::Running;
use IRC::Client;
@@ -66,23 +70,23 @@ method did-you-mean($out) {
}
method process($msg, $config, $sources is copy) {
my @commits = self.get-commits: $config, repo => MOARVM;
my @commits = get-commits $config, repo => $CONFIG<moarvm>;
my %files;
my @processed;
for @commits -> $commit {
my %prev = @processed.tail if @processed;
my %cur;
# convert to real ids so we can look up the builds
%cur<full-commit> = to-full-commit $commit, repo => MOARVM;
%cur<full-commit> = to-full-commit $commit, repo => $CONFIG<moarvm>;
if not defined %cur<full-commit> {
%cur<error> = β€œCannot find revision $commit”;
my @options = <HEAD v6.c releases all>;
%cur<error> ~= β€œ (did you mean β€œ{self.get-short-commit: self.get-similar: $commit, @options, repo => MOARVM}”?)”
%cur<error> ~= β€œ (did you mean β€œ{get-short-commit get-similar $commit, @options, repo => $CONFIG<moarvm>}”?)”
} elsif not build-exists %cur<full-commit>, :backend<moarvm> {
%cur<error> = β€˜No build for this commit’
}
%cur<short-commit> = self.get-short-commit: $commit;
%cur<short-commit> ~= β€œ({self.get-short-commit: %cur<full-commit>})” if $commit eq β€˜HEAD’;
%cur<short-commit> = get-short-commit $commit;
%cur<short-commit> ~= β€œ({get-short-commit %cur<full-commit>})” if $commit eq β€˜HEAD’;
if %prev {
my $filename = β€œresult-{(1 + %files).fmt: β€˜%05d’}”;
my $result = β€œComparing %prev<short-commit> β†’ %cur<short-commit>\n”;
@@ -18,7 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Whateverable;
use Misc;
use Whateverable::Bits;
use Whateverable::Builds;
use Whateverable::Processing;
use Whateverable::Running;
use IRC::Client;
@@ -62,13 +65,13 @@ multi method irc-to-me($msg where /^ \s* [ @<envs>=((<[\w-]>+)β€˜=’(\S*)) ]* %
method process-commit($commit, $filename, :%ENV) {
# convert to real ids so we can look up the builds
my $full-commit = to-full-commit $commit;
my $short-commit = self.get-short-commit: $commit;
$short-commit ~= β€œ({self.get-short-commit: $full-commit})” if $commit eq β€˜HEAD’;
my $full-commit = to-full-commit $commit;
my $short-commit = get-short-commit $commit;
$short-commit ~= β€œ({get-short-commit $full-commit})” if $commit eq β€˜HEAD’;
without $full-commit {
return $short-commit R=> β€˜Cannot find this revision (did you mean β€œβ€™ ~
self.get-short-commit(self.get-similar: $commit, <HEAD v6.c releases all>) ~
get-short-commit(get-similar $commit, <HEAD v6.c releases all>) ~
β€˜β€?)’
}
$short-commit R=> subprocess-commit $commit, $filename, $full-commit, :%ENV;
@@ -81,8 +84,8 @@ method process($msg, $config is copy, $code is copy, :%ENV) {
$code = β€œ$config $code”;
$config = β€˜v6.c’
}
my @commits = self.get-commits: $config;
my $file = self.process-code: $code, $msg;
my @commits = get-commits $config;
my $file = process-code $code, $msg;
LEAVE .unlink with $file;
my @outputs; # unlike %shas this is ordered
@@ -17,7 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Whateverable;
use Misc;
use Whateverable::Bits;
use Whateverable::Builds;
use Whateverable::Config;
use Whateverable::Processing;
use Whateverable::Running;
use IRC::Client;
@@ -55,10 +59,10 @@ method process($msg, $config is copy, $grep is copy, $code) {
$config = β€˜HEAD’
}
my @commits = self.get-commits: $config;
my @commits = get-commits $config;
grumble β€˜Coverable only works with one commit’ if @commits > 1;
my $file = self.process-code: $code, $msg;
my $file = process-code $code, $msg;
LEAVE .unlink with $file;
my $result;
@@ -71,7 +75,7 @@ method process($msg, $config is copy, $grep is copy, $code) {
if not defined $full-commit {
$output = β€˜Cannot find this revision’;
my @options = <HEAD>;
$output ~= β€œ (did you mean β€œ{self.get-short-commit: self.get-similar: $commit, @options}”?)”
$output ~= β€œ (did you mean β€œ{get-short-commit get-similar $commit, @options}”?)”
} elsif not build-exists $full-commit {
$output = β€˜No build for this commit’
} else { # actually run the code
@@ -94,8 +98,8 @@ method process($msg, $config is copy, $grep is copy, $code) {
$output ~= β€œ Β«exit signal = {Signal($result<signal>)} ($result<signal>)»” if $result<signal> β‰  0
}
}
my $short-commit = self.get-short-commit: $commit;
$short-commit ~= β€œ({self.get-short-commit: $full-commit})” if $commit eq β€˜HEAD’;
my $short-commit = get-short-commit $commit;
$short-commit ~= β€œ({get-short-commit $full-commit})” if $commit eq β€˜HEAD’;
if now - $start-time > TOTAL-TIME {
grumble β€œΒ«hit the total time limit of {TOTAL-TIME} seconds»”
@@ -121,10 +125,10 @@ method process($msg, $config is copy, $grep is copy, $code) {
$cover-report ~= β€œ| [$fname#$ln]($url/$fname#$ln) |”;
my $sed-range = β€œ{$l.min},{$l.max}p”;
# ⚠ TODO don't do this ↓ for every line, do it for every *file*. It will be much faster.
my $proc = run :out, :cwd($RAKUDO), β€˜git’, β€˜show’, β€œ$full-commit:$fname”;
my $proc = run :out, :cwd($CONFIG<rakudo>), <git show>, β€œ$full-commit:$fname”;
# TODO So we are using RAKUDO ↑, but RAKUDO may not know about some commits *yet*, while
# they may be accessible if you give a hash directly.
my $code = run(:out, :in($proc.out), β€˜sed’, β€˜-n’, $sed-range).out.slurp-rest.trim; # TODO trim? or just chomp?
my $code = run(:out, :in($proc.out), <sed -n>, $sed-range).out.slurp-rest.trim; # TODO trim? or just chomp?
$code .= subst: :g, β€œ\n”, β€˜```<br>```’; # TODO multiline code blocks using github markdown?
$code .= subst: :g, β€˜|’, β€˜\|’; # TODO really?
$cover-report ~= β€œ ```$code``` |\n”; # TODO close properly (see how many ``` are there already)
@@ -18,15 +18,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Whateverable;
use Misc;
use Whateverable::Bits;
use Whateverable::Builds;
use Whateverable::Config;
use Whateverable::Processing;
use Whateverable::Replaceable;
use Whateverable::Running;
use IRC::Client;
use Terminal::ANSIColor;
unit class Evalable does Whateverable does Replaceable;
constant SHORT-MESSAGE-LIMIT = MESSAGE-LIMIT Γ· 2;
unit class Evalable does Whateverable does Whateverable::Replaceable;
method help($msg) {
β€œLike this: {$msg.server.current-nick}: say β€˜hello’; say β€˜world’”
@@ -51,7 +53,7 @@ multi method irc-privmsg-channel($msg) {
method process($msg, $code, :$good-only?) {
my $commit = %*BOT-ENV<commit>;
my $file = self.process-code: $code, $msg;
my $file = process-code $code, $msg;
LEAVE .unlink with $file;
# convert to real id so we can look up the build
@@ -85,15 +87,16 @@ method process($msg, $code, :$good-only?) {
my $reply-start = β€œrakudo-moar $short-commit: OUTPUT: Β«$extra”;
my $reply-end = β€˜Β»β€™;
if MESSAGE-LIMIT β‰₯ ($reply-start, $output, $reply-end).map(*.encode.elems).sum {
if $CONFIG<message-limit> β‰₯ ($reply-start, $output, $reply-end).map(*.encode.elems).sum {
return $reply-start ~ $output ~ $reply-end # no gist
}
$reply-end = β€˜β€¦β€™ ~ $reply-end;
my $extra-size = ($reply-start, $reply-end).map(*.encode.elems).sum;
my $output-size = 0;
my $SHORT-MESSAGE-LIMIT = $CONFIG<message-limit> Γ· 2;
my $output-cut = $output.comb.grep({
$output-size += .encode.elems;
$output-size + $extra-size < SHORT-MESSAGE-LIMIT
$output-size + $extra-size < $SHORT-MESSAGE-LIMIT
})[0..*-2].join;
$msg.reply: $reply-start ~ $output-cut ~ $reply-end;
sleep 0.02;
@@ -17,11 +17,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Misc;
use Whateverable;
use Whateverable::Bits;
use Whateverable::Output;
use Whateverable::Running;
use IRC::Client;
use Config::INI;
use IRC::Client;
unit class Greppable does Whateverable;
@@ -1,6 +1,9 @@
#!/usr/bin/env perl6
use Whateverable;
use Misc;
use Whateverable::Bits;
use Whateverable::Output;
use Whateverable::Processing;
unit class Nativecallable does Whateverable;
@@ -11,7 +14,7 @@ method help($msg) {
sub run-gptrixie($header-file) {
my %ENV = %*ENV.clone;
%ENV<PATH> = join β€˜:’, β€˜/home/bisectable/.rakudobrew/bin’, %ENV<PATH>; # TODO
my %output = get-output :%ENV, β€˜gptrixie’, β€˜--all’, β€˜--silent’, $header-file;
my %output = get-output :%ENV, β€˜gptrixie’, '--silent', β€˜--all’, β€˜--castxml=c99’, $header-file;
if %output<output>.lines > 20 {
return β€˜β€™ but FileStore(%(β€˜GPTrixiefied.pm6’ => "#Generated by App::GPTrixie\n" ~ %output<output>))
}
@@ -21,14 +24,15 @@ sub run-gptrixie($header-file) {
return (@pruned-output.map: {.subst(/\s+/, " ", :g)}).join: β€œ\n”;
}
my $definitive-output //= %output<output>;
β€˜β€™ but FileStore(%(β€˜GPTrixified.pm6’ => "#Generated by App::GPTrixie\n" ~ $definitive-output))
β€˜β€™ but FileStore(%(β€˜result.pm6’ => "#Generated by App::GPTrixie\n" ~ $definitive-output))
}
multi method irc-to-me($msg where /^ \s* $<code>=.+ /) {
my $file = self.process-code: $<code>, $msg;
my $file = process-code $<code>, $msg;
my $code = slurp $file;
$file.unlink;
my $header-file = write-code β€œ\n#include <stddef.h>\n#include <stdbool.h>\n” ~ $code;
my $header-file = '/tmp/gptnc.h';
spurt $header-file, β€œ\n#include <stddef.h>\n#include <stdbool.h>\n” ~ $code;
LEAVE unlink $_ with $header-file;
run-gptrixie($header-file)
}
Oops, something went wrong.

0 comments on commit 232fe26

Please sign in to comment.