Skip to content

Commit

Permalink
Merge branch 'master' into rakudo-star
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Mar 13, 2011
2 parents 075b257 + ae9a71c commit 34588d1
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 73 deletions.
35 changes: 29 additions & 6 deletions lib/Panda.pm
@@ -1,30 +1,34 @@
use v6;
use Pies;
use JSON::Tiny;

class Panda is Pies {
use Panda::Ecosystem;
use Panda::Fetcher;
use Panda::Builder;
use Panda::Tester;
use Panda::Installer;
use Panda::Resources;

has $!srcdir;
has $!destdir;
has $!statefile;
has $!projectsfile;
has $!resources;

submethod BUILD {
callsame; # attribute initialization
$!ecosystem = Panda::Ecosystem.new(
statefile => $!statefile,
projectsfile => $!projectsfile,
);
$!fetcher = Panda::Fetcher.new(srcdir => $!srcdir);
$!builder = Panda::Builder.new(srcdir => $!srcdir);
$!tester = Panda::Tester.new(srcdir => $!srcdir);
$!resources = Panda::Resources.new(srcdir => $!srcdir);
$!fetcher = Panda::Fetcher.new(resources => $!resources);
$!builder = Panda::Builder.new(resources => $!resources);
$!tester = Panda::Tester.new(resources => $!resources);
$!installer = Panda::Installer.new(
srcdir => $!srcdir,
destdir => $!destdir
resources => $!resources,
destdir => $!destdir,
);
}

Expand Down Expand Up @@ -53,7 +57,26 @@ class Panda is Pies {
}

multi method announce('depends', Pair $p) {
self.announce: "{$p.key.name} depends on {$p.value.name}"
self.announce: "{$p.key.name} depends on {$p.value.join(", ")}"
}

method resolve($proj as Str, Bool :$nodeps, Bool :$notests) {
if $proj.IO ~~ :d and "$proj/META.info".IO ~~ :f {
my $mod = from-json slurp "$proj/META.info";
my $p = Pies::Project.new(
name => $mod<name>,
version => $mod<version>,
dependencies => $mod<depends>,
metainfo => $mod,
);
if $.ecosystem.get-project($p.name) {
self.announce: "Installing {$p.name} "
~ "from a local directory '$proj'";
}
$.ecosystem.add-project($p);
nextwith($p.name, :$nodeps, :$notests);
}
nextsame;
}
}

Expand Down
7 changes: 4 additions & 3 deletions lib/Panda/Builder.pm
Expand Up @@ -4,16 +4,17 @@ use File::Find;
use File::Mkdir;

class Panda::Builder does Pies::Builder {
has $!srcdir;
has $!resources;

method build-order(@list) {
# TODO
return @list
}

method build(Pies::Project $p) {
return unless "$!srcdir/{dirname $p.name}/lib".IO ~~ :d;
indir "$!srcdir/{dirname $p.name}", {
my $workdir = $!resources.workdir($p);
return unless "$workdir/lib".IO ~~ :d;
indir $workdir, {
if "Configure.pl".IO ~~ :f {
run 'perl6 Configure.pl' and die "Configure.pl failed";
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Panda/Ecosystem.pm
Expand Up @@ -30,7 +30,7 @@ class Panda::Ecosystem is Pies::Ecosystem {
dependencies => $mod<depends>,
metainfo => $mod,
);
%!projects{$mod<name>} = $p;
self.add-project($p);
}
}

Expand All @@ -47,7 +47,7 @@ class Panda::Ecosystem is Pies::Ecosystem {
# Pies::Ecosystem methods

method add-project(Pies::Project $p) {
%!projects.push($p.name, $p);
%!projects{$p.name} = $p;
}

method get-project($p as Str) {
Expand Down
47 changes: 31 additions & 16 deletions lib/Panda/Fetcher.pm
@@ -1,26 +1,41 @@
use Pies;
use Panda::Common;
use Panda::Resources;
use File::Find;
use File::Mkdir;

class Panda::Fetcher does Pies::Fetcher {
has $!srcdir;
has $!resources;
method fetch (Pies::Project $p) {
my $dir = dirname($p.name);
unless $p.metainfo<repo-type> eq 'git' {
die "Failed fetching {$p.name}, "
~ "sources other than git not yet supported"
}
my $url = $p.metainfo<repo-url>;
indir $!srcdir, {
if "{$!srcdir}/$dir".IO ~~ :d {
indir $dir, {
run 'git pull -q'
my $dest = $!resources.workdir($p);
my $url = $p.metainfo<repo-url>;
given $p.metainfo<repo-type> {
when 'git' {
if $dest.IO ~~ :d {
indir $dest, {
run 'git pull -q'
and die "Failed updating the {$p.name} repo";
};
} else {
run "git clone -q $url $dir"
and die "Failed cloning the {$p.name} repo";
};
} else {
run "git clone -q $url $dest"
and die "Failed cloning the {$p.name} repo";
}
}
when 'local' {
for find(dir => $url).list {
# that's sort of ugly, I know, but we need
# <repo-url> stripped
my $where = "$dest/{$_.dir.substr($url.chars)}";
mkdir $where, :p;
next if $_.IO ~~ :d;
$_.IO.copy("$where/{$_.name}");
}
}
};
default {
die "Failed fetching {$p.name}, "
~ "repo-type $_ not supported";
}
}
# returns the directory where the module lies
# return {$Settings::srcdir} ~ "/$name";
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Panda/Installer.pm
Expand Up @@ -4,11 +4,11 @@ use File::Find;
use File::Mkdir;

class Panda::Installer does Pies::Installer {
has $!srcdir;
has $!resources;
has $!destdir;

method install(Pies::Project $p) {
indir "$!srcdir/{dirname $p.name}", {
indir $!resources.workdir($p), {
if 'blib'.IO ~~ :d {
for find(dir => 'blib', type => 'file').list -> $i {
# .substr(5) to skip 'blib/'
Expand Down
10 changes: 10 additions & 0 deletions lib/Panda/Resources.pm
@@ -0,0 +1,10 @@
use Pies;

class Panda::Resources {
has $!srcdir;
method workdir(Pies::Project $p) {
"$!srcdir/{$p.name.subst(':', '_', :g)}"
}
}

# vim: ft=perl6
4 changes: 2 additions & 2 deletions lib/Panda/Tester.pm
Expand Up @@ -2,10 +2,10 @@ use Pies;
use Panda::Common;

class Panda::Tester does Pies::Tester {
has $!srcdir;
has $!resources;

method test(Pies::Project $p) {
indir "$!srcdir/{dirname $p.name}", {
indir $!resources.workdir($p), {
if 'Makefile'.IO ~~ :f {
run 'make test'
and die "'make test' failed for {$p.name}";
Expand Down
61 changes: 38 additions & 23 deletions lib/Pies.pm
Expand Up @@ -46,35 +46,50 @@ class Pies {

method announce(Str $what, $data) { }

method fetch-helper(Pies::Project $bone) {
self.announce('fetching', $bone);
$!fetcher.fetch($bone);
}
method build-helper(Pies::Project $bone) {
self.announce('building', $bone);
$!builder.build($bone);
}
method test-helper(Pies::Project $bone) {
self.announce('testing', $bone);
$!tester.test($bone);
}
method install-helper(Pies::Project $bone) {
self.announce('installing', $bone);
$!installer.install($bone);
}
method deps-helper(Pies::Project $bone) {
return unless $bone.dependencies[0];
# return a list of projects to be installed
my @deps = $bone.dependencies.map: {
my $littlebone = $.ecosystem.get-project($_)
or die "{$bone.name} depends on $_, "
~ "which was not found in the ecosystem";

next unless $.ecosystem.project-get-state($littlebone)
eq 'absent';
$littlebone;
};
self.announce('depends', $bone => @deps».name) if +@deps;
return @deps;
}

method resolve-helper(Pies::Project $bone, $nodeps,
$notests, $isdep as Bool) {
unless $nodeps {
for $bone.dependencies -> $dep {
next unless $dep;
my $littlebone = $.ecosystem.get-project($dep);
unless $littlebone {
die "Dependency $dep not found in the ecosystem";
}
next unless $.ecosystem.project-get-state($littlebone)
eq 'absent';
self.announce('depends', $bone => $littlebone);
self.resolve-helper($littlebone, $nodeps, $notests, 1);
for self.deps-helper($bone) {
self.resolve-helper($_, $nodeps, $notests, 1);
}
}

self.announce('fetching', $bone);
$!fetcher.fetch: $bone;

self.announce('building', $bone);
$!builder.build: $bone;

unless $notests {
self.announce('testing', $bone);
$!tester.test: $bone;
}

self.announce('installing', $bone);
$!installer.install: $bone;
self.fetch-helper($bone);
self.build-helper($bone);
self.test-helper($bone) unless $notests;
self.install-helper($bone);

$.ecosystem.project-set-state($bone, $isdep ?? 'installed-dep'
!! 'installed');
Expand Down
4 changes: 3 additions & 1 deletion t/panda/builder.t
@@ -1,11 +1,13 @@
use Test;
use Panda::Builder;
use Panda::Resources;

plan 3;

my $srcdir = 'testmodules';

my $b = Panda::Builder.new(srcdir => $srcdir);
my $r = Panda::Resources.new(srcdir => $srcdir);
my $b = Panda::Builder.new(resources => $r);

my $p = Pies::Project.new(name => 'dummymodule');

Expand Down
17 changes: 14 additions & 3 deletions t/panda/fetcher.t
@@ -1,9 +1,12 @@
use Test;
use Panda::Fetcher;
use Panda::Resources;

plan 2;
plan 4;

my $f = Panda::Fetcher.new(srcdir => '/tmp/whatever');
my $srcdir = 'REMOVEME';
my $r = Panda::Resources.new(srcdir => $srcdir);
my $f = Panda::Fetcher.new(resources => $r);

my $p = Pies::Project.new(
name => 'foobar',
Expand All @@ -19,6 +22,14 @@ ok $! ~~ /'Failed cloning'/, 'attempts to clone';

$p.metainfo<repo-type> = 'hg';
try { $f.fetch($p) }
ok $! ~~ /'other than git'/, 'checks repo-type';
ok $! ~~ /'hg not supported'/, 'checks repo-type';

$p.metainfo<repo-type> = 'local';
$p.metainfo<repo-url> = 'testmodules/dummymodule';

lives_ok { $f.fetch($p) }, 'can fetch a local project';
ok "$srcdir/foobar/lib/foo.pm".IO ~~ :f, 'fetch ok';

run "rm -r $srcdir";

# vim: ft=perl6
4 changes: 3 additions & 1 deletion t/panda/installer.t
@@ -1,12 +1,14 @@
use Test;
use Panda::Installer;
use Panda::Resources;

plan 4;

my $srcdir = 'testmodules';
my $destdir = "{cwd}/removeme";

my $b = Panda::Installer.new(srcdir => $srcdir, destdir => $destdir);
my $r = Panda::Resources.new(srcdir => $srcdir);
my $b = Panda::Installer.new(resources => $r, destdir => $destdir);

my $p = Pies::Project.new(name => 'compiledmodule');

Expand Down
4 changes: 3 additions & 1 deletion t/panda/tester.t
@@ -1,11 +1,13 @@
use Test;
use Panda::Tester;
use Panda::Resources;

plan 2;

my $srcdir = 'testmodules';

my $b = Panda::Tester.new(srcdir => $srcdir);
my $r = Panda::Resources.new(srcdir => $srcdir);
my $b = Panda::Tester.new(resources => $r);

my $p = Pies::Project.new(name => 'testme1');

Expand Down

0 comments on commit 34588d1

Please sign in to comment.