From 0a0596b14300f6726b6cdb51e350469be275536b Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 31 Dec 2024 15:49:13 +0000 Subject: [PATCH 1/3] Project enumeration --- bin/iutils | 12 +++------ lib/IUtils.rakumod | 61 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/bin/iutils b/bin/iutils index 85452e8..b0595e5 100755 --- a/bin/iutils +++ b/bin/iutils @@ -3,12 +3,8 @@ use v6.d; use IUtils; use IUtils::Comments; -my $contents = "/home/nathan/Projects/Idris/structures/test/src/Main.idr".IO.slurp; +unit sub MAIN; -say "\nTesting full flagged-expression:"; -say $contents ~~ &flagged-expression; -when $contents ~~ &flagged-expression { - say $; - say $; - say $; -} +temp $*CWD = "/home/nathan/Projects/Idris/structures/".IO; + +say scan-packages; diff --git a/lib/IUtils.rakumod b/lib/IUtils.rakumod index 2064e2d..9c4cdf6 100644 --- a/lib/IUtils.rakumod +++ b/lib/IUtils.rakumod @@ -3,6 +3,39 @@ 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* + '"' $=[<-["]>*] '"' /) + // "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) +} + +#| 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; +} + + # Utility functions for pack #| Invoke a pack command @@ -24,17 +57,34 @@ sub pack-run(*@cmd) is export { #| Build a package with pack sub pack-build($pkg) is export { - pack-run 'build', $pkg; + pack-run 'build', $pkg } #| Test a package with pack sub pack-test($pkg) is export { - pack-run 'build', $pkg; + pack-run 'build', $pkg } #| Clean a package with pack sub pack-clean($pkg) is export { - pack-run 'clean', $pkg; + 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 @@ -43,7 +93,10 @@ sub idris-run(*@cmd) is export { my $out = $proc.out.slurp(:close); my $err = $proc.err.slurp(:close); unless $proc { - ($out, $err) + IdrisError.new( + out => $out, err => $err, + exit-code => $proc.exitcode, command => @cmd.Str) + .throw; } return $out; } From a4e4c4a31409a764c31d9acca1936f828f52e960 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 31 Dec 2024 16:04:33 +0000 Subject: [PATCH 2/3] Minor tweaks --- META6.json | 5 ++++- lib/IUtils/Comments.rakumod | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/META6.json b/META6.json index e370616..c3f0ccb 100644 --- a/META6.json +++ b/META6.json @@ -6,6 +6,9 @@ "authors": [ "Nathan McCarty " ], + "depends": [ + "paths" + ], "provides": { "IUtils": "lib/IUtils.rakumod", "IUtils::IDEMode": "lib/IUtils/IDEMode.rakumod", @@ -14,5 +17,5 @@ "bin": { "iutils": "bin/iutils" }, - "resources": [ ], + "resources": [ ] } diff --git a/lib/IUtils/Comments.rakumod b/lib/IUtils/Comments.rakumod index 9274e64..edd7e9d 100644 --- a/lib/IUtils/Comments.rakumod +++ b/lib/IUtils/Comments.rakumod @@ -10,5 +10,5 @@ my token name { <[\w \-]>+ } my regex flagged-expression is export { <&comment-start> \h* \h* \V* \v [<&comment-start> \V* \v]* - $= \h+ \: \V* \v + \h+ \: \V* \v } From 9e9903429eb52aabfb247c079fcc29995b4ee51b Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 31 Dec 2024 16:25:05 +0000 Subject: [PATCH 3/3] Scanning checkpoint --- bin/iutils | 24 +++++++++++++++++++----- lib/IUtils.rakumod | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/bin/iutils b/bin/iutils index b0595e5..9f99a00 100755 --- a/bin/iutils +++ b/bin/iutils @@ -3,8 +3,22 @@ use v6.d; use IUtils; use IUtils::Comments; -unit sub MAIN; - -temp $*CWD = "/home/nathan/Projects/Idris/structures/".IO; - -say scan-packages; +#| Execute the tests in an idris project +multi MAIN( + "test", + Str $project-path?, #= Base directory of the project, defaults to $*CWD +) { + # CD into the project path if needed + chdir($project-path.IO.resolve: :completely) if $project-path; + # Scan for our packages + my @packages = scan-packages; + # Collect tests + my @tests; + for @packages -> $package { + # FIXME + say 'Finding tests for ', $package.ipkg.relative; + for $package.sources -> $source { + say 'Scanning for tests in ', $source; + } + } +} diff --git a/lib/IUtils.rakumod b/lib/IUtils.rakumod index 9c4cdf6..d41c8f8 100644 --- a/lib/IUtils.rakumod +++ b/lib/IUtils.rakumod @@ -28,6 +28,9 @@ sub scan-ipkg(IO::Path:D $ipkg --> PackageInfo:D) { 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 =