/
Panda.pm
99 lines (87 loc) · 2.89 KB
/
Panda.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use v6;
use Pies;
use JSON::Tiny;
use Panda::Ecosystem;
use Panda::Fetcher;
use Panda::Builder;
use Panda::Tester;
use Panda::Installer;
use Panda::Resources;
class Panda is Pies {
has $.srcdir;
has $.destdir;
has $.statefile;
has $.projectsfile;
has $.resources;
method new(:$srcdir, :$destdir, :$statefile, :$projectsfile) {
my $ecosystem = Panda::Ecosystem.new(
:$statefile,
:$projectsfile,
);
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,
:$destdir,
);
self.bless(*, :$srcdir, :$destdir, :$statefile, :$projectsfile,
:$ecosystem, :$fetcher, :$builder, :$tester,
:$installer);
}
multi method announce(Str $what) {
say "==> $what"
}
multi method announce('fetching', Pies::Project $p) {
self.announce: "Fetching {$p.name}"
}
multi method announce('building', Pies::Project $p) {
self.announce: "Building {$p.name}"
}
multi method announce('testing', Pies::Project $p) {
self.announce: "Testing {$p.name}"
}
multi method announce('installing', Pies::Project $p) {
self.announce: "Installing {$p.name}"
}
multi method announce('success', Pies::Project $p) {
self.announce: "Successfully installed {$p.name}"
}
multi method announce('depends', Pair $p) {
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";
$mod<source-type> = "local";
$mod<source-url> = $proj;
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;
CATCH {
if $_ !~~ X::Panda {
die X::Panda.new($proj, 'resolve', $_.message);
}
if $_.module ne $proj {
X::Panda.new($proj, 'resolve',
'Dependency resolution has failed: '
~ "stage {$_.stage} failed for {$_.module}"
).throw;
}
$_.rethrow;
}
}
}
# vim: ft=perl6