Refactor compiler interaction
This commit is contained in:
parent
1bfe73f77a
commit
49c118eef4
|
@ -12,7 +12,8 @@
|
||||||
"provides": {
|
"provides": {
|
||||||
"IUtils": "lib/IUtils.rakumod",
|
"IUtils": "lib/IUtils.rakumod",
|
||||||
"IUtils::IDEMode": "lib/IUtils/IDEMode.rakumod",
|
"IUtils::IDEMode": "lib/IUtils/IDEMode.rakumod",
|
||||||
"IUtils::Regexs": "lib/IUtils/Regexes.rakumod"
|
"IUtils::Regexs": "lib/IUtils/Regexes.rakumod",
|
||||||
|
"IUtils::Compiler": "lib/IUtils/Compiler.rakumod"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"iutils": "bin/iutils"
|
"iutils": "bin/iutils"
|
||||||
|
|
|
@ -37,74 +37,3 @@ sub scan-packages(--> Array[PackageInfo:D]) is export {
|
||||||
paths(:file(*.ends-with(".ipkg"))).map(*.IO.&scan-ipkg);
|
paths(:file(*.ends-with(".ipkg"))).map(*.IO.&scan-ipkg);
|
||||||
return @ipkgs;
|
return @ipkgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Utility functions for pack
|
|
||||||
|
|
||||||
#| Invoke a pack command
|
|
||||||
sub pack-run(*@cmd) is export {
|
|
||||||
my $proc = run "pack", @cmd, :out, :err;
|
|
||||||
my $out = $proc.out.slurp(:close);
|
|
||||||
my $err = $proc.err.slurp(:close);
|
|
||||||
unless $proc {
|
|
||||||
die qq:to/END/;
|
|
||||||
Pack Failure!
|
|
||||||
Captured Output:
|
|
||||||
$out
|
|
||||||
|
|
||||||
Captured StdErr:
|
|
||||||
$err
|
|
||||||
END
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Build a package with pack
|
|
||||||
sub pack-build($pkg) is export {
|
|
||||||
pack-run 'build', $pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Test a package with pack
|
|
||||||
sub pack-test($pkg) is export {
|
|
||||||
pack-run 'build', $pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Clean a package with pack
|
|
||||||
sub pack-clean($pkg) is export {
|
|
||||||
pack-run 'clean', $pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
# Utility functions for idris
|
|
||||||
|
|
||||||
#| An error coming from the idris compiler
|
|
||||||
class IdrisError is Exception {
|
|
||||||
has Str $.out;
|
|
||||||
has Str $.err;
|
|
||||||
has Int $.exit-code;
|
|
||||||
has Str $.command;
|
|
||||||
|
|
||||||
method message {
|
|
||||||
qq:to/END/;
|
|
||||||
Error running idris command: $.command
|
|
||||||
Command exited with $.exit-code
|
|
||||||
END
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Invoke an idris command
|
|
||||||
sub idris-run(*@cmd) is export {
|
|
||||||
my $proc = run "idris2", @cmd, :out, :err;
|
|
||||||
my $out = $proc.out.slurp(:close);
|
|
||||||
my $err = $proc.err.slurp(:close);
|
|
||||||
unless $proc {
|
|
||||||
IdrisError.new(
|
|
||||||
out => $out, err => $err,
|
|
||||||
exit-code => $proc.exitcode, command => @cmd.Str)
|
|
||||||
.throw;
|
|
||||||
}
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#| Exec the expression with the given name in the given file
|
|
||||||
sub idris-exec($expr, $file) is export {
|
|
||||||
idris-run '--find-ipkg', '--exec', $expr, $file
|
|
||||||
}
|
|
||||||
|
|
72
lib/IUtils/Compiler.rakumod
Normal file
72
lib/IUtils/Compiler.rakumod
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#| Utilities for interacting with the idris compiler and package manager
|
||||||
|
unit module IUtils::Compiler;
|
||||||
|
|
||||||
|
# Utility functions for pack
|
||||||
|
|
||||||
|
#| Invoke a pack command
|
||||||
|
sub pack-run(*@cmd) is export {
|
||||||
|
my $proc = run "pack", @cmd, :out, :err;
|
||||||
|
my $out = $proc.out.slurp(:close);
|
||||||
|
my $err = $proc.err.slurp(:close);
|
||||||
|
unless $proc {
|
||||||
|
die qq:to/END/;
|
||||||
|
Pack Failure!
|
||||||
|
Captured Output:
|
||||||
|
$out
|
||||||
|
|
||||||
|
Captured StdErr:
|
||||||
|
$err
|
||||||
|
END
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Build a package with pack
|
||||||
|
sub pack-build($pkg) is export {
|
||||||
|
pack-run 'build', $pkg
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Test a package with pack
|
||||||
|
sub pack-test($pkg) is export {
|
||||||
|
pack-run 'build', $pkg
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Clean a package with pack
|
||||||
|
sub pack-clean($pkg) is export {
|
||||||
|
pack-run 'clean', $pkg
|
||||||
|
}
|
||||||
|
|
||||||
|
# Utility functions for idris
|
||||||
|
|
||||||
|
#| An error coming from the idris compiler
|
||||||
|
class IdrisError is Exception {
|
||||||
|
has Str $.out;
|
||||||
|
has Str $.err;
|
||||||
|
has Int $.exit-code;
|
||||||
|
has Str $.command;
|
||||||
|
|
||||||
|
method message {
|
||||||
|
qq:to/END/;
|
||||||
|
Error running idris command: $.command
|
||||||
|
Command exited with $.exit-code
|
||||||
|
END
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Invoke an idris command
|
||||||
|
sub idris-run(*@cmd) is export {
|
||||||
|
my $proc = run "idris2", @cmd, :out, :err;
|
||||||
|
my $out = $proc.out.slurp(:close);
|
||||||
|
my $err = $proc.err.slurp(:close);
|
||||||
|
unless $proc {
|
||||||
|
IdrisError.new(
|
||||||
|
out => $out, err => $err,
|
||||||
|
exit-code => $proc.exitcode, command => @cmd.Str)
|
||||||
|
.throw;
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
#| Exec the expression with the given name in the given file
|
||||||
|
sub idris-exec($expr, $file) is export {
|
||||||
|
idris-run '--find-ipkg', '--exec', $expr, $file
|
||||||
|
}
|
Loading…
Reference in a new issue