Skip to content

Commit 7109d14

Browse files
committed
import NQP::Configure changes from Rakudo
1 parent 31129a2 commit 7109d14

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed

tools/lib/NQP/Configure.pm

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ our @EXPORT_OK = qw(sorry slurp system_or_die
1414
gen_nqp gen_parrot);
1515

1616
our $exe = $^O eq 'MSWin32' ? '.exe' : '';
17+
our $bat = $^O eq 'MSWin32' ? '.bat' : '';
1718

1819
our @required_parrot_files = qw(
1920
@bindir@/parrot@exe@
@@ -25,7 +26,7 @@ our @required_parrot_files = qw(
2526
);
2627

2728
our @required_nqp_files = qw(
28-
@bindir@/nqp@exe@
29+
@bindir@/nqp-p@exe@
2930
);
3031

3132
our $nqp_git = 'http://github.com/perl6/nqp.git';
@@ -82,11 +83,12 @@ sub cmp_rev {
8283
sub read_config {
8384
my @config_src = @_;
8485
my %config = ();
86+
local $_;
8587
for my $file (@config_src) {
8688
no warnings;
8789
if (open my $CONFIG, '-|', "$file --show-config") {
8890
while (<$CONFIG>) {
89-
if (/^([\w:]+)=(.*)/) { $config{$1} = $2 }
91+
if (/^([^\s=]+)=(.*)/) { $config{$1} = $2 }
9092
}
9193
close($CONFIG);
9294
}
@@ -264,61 +266,84 @@ sub gen_nqp {
264266
my $nqp_want = shift;
265267
my %options = @_;
266268

269+
my $backends = $options{'backends'};
267270
my $gen_nqp = $options{'gen-nqp'};
268-
my $with_parrot = $options{'with-parrot'};
269271
my $gen_parrot = $options{'gen-parrot'};
270272
my $prefix = $options{'prefix'} || cwd().'/install';
271273
my $startdir = cwd();
272274

273275
my $PARROT_REVISION = 'nqp/tools/build/PARROT_REVISION';
274276

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+
}
283298
}
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+
}
287314
}
288315

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) {
296319
git_checkout($nqp_git, 'nqp', $nqp_want, $nqp_push);
297320
}
298321

299-
if (defined $gen_parrot) {
322+
if ($need{parrot} && defined $gen_parrot) {
300323
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;
307328
}
308329

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);
313331

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");
316335
print "Building NQP ...\n";
317336
chdir("$startdir/nqp");
318337
print "@cmd\n";
319338
system_or_die(@cmd);
320339
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;
322347
}
323348

324349

0 commit comments

Comments
 (0)