/
perlall
executable file
·2656 lines (2348 loc) · 81.4 KB
/
perlall
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
eval 'exec /usr/bin/env perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
#BEGIN {$DB::single=1} # debug into attribute handling
# TODO:
# tee make test with -v (unbuffered IPC::Run or via fork-like callback?)
# maketest or -q: mark FAIL tests *RED*, p line bold black (see t/testc.sh)
# implement smoke, bench
# maketest --all (locally and testvm --all)
# more testvm_ctl: xen-shell, vmrun, VBoXManage
# uninstall: packfile of installed files instead of rather unsafe globbing
# cmd --help
# get msys compiled, bootstrap a mingw perl without strawberry
# build win32 from win32/
# -v --help fails on some machines, broken Pod::Usage
# TEST:
# init-modules: \ handling and `` expansion
# testvm logs back from forks
# fix testvm forked and --fork arg
# 'perlall=5.8* perlall do -m' should filter only main 5.8*
# testvm max balancing
# init is unstable (IO::Tee in IPC::Run) - refactored
# --as explicit and implicit - looks good, but no test
# non-critical TODO:
# 5.8.8 (centos5) fails with Attribute::Handler 0.78_02. monkeypatch or fail?
# build: test perlbrew and HOME friendly (no hardcoded paths)
# windows support (paths, tee, tools), die on other non-POSIX exots (VMS)...
# CPAN::Shell->expand("Devel::*"), not easy todo with metacpan.
use strict;
use 5.006;
our $VERSION = '0.14';
use Config;
use Cwd ();
use File::Spec ();
use File::Basename 'basename';
use Fcntl ();
my @extuse;
BEGIN { # check platform support: perldoc perlport
@extuse = qw(App::Rad IPC::Cmd IO::Scalar Devel::Platform::Info Devel::PatchPerl);
if ($^O !~ /^linux|freebsd|darwin|solaris|openbsd|cygwin$/) {
if ($^O =~ /^vms|dos|bsdos$/) {
die "unsupported OS $^O"; # fixes welcome
} elsif ($^O =~ /^MSWin32|msys/) {
warn "$^O not yet fully supported\n";
} else { # should theoretically work:
# netbsd sunos aix haiku hpux irix next svr4 unicos* plan9
# scary: VOS os390 os400 posix-bc vmesa riscos amigaos beos mpeix
warn "untested OS $^O. Feedback welcome";
# VOS forbids slashes in filenames. no big deal
}
}
sub _auto_use { # autoinstall the non-core modules, and use them
my @m;
for (@_) { push @m, $_ unless eval "require $_;" }
if (@m) { # Checked the API back to 1.76_01 (v5.8.4)
require CPAN; CPAN->import;
warn "CPAN::Shell->install(qw(@m))\n"; CPAN::Shell->install(@m); }
$_->import for @m;
}
_auto_use( @extuse );
}
# 5.8.4: ??, 5.8.5: centos4, 5.8.8: centos5
our @main_releases = qw(5.6.2 5.8.4 5.8.5 5.8.8 5.8.9 5.10.1 5.12.4 5.14.2 5.16.0);
push @App::Rad::ISA, 'main';
our @opts = (
[ "skip=s", "skip versions (glob-style) or --skip=outdated" ],
[ "newer=s", "only newer and same versions (glob-style)" ],
[ "older=s", "only older versions (glob-style)" ],
[ "nogit", "skip @ git versions" ],
[ "main|m", "same as --skip=outdated" ],
[ "reverse|r","reverse, oldest first" ],
[ "quiet|q", "no TEST_VERBOSE, no system >STDOUT" ],
[ "verbose|v","Make perlall command say more" ],
[ "dryrun!", "do not execute commands, only print" ],
[ "nolog", "skip writing log file(s)" ],
[ "help|h", "commands and options" ],
[ "debug|d", "lots of internal debugging output" ],
[ "gittag=s", "for the testvm logfile"],
[ "timeout=i", "IPC::Cmd::run timeout in seconds, Default: 0"],
[ "version|V" ]);
App::Rad->import ('debug') if grep /^-d$/, @ARGV;
App::Rad->run();
=head1 NAME
perlall - build, test and do with all perls
=head1 SYNOPSIS
perlall [opts] cmd [ what [ how ]]
perlall build perl5.15.4
perlall build perl5.14.2-nt
perlall -v build -j4 bleadd-nt smoke-me/khw-tk
perlall build perl5.15.5d-nt-blead-clang blead # or with --as
perlall build --as perl5.15.5d-nt-blead-clang bleadd-nt
perlall uninstall perl5.15.4d-nt@khw-tk
perlall init perl5.15.4d-nt@blead DBI CPAN::SQLite $(cat ~/Perl/B-C/t/top100)
perlall="5.1*" perlall do -MData::Dumper -e'my $a;$b={1=>\$a};$a=\$b;print Dumper($b)'
perlall --older 5.12 make -Mblib t/0basic.t
perlall=5.15.4 perlall maketest # test with version as ENV
perlall="5.14*" perlall makeinstall
perlall cpan My::Module
perlall cpanm More::Modules
perlall maketest "5.*.d*" # test with all debugging, version as option
perlall testvm centos4 centos5 solaris10
perlall initvm --all --max=6
perlall testvm --all --fork -c=init # see testvm in .perlall
perlall config
perlall selfupgrade
=head2 Planned Features
perlall maketest --all
perlall smoke -j4 bleadd-nt smoke-me/*
perlall=5*[0-9]-nt perlall bench [ what [ how ]]
perlall cpan Devel::*Prof*
=head1 OPTIONS
General options before the command:
--skip=s skip versions (glob-style) or --skip=outdated
versions might be a glob-style regex.
E.g. --skip '5.1[024]d*'
--newer=s only newer and same versions (glob-style)
globs may include the special arch suffix.
E.g. perlall do --newer "5.10.?d-nt"
--older=s only older versions. glob-style as in --newer.
--nogit skip @ git versions
--main|-m same as --skip=outdated,
only 5.6.2 5.8.[4589] 5.10.1 5.12.4 5.14.2 5.15.5
--reverse|-r oldest first. default is sorted by newest first
--quiet|-q make perlall command quieter
--verbose|v make perlall command say more
--dryrun! do not execute commands, only print
--nolog skip writing log file(s)
--help|-h commands and options
--debug|-d, lots of internal debugging output
--timeout=i IPC::Cmd::run timeout in seconds, Default: 0
--gittag=s Internally set by testvm for the logfile
--forked! Internally set by testvm
--help|-h
--version|-V
Specific options after the command I<(see also below)>
build and smoke only:
--D=s Configure option
--A=s Configure option
--U=s Configure option
--j=n parallel make
--link -Dmksymlinks with blead, otherwise copy
--install skip Configure && make, only do make install
build and makeinstall:
--notest|-n skip the test suite on build and makeinstall
--force|-f force install
testvm: see L</testvm>
=head1 DESCRIPTION
B<perlall> is like a better L<perlbrew> with a lot of testing
features. The perls are in the default F</usr/local/bin/>, and
F</usr/local/lib/perl5/VERSION> paths, instead of locally, and . You
need write access to the default PREFIX F</usr/local>, e.g. via
C<sudo>. It does not use L<local::lib>, does not mangle C<PERL5LIB>
and builds and keeps sane global perl installations with special
suffices, without the need to save and restore internal states. The
suffices are used in postprocessing scripts.
The currently used perl together with more options is stored as alias
C<p> in F<~/.perlall>, which can be sourced by your F<.profile>.
alias p=perl5.15.4d-nt
Build and init perls:
Version numbers look like C<5.xx.x> and the perl C<suffix> can be any of:
C<d> DEBUGGING
C<-nt> non-threaded, or
C<-m> multi (non-threaded)
C<@xxxxxx> git ids / branch names
You want to switch to use the "thr" suffix, then the default
is non-threaded. This behaviour is controlled via the config setting
C<usethrsuffix=1>. But be consistent to interpret the logfiles.
For older perls special patches are applied to successfully build
them. C<archname> and the archlibs are extended by C<-debug> and
special git suffices. The installed perl binary and on windows
the F<perl.dll> ditto.
Platforms
I use and support perlall on cygwin, linux (debian+centos),
freebsd, openbsd and solaris, with bash, dash and ksh.
Supporting other platforms besides VMS should not be hard.
freebsd needs sudo from ports. mingw (strawberry) support is
planned.
Log Files
Most commands always create a log file with the command, platform
and version, like F<log.maketest-centos5-5.10.1d-nt> or
F<log.makeinstall-osx10.6.8-5.15.4>, F<log.build-osx10.6.8-5.15.4d-nt@30cb48da>.
In the L<B::C> perl-compiler distribution there are some post-processing scripts
F<status_upd>, F<store_rpt>, F<download-reports> for such logfiles.
Windows
Note in cmd.exe you need different quoting rules.
You can try:
perlall do -e"""print $^O"""
But easier is:
perlall do '-e"print $^O"'
=cut
sub setup {
$_[0]->register_commands( {-ignore_prefix => '_'} );
$_[0]->register('install', \&build, "alias to build");
$_[0]->register('smoke', \&build, "(NYI) smoke [ perl<version><suffix> branch ]");
$_[0]->unregister('basename'); #imported (bug)
}
sub App::Rad::Help::usage {
return "Usage: ".basename($0)." [options] command [arguments]";
}
sub pre_process {
my $c = shift;
my $cmd = $c->cmd;
# config defaults: for all
$c->config->{PERLALL_PREFIX} = '/usr/local';
# build only
$c->config->{PERLALL_BUILDROOT} = '/usr/src/perl';
if ($cmd eq 'init') {
$c->config->{cpan} = 'cpan';
$c->config->{'init-modules'} = 'YAML DBI DBD::SQLite CPAN::SQLite Devel::Platform::Info'
.' Params::Util Bundle::CPANReporter2 Math::Round Params::Classify Bundle::CygwinVendor'
.' YAML::XS List::MoreUtils DBIx::Class SQL::Abstract Module::Find Mouse MouseX::Types Modern::Perl'
.' Task::Kensho';
if (basename(Cwd::getcwd) =~/^B-C/ and -f "t/top100") {
_auto_use("File::Slurp");
$c->config->{'init-modules'} .= " "
.join(" ",File::Slurp::read_file("t/top100"));
}
}
my $sudo = $^O =~ /cygwin|msys|MSWin32/ ? "" : "sudo";
$c->config->{sudo} = $sudo;
if ($^O eq 'MSWin32') {
$ENV{HOME} = $ENV{HOMEDRIVE} . $ENV{HOMEPATH} unless $ENV{HOME};
$c->config->{PERLALL_PREFIX} = $Config{prefix};
$c->config->{PERLALL_BUILDROOT} = $ENV{HOME}."\\perl5";
# bindir should be in the path.
if ($Config{installsitebin} and $Config{installsitebin} =~ $ENV{PATH}) {
$c->config->{PERLALL_BINDIR} = $Config{installsitebin};
} else {
$c->config->{PERLALL_BINDIR} = $ENV{HOME}."\\perl5\\bin";
}
}
# read .perlall config
if ($cmd =~ /^build|config|uninstall|init|list|testvm|smoke|do|make.*$|cpan.*/) {
for ( "/etc/perlall", "$ENV{HOME}/.perlall" ) {
$c->_dot_perlall($_) if -f $_;
}
$c->config->{PERLALL_PREFIX} = '/usr/local'
unless $c->config->{PERLALL_PREFIX};
$c->config->{PERLALL_BINDIR} = $c->config->{PERLALL_PREFIX}."/bin"
unless $c->config->{PERLALL_BINDIR};
$c->config->{PERLALL_BUILDROOT} = '/usr/src/perl'
unless $c->config->{PERLALL_BUILDROOT};
$c->config->{'perl-git'} = $c->config->{PERLALL_BUILDROOT}.'/blead/perl-git'
unless $c->config->{'perl-git'};
$c->config->{'perlall_timeout'} = 0 unless $c->config->{'perlall_timeout'};
if ($c->is_command($cmd) and $cmd !~ /^list/) {
# logging + locking
my $d = Devel::Platform::Info->new->get_info();
my $s = $d->{oslabel};
my $v = $d->{osvers};
if ($^O eq 'solaris' and !$s) {
$s = "solaris";
$v = $d->{kvers} if $v eq 'SunOS';
}
$v =~ s/^\D*//; # strip non-number lead
$v =~ s/[^\d\.]//g; # only numbers and dots
$s = $s . $v;
$s =~ s/[\s\(\)\[\}\[\]]//g;
if ($^O eq 'cygwin') {
$s = $d->{source}->{uname}->[2];
$s =~ s/\(.+$//;
$s = 'cygwin'.$s.'_'.$d->{source}->{uname}->[1]; # cygwin1.7.10s_winxp
}
$s = $^O unless $s;
if ($cmd eq 'maketest') {
$c->stash->{logprefix} = "log.test-".lc($s)."-";
} else {
$c->stash->{logprefix} = "log.$cmd-".lc($s)."-";
}
# "we should not disturb a running perlall in this dir"
$c->_check_lock() if $cmd =~ /^do|make/;
}
}
# accept multiple versions?
# expand versions from $ENV{perlall} or version from first argument
if ($cmd =~ /^do|make.*|init|cpanm?|list|uninstall$/) {
my @p;
if ( $c->argv->[0] =~ /^(perl)?5\./ ) {
@p = (shift @{$c->argv});
if ($p[0] =~ /[\*\?\[]/) { # only glob if necessary
$p[0] =~ s/^perl//;
@p = $c->_get_perlall($p[0]);
} else {
$p[0] =~ s/^5\./perl5\./;
}
} else {
@p = $c->_get_perlall();
}
$c->stash->{perlall} = \@p;
}
}
# add opts for specific commands
# getopts overwites the old opts
sub App::Rad::addopts {
my $c = shift;
my $savopts = $c->options;
my @savargv = @ARGV;
if ($c->cmd =~ /^make|do/) {
$c->debug("pass options verbatim through");
@ARGV = ();
}
$c->getopt( @_ );
$c->options->{$_} = $savopts->{$_} for keys %$savopts; # merge with old opts
@ARGV = @savargv;
}
# only process opts before the command.
# all other opts are passed verbatim to the subprocesses
sub App::Rad::_get_input {
my $c = shift;
require Getopt::Long;
die "Getopt::Long needs to be version 2.36 or above"
unless $Getopt::Long::VERSION >= 2.36;
my (@options, @params);
my $base = basename($0);
my $cmd;
if ($base ne 'perlall') {
# take cmd from link name
($cmd) = $base =~ /perlall-(\w+)$/;
$c->{'cmd'} = $cmd;
unless ($c->is_command($cmd)) {
warn "invalid link $base: unknown Command $cmd\n";
return;
}
$c->config->{linked} = $cmd; # yet unused
}
for (my $i=0; $i<@ARGV; $i++) { # the first non-option is the cmd, the rest its args
if (defined ($ARGV[$i]) and substr($ARGV[$i], 0, 1) ne '-') {
$c->{'cmd'} = $ARGV[$i] unless $cmd;
@params = (@ARGV[$i..$#ARGV]);
shift @params unless $c->config->{linked};
last;
}
push @options, ($ARGV[$i]);
}
@{$c->argv} = (@params);
$c->{'cmd'} = '' unless $c->{'cmd'};
my $parser = new Getopt::Long::Parser;
$parser->configure( qw(bundling) );
@ARGV = @options; # getoptions eats @ARGV
my $ret = $parser->getoptions($c->{'_options'}, map {$_->[0]} @opts);
$c->options->{timeout} = $c->config->{perlall_timeout} unless exists $c->options->{timeout};
delete $c->options->{timeout} unless $c->options->{timeout};
$c->debug('received options: ' . join(' ',@options) . ' => '
. _opts($c->options));
$c->debug('received command: ' . $c->{'cmd'});
$c->debug('received parameters: ' . join (' ', @{$c->argv} ));
@ARGV = @{$c->argv};
if (!$c->{'cmd'} and $c->options->{version}) {
return $c->version();
}
return $c;
}
# from cmdline arg or ENV perlall
sub _get_perlall {
my ($c, $glob) = @_;
unless ($glob) {
$glob = $ENV{perlall} ? $ENV{perlall} : "5.*";
}
die "invalid version $glob" if $glob !~ /^5\./ or $glob =~ /[!"';,\(\)]/;
my $prefix = $c->config->{PERLALL_BINDIR};
$prefix = "/usr/local/bin" unless $prefix;
my @p;
my $pathsep = $^O eq 'MSWin32' ? '\\' : '/';
my $perl = "$prefix$pathsep"."perl";
if ($c->options->{dryrun} and $ENV{HARNESS_ACTIVE}) { # testing only
@p = map{"/usr/local/bin/perl$_"} qw(5.8.9d 5.12.1-nt 5.14.2 5.15.4@ababab);
} else {
@p = glob "$perl$glob";
}
# do the filtering
my %skip;
if ($c->options->{skip} or $c->options->{main}) {
if ($c->options->{main} or $c->options->{skip} eq 'outdated') {
# no @git releases only blead
my @np;
for my $p (grep !/\@/, @p) {
push @np, map{index($p, "perl$_")>=0 ? $p :()} @main_releases;
}
@p = @np; @np = ();
for my $p (@p) { # '5.8.9-nt' vs '5.8.9d-nt'
my $nondbg = $p;
$nondbg =~ s/(\.\d)d/$1/; # skip debug if non-debug exists
if ($nondbg ne $p) {
$skip{$p}++ if grep {$nondbg eq $_} @p;
}
}
} else {
%skip = map {$_ => 1} glob $perl.$c->options->{skip};
}
}
@p = grep !/(\@|-git)/,@p if $c->options->{nogit};
# glob-style
if (my $ver = $c->options->{older}) {
# XXX? if last char is non-decimal match this suffix filter also. or use skip
for (@p) {
$skip{$_}++ unless $c->_older( $_, $ver);
}
}
if (my $ver = $c->options->{newer}) { #or same
for (@p) {
$skip{$_}++ if $c->_older( $_, $ver);
}
}
@p = grep(!$skip{$_},@p) if %skip;
# resolve symlinks: @blead => @id (just to simplify implementation)
# XXX: we really should keep the -l and remove the target if also in the list
#for (grep {-l} @p) {
# @p = grep {
# my $b = readlink($_);
# if (basename($b) eq $b) { # -> perl5.some
# $b ne basename($_) ? $_ : 0
# } else { # /usr/bin/perl5.some
# $b ne $_ ? $_ : 0
# }
# } @p;
#}
@p = grep {
(-l $_ and (readlink($_) =~ m|$prefix/perl5\..*|)) ? 0 : $_
} @p;
if ($c->options->{reverse}) { # oldest first
sort { _strip2float($a) <=> _strip2float($b) } @p;
} else {
# sort reverse numerically, newest first
sort { _strip2float($b) <=> _strip2float($a) } @p;
}
}
# string of hash key=val...
sub _opts {
my $h = shift;
my $s = '';
for (keys %$h) {
my $v = $h->{$_};
if (ref($v) eq 'ARRAY') {
for my $v (@{$h->{$_}}) {
$s .= ($v != 1 ? " --".$_."=$v" : " --".$_);
}
} else {
$s .= ($v != 1 ? " --".$_."=$v" : " --".$_);
}
}
substr($s,1);
}
# perl5.14.2d-nt => 14.2
sub _strip2float {
my $p = shift;
$p =~ s/^.*perl5\.//;
$p =~ s/^5\.//;
$p =~ s/(\.\d+)\D.*$/$1/;
$p
}
# if p is older then ver
# $p gets full path
sub _older {
my $c = shift;
my ($p, $ver) = @_;
$p =~ s/^.*perl5\.//;
$p =~ s/^5\.//;
$p =~ s/(\.\d+)\D.*$/$1/;
# perl5.14.2d-nt@345aef vs 5.12 => 14.2 vs 12
$ver =~ s/^5\.//;
$c->debug("_older($_[0], $_[1]) => $p, $ver");
return $p < $ver;
}
sub _dot_perlall {
my ($c, $filename, $write) = (@_);
$c->debug(($write?"writing":"loading")." configuration from $filename");
open my $CONFIG, '<', $filename
or Carp::croak "error opening $filename: $!\n";
my ($s, $NEW);
$write = undef if $c->options->{dryrun};
if ($write) {
open $NEW, '>', $filename.".tmp"
or Carp::croak "error opening $filename.tmp: $!\n";
}
while (<$CONFIG>) {
$s = $_ if $write; # backup
chomp;
s/#.*//;
s/\s+$//;
print $NEW $s if $s and !length;
next unless length;
if (/\\\s*$/) {
my $t = '';
do {
s/\\\s*$//;
s/#.*//;
chomp;
$t .= $_;
} while ($_ = <$CONFIG> and $_ =~ /\\\s*$/);
s/#.*//;
chomp;
$t .= $_;
$_ = $t;
}
s/^\s+//;
if ( m/^alias\s([^\=\:\s]+) # alias key=value
(?:=['"]?) # ='
([^'"]+) # value
/x
) {
my ($k,$v) = ($1, $2);
if ($k eq 'perl-git') {
$v =~ s/^cd //;
$c->config->{$k} = $v;
$v = "cd ".$v;
} else {
$c->config->{$k} = $v;
}
if ($write and $k eq 'p') {
$v = $write;
}
print $NEW "alias $k='$v'\n" if $write;
}
elsif ( m/^([^\=\:\s]+) # key
(?: # (value is optional)
(?:\s*[\=\:]\s*|\s+) # separator ('=', ':', '"' or whitespace)
(.+) # value
)?
/x
) {
my $v = $2;
if (substr($v,0,1) eq '"' and substr($v,-1,1) eq '"') {
$v = substr($v,1,-1);
}
$c->config->{$1} = $v;
print $NEW $s if $write;
} elsif ($write) {
print $NEW $s;
}
}
close $CONFIG;
if ($write) {
close $NEW;
unlink $CONFIG;
rename $filename.".tmp", $filename
or Carp::croak "error writing $filename: $!\n";
}
scalar keys %{$c->config};
}
# store alias p if explicitly wished (2nd arg $p),
# or if only one version was selected. received with no perl prefix
sub _set_alias {
my ($c, $p) = @_;
my $f = "$ENV{HOME}/.perlall";
unless ($p) {
$p = $c->stash->{perlall}->[0] if @{$c->stash->{perlall}} == 1;
$c->_dot_perlall($f, $p) if -f $f and $p; # set alias
} else {
$c->_dot_perlall($f, "perl$p") if -f $f and $p; # set alias
}
""
}
sub _numonly {
my $p = shift;
$p =~ s/^.*perl//;
$p =~ s/\-.+$//;
$p =~ s/@.+$//;
$p =~ s/thr$//;
$p =~ s/d$//;
return $p;
}
sub _short {
my $p = shift;
$p =~ s/^.*perl//;
return $p;
}
sub _print {
my $level = shift;
if ($^O eq 'MSWin32') {
print join(" ",@_),"\n";
} elsif ($level == 0) { # bold green, highest level, headers
print "\033[1;32m",join(" ",@_),"\033[0;0m\n";
} elsif ($level == 1) { # bold red/black, major commands
print "\033[1;39m",join(" ",@_),"\033[0;0m\n";
}
}
sub _backup($) {
my $f = shift;
my $i = 1;
while (-e "$f.$i") { $i++ }
rename $f,"$f.$i";
}
sub __system {
my $c = shift;
unless ($c->options->{dryrun}) {
# MSWin32 ExtUtils::Command methods (tools_other section)
if ($^O eq 'MSWin32' and $_[0] =~ /^(rm|mv|mkdir) /) {
my $what = join " ",@_;
if ($what =~ /^rm -rf/) {
system("$^X -MExtUtils::Command -e 'rm_rf' -- ",substr($what,6));
} elsif ($what =~ /^rm /) {
system("$^X -MExtUtils::Command -e 'rm_f' -- ",substr($what,5));
} elsif ($what =~ /^mv /) {
system("$^X -MExtUtils::Command -e 'mv' -- ",substr($what,3));
} elsif ($what =~ /^mkdir (-p)?(.*)/) {
system("$^X -MExtUtils::Command -e 'mkpath' -- $2");
} else {
die "unhandled $what";
}
# native chdir/rmdir/mkdir/unlink/rename
} elsif ($_[0] =~ /^chdir|rmdir|mkdir|unlink|rename$/) {
my $cmd = shift @_;
my $what = join "','",@_;
if ($cmd =~ /^mkdir -p/) {
system(@_);
} else {
eval "$cmd('$what')";
}
} else {
my $fh = $c->stash->{log_fh};
if ($^O eq 'MSWin32') {
# Need to replace ' with " otherwise we would need to write
# perlall do -e"""print $^O""". Now we only need to do
# perlall do '-e"print $^O"'
map { s/\'/"/g } @_;
}
my ($success, $error_message, $full_buf, $stdout_buf, $stderr_buf) =
IPC::Cmd::run('command' => [ @_ ],
($c->options->{verbose}
? ('verbose' => 1) : ()),
(defined $c->options->{timeout}
? ('timeout' => $c->options->{timeout} )
: ())
);
if ($fh and !$c->options->{verbose} and @$full_buf) {
print $fh $_ for @$full_buf;
if (!$c->options->{quiet} and $c->cmd =~ /^smoke|do|make.*|cpan.*/) {
print $_ for @$stdout_buf;
}
}
if (@$stderr_buf and !$c->options->{quiet}) {
print STDERR $_ for @$stderr_buf;
}
$success;
}
}
}
sub _loginit {
my $c = shift;
my $q = $c->options->{quiet};
my $v = $c->options->{verbose};
my $dryrun = $c->options->{dryrun};
my $log = $c->stash->{log};
if ( !$dryrun and $log ) {
_backup($log) if -e $log;
$c->stash->{log_fh} = IO::File->new($v ? ">& $log" : "> $log");
}
}
# $c->_log(level, @messages)
# -q only print to log, STDOUT level 0
# STDOUT level 1, STDOUT+STDERR >>log
# -v tee to STDOUT (STDERR not yet) and log
sub _log {
my $c = shift;
my $level = shift;
my $q = $c->options->{quiet};
my $v = $c->options->{verbose};
my $dryrun = $c->options->{dryrun};
my $log = $c->stash->{log};
my $fh = $c->stash->{log_fh};
local $| = 1;
if ($log) {
$c->_loginit unless $fh;
$fh = $c->stash->{log_fh};
if (!$q) {
if ($level ne '') {
_print($level,@_);
}
if ($fh) {
print $fh join(" ",@_),"\n";
$fh->flush;
} elsif ($level eq '') {
print join(" ",@_),"\n"; # fails on my centos5
}
} elsif ($level == 0) {
_print(0,@_);
}
} elsif ($v or $level == 0) {
if ($level ne '') {
_print($level,@_);
} else {
print join(" ",@_),"\n";
}
}
}
sub _system {
my $c = shift;
$c->_log('', @_) unless $c->options->{quiet};
$c->__system(@_);
}
sub _system0 {
my $c = shift;
$c->_log(0,@_);
$c->__system(@_);
}
sub _system1 {
my $c = shift;
$c->_log(1,@_);
$c->__system(@_);
}
sub _check_lock {
my $lock = Cwd::getcwd()."/perlall.lock";
if (-f $lock) {
print "$lock exists. Probably perlall still running.\n";
system("pgrep","-fl","perlall");
exit 1;
}
open LOCK,">",$lock;# XXX where? for build in the builddir
print LOCK $$,"\n";
close LOCK;
$SIG{INT} = $SIG{TERM} = sub {my $l=$lock; unlink $l if -f $l; exit 1; };
END {
my $l = $lock;
if (-f $l) { # do not override other locks
open LOCK,"<",$l;
my $pid = <LOCK>;
chomp $pid;
close LOCK;
if ($$ == $pid) {
unlink $l;
} else {
warn "Other perlall process $pid still running. perlall.lock kept\n";
warn `ps -l -p $pid`,"\n";
# unlink $l;
}
}
}
}
sub _lognew {
my $c = shift;
my $p = shift;
if ($p) {
$p = substr($p,0,-4) if $p =~ /\.exe$/;
$c->stash->{log} = $c->stash->{logprefix} . $p;
} else {
$c->stash->{log} = substr($c->stash->{logprefix},0,-1); # strip last -
}
if ($c->stash->{log_fh}) {
$c->stash->{log_fh}->close() if ref($c->stash->{log_fh}) eq 'IO::File';
undef $c->stash->{log_fh};
}
$c->_loginit();
}
# -i inplace editing or just grep
# print unless /<command-line>/
# s,$dll,$newdll,; print
sub _grep {
my $c = shift;
my $cmd = shift;
my ($inplace, $out);
if (substr($cmd,0,3) eq '-i ') {
$inplace = 1;
$cmd = substr($cmd,3);
}
$c->_log('',"perl -i~ -ne'$cmd'",join(" ",@_)) if $inplace;
return if $c->options->{dryrun};
my $catch = '';
while (my $f = shift @_) {
next unless -f $f;
my $b = $f;
if ($inplace) {
$b .= "~";
unlink $b if -e $b; # does this work on windows?
rename($f, $b);
open($out, ">", $f);
select $out;
} else {
$out = IO::Scalar->new(\$catch);
select $out;
}
open(IN, "<", $b);
LINE: while (<IN>) {
eval $cmd;
}
close IN;
close $out;
}
select(STDOUT);
$catch;
}
# takes path to file and applies all os patches from HEAD up to blead
sub _patch {
my ($c, $file) = @_;
$c->_system("git show HEAD..blead $file | patch -N -p1")
and warn("patch HEAD..blead $file had some errors\n");
}
# like Porting/bisect-runner.pl apply_commit
sub _apply_commit {
my ($c, $commit, @files) = @_;
$c->_system("git show $commit @files | patch -N -p1")
and warn("cannot apply commit $commit".(@files ? " to @files":"")."\n");
}
sub _teardown {
my $c = shift;
close $c->stash->{log_fh} if $c->stash->{log_fh};
""
}
sub _fail {
my $c = shift;
if ($c->options->{verbose}) {
warn $c->{output}," at perlall line @{[(caller(0))[2]]}\n";
}
die "@_\n";
}
sub _glob_git {
my $c = shift;
my $git = shift;
return qw(smoke-me/scream smoke-me/taint.t ) if $c->options->{dryrun};
my $srcdir = $c->config->{'perl-git'};
my $cwd = Cwd::getcwd;
chdir "$srcdir/.git/refs/heads" or die;
# XXX expand subdirs with glob. smoke-me/s*: smoke-me/s/r => smoke-me/s
# => File::Find
my @git = glob $git;
chdir "../remotes/origin" or die;
push @git, glob $git;
chdir "../../tags" or die;
push @git, glob $git;
chdir $cwd or die;
return @git;
}
=head2 COMMANDS
=over
=item B<build> [OPTIONS] <version><suffix> [ branch|from ]
Build and install the given version of perl.
The optional 2nd argument C<from> can be a git tag/commit/branch id,
e.g. a smoke-me branch, or a file or url with the perl-*.tar.gz.
The branchname or commit-id is added to the archname and dll suffix, such as
C<@sproututf8> for C<sprout/utf8>, the binary name is taken from the
first argument. All unreleased git versions, like C<blead> or C<smoke-me>
branches get a C<@gitid> suffix. C<smoke-me/> is stripped from the
suffix. The special version "blead" denotes the latest version.
E.g. C<perlall build blead-nt> builds latest non-threaded.
If the checkout from a bit branch is not a release, the suffix will be
marked with C<@> and the sources are copied to the
builddir.
C<-Dmksymlinks> is used for blead, unless the option C<--link> is
specified.
On cygwin and windows the F<perl*.dll> also gets the suffix, because they
are stored globally.
The specified perl is taken from a perl git repo (version or tag or branch)
(specified via perl-git in ~/.perlall), or downloaded
via CPAN. (not yet)
C<man> files are not installed. This is the job for the default
/usr/local/bin/perl or /usr/bin/perl.
C<-Dusedevel> is always used to install versioned executables.
Special site-specific non-default config vars are taken from
F</usr/local/bin/perl>, such as C<cf_email, perladmin, ccflags, cc,
ldflags, ld, pager, libpth, incpth, useshrplib>.
The builddir is under C<PERLALL_BUILDROOT> (Default: "/usr/src/perl")
as "build-E<lt>versionE<gt>E<lt>suffix>"
The intermediate "make install DESTDIR" as "inst-E<lt>versionE<gt>E<lt>suffixE<gt>".
Specific Options:
-D.. -U.. -A.. pass through switches to the perl Configure script.
perlall build perl5.10.1-nt -Dusemymalloc -Uuselargefiles
Certain special switches are merged from F</usr/local/bin/perl> or F</usr/bin/perl>
--as name Install a given perl under the given name. (not yet)
perlall build perl5.6.2 -Dusemymalloc --as perl5.6.2-mymalloc
perlall build blead-nt smoke-me/test --as perl5.15.4-test
-jnum Enable parallel make and test (if supported by the target perl)
perlall build -j5 perl5.12.3
--link Force -Dmksymlinks to the srcdir for blead only.
Otherwise releases from git are copied anew.
-n|--notest Skip the test suite
-f|--force Force installation if make test fails.
--install skip Configure, make, make test. make install only.
=cut
sub build
:Help('build [opts] perl<version><suffix> [ branch|from ]')
{
my $c = shift;
# special build options (after the cmd)
if (@{$c->argv}) {
my @build_opts =
(
[ "as=s", "install perl under given name" ],
[ "D=s@", "./configure option" ],
[ "A=s@", "./configure option" ],
[ "U=s@", "./configure option" ],
[ "j=n", "parallel make (>5.10)" ],
[ "link", "make symlinks (blead only) from git" ],
[ "notest|n", "skip the test suite on build and makeinstall" ],
[ "force|f", "force install" ],
[ 'install', 'only do install' ],
);
$c->addopts( map {$_->[0]} @build_opts );
}
my @args = @{$c->argv};
my $p = $args[0];
if ($p =~ /^(perl)?5\./ ) {
shift @args;
} elsif ($p =~ /^blead/ ) {
my $srcdir = $c->config->{'perl-git'} or $c->_fail("blead needs perl-git");
my $v = `$^X -ane'print \$F[2] if /PERL_API_VERSION/' $srcdir/patchlevel.h`;
my $sv = `$^X -ane'print \$F[2] if /PERL_API_SUBVERSION/' $srcdir/patchlevel.h`;
$p = "5.$v.$sv".substr($p,5);
if (@args > 1) {
shift @args;
} else {