40 lines
1.2 KiB
Raku
40 lines
1.2 KiB
Raku
#| Utilities for interacting with idris and associated tooling
|
|
unit module IUtils;
|
|
|
|
need IUtils::IDEMode;
|
|
|
|
use paths;
|
|
|
|
#| Structure representing the root of what idris considers a package directory,
|
|
#| with the associated ipkg and source files. These can and will overlap within
|
|
#| the same directory.
|
|
class PackageInfo {
|
|
has IO::Path:D $.ipkg is required;
|
|
has IO::Path:D $.root is required;
|
|
has IO::Path:D @.sources is required;
|
|
}
|
|
|
|
#| Scan a particular ipkg for its associated sources
|
|
sub scan-ipkg(IO::Path:D $ipkg --> PackageInfo:D) {
|
|
my $contents = $ipkg.slurp;
|
|
my $src-dir =
|
|
($contents ~~
|
|
/ 'sourcedir' \h* '=' \h*
|
|
'"' $<value>=[<-["]>*] '"' /)<value>
|
|
// "src";
|
|
|
|
my IO::Path:D @sources =
|
|
paths($ipkg.parent.add($src-dir), :file(*.ends-with(".idr"))).map(*.IO);
|
|
PackageInfo.new(ipkg => $ipkg, root => $ipkg.parent, sources => @sources)
|
|
}
|
|
|
|
# TODO: Add some parsing of pack.toml to locate test packages and associate them
|
|
# with their source ipkg
|
|
|
|
#| Scan $*CWD to locate ipkgs and their associated sources
|
|
sub scan-packages(--> Array[PackageInfo:D]) is export {
|
|
my PackageInfo:D @ipkgs =
|
|
paths(:file(*.ends-with(".ipkg"))).map(*.IO.&scan-ipkg);
|
|
return @ipkgs;
|
|
}
|