forked from tadzik/panda
/
Fetcher.pm
63 lines (59 loc) · 2.02 KB
/
Fetcher.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
use Pies;
use Panda::Common;
use Panda::Resources;
use File::Find;
use Shell::Command;
class Panda::Fetcher does Pies::Fetcher {
sub die (Pies::Project $p, $d) is hidden_from_backtrace {
X::Panda.new($p.name, 'fetch', $d).throw
}
has $.resources;
method fetch (Pies::Project $p) {
my $dest = $!resources.workdir($p);
# the repo-* variants are kept for backwards compatibility only
my $url = $p.metainfo<source-url> // $p.metainfo<repo-url>;
my $type = $p.metainfo<source-type> // $p.metainfo<repo-type>;
unless $type {
given $url {
when /^ [ 'git:' | 'http' 's'? '://github.com/' ] / {
$type = 'git';
}
default {
die $p, "Unable to determine source-type using source-url";
}
}
$p.metainfo<source-type> = $type;
}
given $type {
when 'git' {
if $dest.IO ~~ :d {
indir $dest, {
shell 'git pull -q'
and die $p, "Failed updating the repo";
};
} else {
shell "git clone -q $url $dest"
and die $p, "Failed cloning the repo";
}
indir $dest, {
my $desc = qx{git describe --always --dirty}.chomp;
$p.metainfo<source-revision> = $desc;
};
}
when 'local' {
for find(dir => $url).list {
# that's sort of ugly, I know, but we need
# <source-url> stripped
my $where = "$dest/{$_.dir.substr($url.chars)}";
mkpath $where;
next if $_.IO ~~ :d;
$_.IO.copy("$where/{$_.name}");
}
}
default {
die $p, "source-type $_ not supported";
}
}
}
}
# vim: ft=perl6