forked from matrix-org/sytest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-deps.pl
executable file
·87 lines (66 loc) · 2.12 KB
/
install-deps.pl
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
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use CPAN;
GetOptions(
'T|notest' => \my $NOTEST,
'n|dryrun' => \my $DRYRUN,
) or exit 1;
sub check_installed
{
my ( $mod, $want_ver, %opts ) = @_;
# we do the import via a subprocess. The main reason for this is that, as
# things get installed, the number of directories to be scanned increases
# (for example, we may add architecture-dependent directories), and perl
# only checks for these to add to @INC at startup.
#
# There are other benefits in doing so:
# - we don't pollute the installation process with lots of random modules
# - we ensure that each module really is installable in its own right.
my $res = `$^X -M$mod -e 1 2>&1`;
if( $? != 0 ) {
die "unable to import $mod: $res";
}
defined $want_ver or return 1;
unless( $want_ver =~ s/^>=\s+// ) {
print STDERR "TODO: can only perform '>=' version checks\n";
return 1;
}
my $inst_ver = `$^X -M$mod -e 'print \$${mod}::VERSION'`;
if( $inst_ver lt $want_ver ) {
die "$mod: got $inst_ver, want $want_ver\n";
}
return 1;
}
sub requires
{
my ( $mod, $ver ) = @_;
eval { check_installed( $mod, $ver ) } and return;
# TODO: check that some location is user-writable in @INC, and that it appears
# somehow in PERL_{MB,MM}_OPT
if( !$DRYRUN ) {
print STDERR "**** Installing $mod ****\n";
if( $NOTEST ) {
CPAN::Shell->notest('install', $mod);
} else {
CPAN::Shell->install($mod);
}
if( not eval { check_installed( $mod, $ver ) } ) {
print STDERR "Failed to import $mod even after installing: $@\n";
exit 1;
}
} else {
print qq($^X -MCPAN -e 'install "$mod"'\n);
}
}
# $CPAN::DEBUG=2047;
# load the config before we override things
CPAN::HandleConfig->load;
# tell CPAN to halt on first failure, to avoid hiding the error with errors
# from things that are now certain to fail
$CPAN::Config->{halt_on_failure} = 1;
# Alien::Sodium will think it is building for javascript if the EMSCRIPTEN env
# var is set.
delete $ENV{EMSCRIPTEN};
do "./cpanfile";