This repository was archived by the owner on Nov 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_extlibs.prl
executable file
·172 lines (155 loc) · 4.73 KB
/
build_extlibs.prl
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/perl
use strict;
use warnings;
use YAML;
use LWP::Simple;
use Cwd;
use Getopt::Std;
use List::MoreUtils qw/distinct/;
our ($opt_l,$opt_d,$opt_n,$opt_v, $opt_c);
getopts('ldn:v:c:') or die "unknown opt";
# clean out environment
delete $ENV{JHC_PATH};
delete $ENV{JHC_OPTS};
delete $ENV{JHC_CACHE};
delete $ENV{JHC_LIBRARY_PATH};
my $tmpdir = "tmp/build";
mkdir "tmp";
mkdir "tmp/build";
sub mysystem {
print( (join " ", @_), "\n");
system @_ and die "Running Command Failed!";
}
sub makelibyaml {
my ($fn) = @_;
my %y;
#$y{Name} = $n;
#$y{Version} = $v;
open my $fd, "<", $fn or die "$!: $fn";
while(my $l = <$fd>) {
begin:
last unless defined $l;
chomp $l;
$l =~ s/\-\-+.*//;
next unless $l =~ /\S/;
if ($l =~ /^(\s*)([\w-]+):\s*(.*?)\s*$/) {
my $z = $1;
my ($n,$v) = ($2,$3);
# print YAML::Dump([$z,$n,$v]);
while ($l = <$fd>) {
chomp $l;
$l =~ s/\-\-+.*//;
next unless $l =~ /\S/;
$l =~ s/^$z\s+// ? $v .= "\n$l" : last;
}
$y{$n} .= "\n$v";
$y{$n} =~ s/^\s*//;
$y{$n} =~ s/\s*$//;
goto begin;
} elsif ($l =~ /^(benchmark|test-suite|executable)\s*/) {
last;
}
}
my %z;
for (keys %y) {
$z{lc $_} = $y{$_};
}
%y = %z;
my $list = sub {
return unless exists $y{$_[0]};
my @ls = split(/\s*[,\n]\s*/, $y{$_[0]});
map { s/^\s*//; s/\s*$//; } @ls;
$y{$_[0]} = [ distinct @ls ];
};
$list->('exposed-modules');
$list->('other-modules');
$list->('hidden-modules');
$list->('build-depends');
$list->('extensions');
$y{'build-suggestions'} = $y{'build-depends'};
delete $y{'build-depends'};
$y{'build-depends'} = [grep { s/([\w-]+).*/$1/; !/^(base|integer|integer-gmp|ghc-prim|array)/ } @{$y{'build-suggestions'}}];
my $res = YAML::Dump(\%y);
print $res;
return $res;
}
if ($opt_c) {
makelibyaml $opt_c;
exit(0);
}
sub fetchsource {
my ($name,$version) = @_;
my $url = "http://hackage.haskell.org/packages/archive/$name/$version/$name-$version.tar.gz";
print "Fetching $url\n";
unless(-e "$tmpdir/$name-$version.tar.gz") {
my $rc = getstore($url, "$tmpdir/$name-$version.tar.gz");
if (is_error $rc) { die "$url: $rc" } ;
}
mysystem "tar -zxv --directory $tmpdir -f $tmpdir/$name-$version.tar.gz" and die "$!: tar";
my $src = -d "$tmpdir/$name-$version/src" ? "/src" : "";
return $src;
}
my %index;
sub fill_index {
return if %index;
my $url = "http://hackage.haskell.org/00-index.tar.gz";
unless(-e "$tmpdir/00-index.tar.gz") {
print "Fetching $url\n";
my $rc = getstore($url, "$tmpdir/00-index.tar.gz");
if (is_error $rc) { die "$url: $rc" } ;
}
my $res = `tar ztf $tmpdir/00-index.tar.gz`;
my @rs = split /\n/,$res;
for (@rs) {
my ($p,$v) = split '/';
$index{$p} = $v;
}
# print YAML::Dump(\%index);
}
sub fetch_package {
my ($name,$version) = @_;
if (!defined $version || $version eq 'latest') {
if ($version ne 'latest' && -f "lib/ext/$name.yaml") {
push @ARGV, "lib/ext/$name.yaml";
return;
}
fill_index;
$version = $index{$name};
die "could not get hackage index, specify version with -v" unless $version;
}
fetchsource($name,$version);
my $yl = makelibyaml "tmp/build/$name-$version/$name.cabal";
my $fn = "tmp/build/$name.yaml";
open my $fh, ">", $fn or die "$!: $fn";
print $fh $yl;
close $fh;
push @ARGV, $fn;
}
if ($opt_n) {
fetch_package($opt_n,$opt_v);
}
foreach my $fn (@ARGV) {
next unless $fn =~ /\.(cabal|yaml)$/;
my $patch = $fn;
$patch =~ s/\.(cabal|yaml)$/.patch/;
print "Processing $fn\n" unless $opt_l;
open my $fh, "<", $fn or die "$!: $fn";
my ($name,$version,$options);
$options = "";
while(<$fh>) {
$name = $1 if /^name:\s*(.*?)\s*$/i;
$version = $1 if /^version:\s*(.*?)\s*$/i;
$options = $1 if /^options:\s*(.*?)\s*$/i;
}
next unless $name;
next unless $version;
$options = "$options --stop deps --deps tmp/$name-deps.yaml" if $opt_d;
print("$name-$version.hl\n"),next if $opt_l;
print "Processing $fn, found $name-$version\n";
my $src = fetchsource($name,$version);
mysystem "patch -d $tmpdir/$name-$version -p1 < $patch" if -e $patch;
mysystem("cp '$fn' '$tmpdir/$name-$version'");
$fn =~ s/.*\///;
mysystem("./jhc $options " . ($ENV{JHC_TEST} || "") .
" --build-hl '$tmpdir/$name-$version/$fn' -L- -L. -i- '-i$tmpdir/$name-$version$src'") and die "$!: jhc";
}