Skip to content

Commit

Permalink
Merge branch 'pod-installing' of github.com:tadzik/panda into pod-ins…
Browse files Browse the repository at this point in the history
…talling
  • Loading branch information
Tadeusz Sośnierz committed Jul 11, 2012
2 parents 395943c + b7c1e4d commit de5092e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bootstrap.bat
@@ -1,4 +1,4 @@
SET PERL6LIB=%CD%\ext;%CD%\lib
SET PERL6LIB=%CD%\ext;%CD%\lib
perl6 bin\panda install File::Tools JSON::Tiny Test::Mock
SET PERL6LIB=%CD%\lib
perl6 bin\panda install panda
8 changes: 2 additions & 6 deletions ext/File/Find.pm
Expand Up @@ -44,21 +44,17 @@ sub checkrules ($elem, %opts) {
return True
}

sub file-from-path($path) {
$path.split('/')[*-1];
}

sub find (:$dir!, :$name, :$type) is export {
my @targets = dir($dir).map: {
File::Find::Result.new(dir => $dir, name => file-from-path(.path));
File::Find::Result.new(dir => $dir, name => .basename);
};
my $list = gather while @targets {
my $elem = @targets.shift;
take $elem if checkrules($elem, { :$name, :$type });
if $elem.IO ~~ :d {
for dir($elem) -> $file {
@targets.push(
File::Find::Result.new(dir => $elem, name => file-from-path($file.path))
File::Find::Result.new(dir => $elem, name => $file.basename)
);
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/Panda.pm
Expand Up @@ -17,16 +17,16 @@ class Panda is Pies {

method new(:$srcdir, :$destdir, :$statefile, :$projectsfile) {
my $ecosystem = Panda::Ecosystem.new(
statefile => $statefile,
projectsfile => $projectsfile,
:$statefile,
:$projectsfile,
);
my $resources = Panda::Resources.new(srcdir => $srcdir);
my $fetcher = Panda::Fetcher.new(resources => $resources);
my $builder = Panda::Builder.new(resources => $resources);
my $tester = Panda::Tester.new(resources => $resources);
my $resources = Panda::Resources.new(:$srcdir);
my $fetcher = Panda::Fetcher.new(:$resources);
my $builder = Panda::Builder.new(:$resources);
my $tester = Panda::Tester.new(:$resources);
my $installer = Panda::Installer.new(
resources => $resources,
destdir => $destdir,
:$resources,
:$destdir,
);
self.bless(*, :$srcdir, :$destdir, :$statefile, :$projectsfile,
:$ecosystem, :$fetcher, :$builder, :$tester,
Expand Down
21 changes: 11 additions & 10 deletions lib/Panda/Builder.pm
Expand Up @@ -37,20 +37,21 @@ class Panda::Builder does Pies::Builder {
return unless "$workdir/lib".IO ~~ :d;
indir $workdir, {
my @files = find(dir => 'lib',
name => /\.p(m6?)|(od)$/).list;
name => /\.p(m6?|od)$/).list;
my @dirs = @files.map(*.dir).uniq;
mkpath "blib/$_" for @dirs;

my @tobuild = self.build-order(@files);
my $p6lib = "{cwd}/blib/lib:{cwd}/lib:{%*ENV<PERL6LIB> // ''}";
for @tobuild -> $file {
$file.IO.copy: "blib/{$file.dir}/{$file.name}";
next if $file ~~ /\.pod$/;
say "Compiling $file";
shell "env PERL6LIB=$p6lib perl6 --target=pir "
~ "--output=blib/{$file.dir}/"
~ "{$file.name.subst(/\.pm6?$/, '.pir')} $file"
and die $p, "Failed building $file";
withp6lib {
for @tobuild -> $file {
$file.IO.copy: "blib/{$file.dir}/{$file.name}";
next if $file ~~ /\.pod$/;
say "Compiling $file";
shell "perl6 --target=pir "
~ "--output=blib/{$file.dir}/"
~ "{$file.name.subst(/\.pm6?$/, '.pir')} $file"
and die $p, "Failed building $file";
}
}
};
}
Expand Down
24 changes: 20 additions & 4 deletions lib/Panda/Common.pm
Expand Up @@ -7,12 +7,28 @@ sub dirname ($mod as Str) is export {

sub indir (Str $where, Callable $what) is export {
my $old = cwd;
LEAVE chdir $old;
mkpath $where;
chdir $where;
my $fail;
try { $what() }
chdir $old;
$!.throw if $!;
$what()
}

sub withp6lib(&what) is export {
my $oldp6lib = %*ENV<PERL6LIB>;
LEAVE {
if $oldp6lib.defined {
%*ENV<PERL6LIB> = $oldp6lib;
}
else {
%*ENV.delete('PERL6LIB');
}
}
my $sep = $*VM<config><osname> eq 'MSWin32' ?? ';' !! ':';
%*ENV<PERL6LIB> = join $sep,
cwd() ~ '/blib/lib',
cwd() ~ '/lib',
%*ENV<PERL6LIB> // '';
what();
}

class X::Panda is Exception {
Expand Down
7 changes: 5 additions & 2 deletions lib/Panda/Ecosystem.pm
Expand Up @@ -25,8 +25,11 @@ class Panda::Ecosystem does Pies::Ecosystem {
}
}

self.update if not $!projectsfile.IO ~~ :f;
self.update if $!projectsfile.IO !~~ :f || $!projectsfile.IO ~~ :z;
my $list = from-json slurp $!projectsfile;
unless defined $list {
die "An unknown error occured while reading the projects file";
}
for $list.list -> $mod {
my $p = Pies::Project.new(
name => $mod<name>,
Expand All @@ -44,7 +47,7 @@ class Panda::Ecosystem does Pies::Ecosystem {

method update {
try unlink $!projectsfile;
shell "wget 'feather.perl6.nl:3000/list' -O '$!projectsfile'";
shell qq[wget "feather.perl6.nl:3000/list" -O "$!projectsfile"];
}

# Pies::Ecosystem methods
Expand Down
4 changes: 3 additions & 1 deletion lib/Panda/Installer.pm
Expand Up @@ -14,7 +14,9 @@ class Panda::Installer does Pies::Installer {
method install(Pies::Project $p) {
indir $!resources.workdir($p), {
if 'blib'.IO ~~ :d {
for find(dir => 'blib', type => 'file').list -> $i {
for find(dir => 'blib', name => /\.p[od|m6?]$/).list,
find(dir => 'blib', name => /\.pir$/).list
-> $i {
# .substr(5) to skip 'blib/'
mkpath "$!destdir/{$i.dir.substr(5)}";
$i.IO.copy("$!destdir/{$i.Str.substr(5)}");
Expand Down
7 changes: 4 additions & 3 deletions lib/Panda/Tester.pm
Expand Up @@ -11,9 +11,10 @@ class Panda::Tester does Pies::Tester {
method test(Pies::Project $p) {
indir $!resources.workdir($p), {
if 't'.IO ~~ :d {
my $p6lib = "{cwd}/blib/lib:{cwd}/lib:{%*ENV<PERL6LIB> // ''}";
my $c = "env PERL6LIB=$p6lib prove -e perl6 -r t/";
shell $c and die $p, "Tests failed";
withp6lib {
my $c = "prove -e perl6 -r t/";
shell $c and die $p, "Tests failed";
}
}
};
}
Expand Down
9 changes: 9 additions & 0 deletions t/panda/common.t
@@ -0,0 +1,9 @@
use v6;
use Test;
use Panda::Common;

plan 2;
my $cwd = cwd;

dies_ok { indir 't', { die "OH NOEZ" } }, '&indir passes exceptions on';
is cwd(), $cwd, 'indir rewinds cwd even when exceptions were thrown';

0 comments on commit de5092e

Please sign in to comment.