@@ -14,6 +14,7 @@ our @EXPORT_OK = qw(sorry slurp system_or_die
14
14
gen_nqp gen_parrot) ;
15
15
16
16
our $exe = $^O eq ' MSWin32' ? ' .exe' : ' ' ;
17
+ our $bat = $^O eq ' MSWin32' ? ' .bat' : ' ' ;
17
18
18
19
our @required_parrot_files = qw(
19
20
@bindir@/parrot@exe@
@@ -25,7 +26,7 @@ our @required_parrot_files = qw(
25
26
) ;
26
27
27
28
our @required_nqp_files = qw(
28
- @bindir@/nqp@exe@
29
+ @bindir@/nqp-p @exe@
29
30
) ;
30
31
31
32
our $nqp_git = ' http://github.com/perl6/nqp.git' ;
@@ -82,11 +83,12 @@ sub cmp_rev {
82
83
sub read_config {
83
84
my @config_src = @_ ;
84
85
my %config = ();
86
+ local $_ ;
85
87
for my $file (@config_src ) {
86
88
no warnings;
87
89
if (open my $CONFIG , ' -|' , " $file --show-config" ) {
88
90
while (<$CONFIG >) {
89
- if (/ ^([\w : ]+)=(.*)/ ) { $config {$1 } = $2 }
91
+ if (/ ^([^ \s = ]+)=(.*)/ ) { $config {$1 } = $2 }
90
92
}
91
93
close ($CONFIG );
92
94
}
@@ -264,61 +266,84 @@ sub gen_nqp {
264
266
my $nqp_want = shift ;
265
267
my %options = @_ ;
266
268
269
+ my $backends = $options {' backends' };
267
270
my $gen_nqp = $options {' gen-nqp' };
268
- my $with_parrot = $options {' with-parrot' };
269
271
my $gen_parrot = $options {' gen-parrot' };
270
272
my $prefix = $options {' prefix' } || cwd().' /install' ;
271
273
my $startdir = cwd();
272
274
273
275
my $PARROT_REVISION = ' nqp/tools/build/PARROT_REVISION' ;
274
276
275
- my %config ;
276
- my $nqp_exe ;
277
- if ($with_parrot ) {
278
- %config = read_parrot_config($with_parrot )
279
- or die " Unable to read parrot configuration from $with_parrot \n " ;
280
- $prefix = $config {' parrot::prefix' };
281
- $nqp_exe = fill_template_text(' @bindir@/nqp@ext@' , %config );
282
- %config = read_config($nqp_exe );
277
+ my (%impls , %need );
278
+
279
+ if ($backends =~ / parrot/ ) {
280
+ my %c = read_parrot_config(" $prefix /bin/parrot" );
281
+
282
+ if (%c ) {
283
+ my $bin = fill_template_text(' @bindir@/nqp-p@ext@' , %c );
284
+ $impls {parrot }{bin } = $bin ;
285
+ %c = read_config($bin );
286
+ my $nqp_have = $c {' nqp::version' };
287
+ my $nqp_ok = $nqp_have && cmp_rev($nqp_have , $nqp_want ) >= 0;
288
+ if ($nqp_ok ) {
289
+ $impls {parrot }{config } = \%c ;
290
+ }
291
+ else {
292
+ $need {parrot } = 1;
293
+ }
294
+ }
295
+ else {
296
+ $need {parrot } = 1;
297
+ }
283
298
}
284
- elsif ($prefix ) {
285
- $nqp_exe = " $prefix /bin/nqp$exe " ;
286
- %config = read_config($nqp_exe );
299
+ for my $b (qw/ jvm moar/ ) {
300
+ if ($backends =~ / $b / ) {
301
+ my $postfix = substr $b , 0, 1;
302
+ my $bin = " $prefix /bin/nqp-$postfix$bat " ;
303
+ $impls {$b }{bin } = $bin ;
304
+ my %c = read_config($bin );
305
+ my $nqp_have = $c {' nqp::version' } || ' ' ;
306
+ my $nqp_ok = $nqp_have && cmp_rev($nqp_have , $nqp_want ) >= 0;
307
+ if ($nqp_ok ) {
308
+ $impls {$b }{config } = \%c ;
309
+ }
310
+ else {
311
+ $need {$b } = 1;
312
+ }
313
+ }
287
314
}
288
315
289
- my $nqp_have = $config {' nqp::version' } || ' ' ;
290
- my $nqp_ok = $nqp_have && cmp_rev($nqp_have , $nqp_want ) >= 0;
291
- if ($gen_nqp ) {
292
- my $nqp_repo = git_checkout($nqp_git , ' nqp' , $gen_nqp , $nqp_push );
293
- $nqp_ok = $nqp_have eq $nqp_repo ;
294
- }
295
- elsif (!$nqp_ok || defined $gen_parrot && !-f $PARROT_REVISION ) {
316
+ return %impls unless %need ;
317
+
318
+ if (defined $gen_nqp || defined $gen_parrot ) {
296
319
git_checkout($nqp_git , ' nqp' , $nqp_want , $nqp_push );
297
320
}
298
321
299
- if (defined $gen_parrot ) {
322
+ if ($need { parrot } && defined $gen_parrot ) {
300
323
my ($par_want ) = split (' ' , slurp($PARROT_REVISION ));
301
- $with_parrot = gen_parrot($par_want , %options , prefix => $prefix );
302
- %config = read_parrot_config($with_parrot );
303
- }
304
- elsif (!%config ) {
305
- %config = read_parrot_config(" $prefix /bin/parrot$exe " , " parrot$exe " );
306
- $with_parrot = fill_template_text(' @bindir@/parrot@exe@' , %config );
324
+ my $parrot = gen_parrot($par_want , %options , prefix => $prefix );
325
+ my %c = read_parrot_config($parrot );
326
+ $impls {parrot }{bin } = fill_template_text(' @bindir@/nqp-p@ext@' , %c );
327
+ $impls {parrot }{config } = \%c ;
307
328
}
308
329
309
- if ($nqp_ok && -M $nqp_exe < -M $with_parrot ) {
310
- print " $nqp_exe is NQP $nqp_have .\n " ;
311
- return $nqp_exe ;
312
- }
330
+ return %impls unless defined ($gen_nqp ) || defined ($gen_parrot );
313
331
314
- my @cmd = ($^X, ' Configure.pl' , " --with-parrot=\" $with_parrot \" " ,
315
- " --make-install" );
332
+ my $backends_to_build = join ' ,' , sort keys %need ;
333
+ my @cmd = ($^X, ' Configure.pl' , " --prefix=$prefix " ,
334
+ " --backends=$backends " , " --make-install" );
316
335
print " Building NQP ...\n " ;
317
336
chdir (" $startdir /nqp" );
318
337
print " @cmd \n " ;
319
338
system_or_die(@cmd );
320
339
chdir ($startdir );
321
- return fill_template_text(' @bindir@/nqp@exe@' , %config );
340
+
341
+ for my $k (keys %need ) {
342
+ my %c = read_config($impls {$k }{bin });
343
+ %c = (%{ $impls {$k }{config } || {} }, %c );
344
+ $impls {$k }{config } = \%c ;
345
+ }
346
+ return %impls ;
322
347
}
323
348
324
349
0 commit comments