Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make Panda::Builder compile modules again, this time in correct order.

Steal module sorting order from ufo.
  • Loading branch information...
commit 4309ab00dca4deec374121d603f903963d7067b0 1 parent b80c41f
@tadzik authored
Showing with 51 additions and 10 deletions.
  1. +49 −7 lib/Panda/Builder.pm
  2. +2 −2 lib/Panda/Common.pm
  3. +0 −1  t/panda/builder.t
View
56 lib/Panda/Builder.pm
@@ -6,9 +6,26 @@ use Shell::Command;
class Panda::Builder does Pies::Builder {
has $.resources;
- method build-order(@list) {
- # TODO
- return @list
+ method build-order(@module-files) {
+ my @modules = map { path-to-module-name($_) }, @module-files;
+ my %module-to-path = @modules Z=> @module-files;
+ my %usages_of;
+ for @module-files -> $module-file {
+ my $fh = open($module-file.Str, :r);
+ my $module = path-to-module-name($module-file);
+ %usages_of{$module} = [];
+ for $fh.lines() {
+ if /^\s* 'use' \s+ (\w+ ['::' \w+]*)/ && $0 -> $used {
+ next if $used eq 'v6';
+ next if $used eq 'MONKEY_TYPING';
+
+ %usages_of{$module}.push(~$used);
+ }
+ }
+ }
+ my @order = topo-sort(@modules, %usages_of);
+
+ return map { %module-to-path{$_} }, @order;
}
method build(Pies::Project $p) {
@@ -33,13 +50,38 @@ class Panda::Builder does Pies::Builder {
my $p6lib = "{cwd}/blib/lib:{cwd}/lib:{%*ENV<PERL6LIB>}";
for @tobuild -> $file {
$file.IO.copy: "blib/{$file.dir}/{$file.name}";
-# shell "env PERL6LIB=$p6lib perl6 --target=pir "
-# ~ "--output=blib/{$file.dir}/"
-# ~ "{$file.name.subst(/\.pm6?$/, '.pir')} $file"
-# and die "Failed building $file";
+ shell "env PERL6LIB=$p6lib perl6 --target=pir "
+ ~ "--output=blib/{$file.dir}/"
+ ~ "{$file.name.subst(/\.pm6?$/, '.pir')} $file"
+ and die "Failed building $file";
}
};
}
+
+ sub topo-sort(@modules, %dependencies) {
+ my @order;
+ my %color_of = @modules X=> 'not yet visited';
+ sub dfs-visit($module) {
+ %color_of{$module} = 'visited';
+ for %dependencies{$module}.list -> $used {
+ if %color_of{$used} eq 'not yet visited' {
+ dfs-visit($used);
+ }
+ }
+ push @order, $module;
+ }
+
+ for @modules -> $module {
+ if %color_of{$module} eq 'not yet visited' {
+ dfs-visit($module);
+ }
+ }
+ @order;
+ }
+
+ sub path-to-module-name($path) {
+ $path.subst(/^'lib/'/, '').subst(/^'lib6/'/, '').subst(/\.pm6?$/, '').subst('/', '::', :g);
+ }
}
# vim: ft=perl6
View
4 lib/Panda/Common.pm
@@ -10,9 +10,9 @@ sub indir (Str $where, Callable $what) is export {
mkpath $where;
chdir $where;
my $fail;
- try { $what(); CATCH { $fail = $! } }
+ try { $what() }
chdir $old;
- die $fail if $fail;
+ $!.throw if $!;
}
# vim: ft=perl6
View
1  t/panda/builder.t
@@ -14,7 +14,6 @@ my $p = Pies::Project.new(name => 'dummymodule');
lives_ok { $b.build($p) };
-todo 'we skip that for now';
ok "$srcdir/dummymodule/blib/lib/foo.pir".IO ~~ :f, 'module compiled';
ok "$srcdir/dummymodule/blib/lib/foo.pm".IO ~~ :f, 'module copied to blib';

0 comments on commit 4309ab0

Please sign in to comment.
Something went wrong with that request. Please try again.