Skip to content

Commit 1f25be9

Browse files
the-horoibuclaw
authored andcommitted
dmd-script: Insert $DFLAGS before a -run switch
Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent 141141c commit 1f25be9

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

dmd-script

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,9 @@ sub browse($) {
327327
# Load dmd.conf before before parsing arguments.
328328
readINI();
329329

330-
if ($ENV{DFLAGS}) {
331-
push @ARGV, split /\s+/, $ENV{DFLAGS};
332-
}
333-
330+
# $DFLAGS should go before a -run switch, or at the end of ARGV
331+
my @extra_dflags = split(/\s+/, $ENV{DFLAGS} || "");
332+
my $extra_dflags_used = 0;
334333
my $arg_i = 0;
335334
while ( $arg_i < scalar(@ARGV) ) {
336335
my $arg = $ARGV[$arg_i++];
@@ -465,6 +464,16 @@ while ( $arg_i < scalar(@ARGV) ) {
465464
my $gdc_id = lc($1);
466465
push @out, "-frevert=$gdc_id";
467466
} elsif ( $arg eq '-run' ) {
467+
if ( $extra_dflags_used == 0 ) {
468+
$extra_dflags_used = 1;
469+
470+
# Place the flags before this switch
471+
splice @ARGV, $arg_i - 1, 0, @extra_dflags;
472+
# And start parsing from there next iteration
473+
$arg_i -= 1;
474+
next;
475+
}
476+
468477
$run = 1;
469478

470479
$arg = $ARGV[$arg_i++];
@@ -473,7 +482,7 @@ while ( $arg_i < scalar(@ARGV) ) {
473482
addSourceFile $arg;
474483

475484
push @run_args, @ARGV[$arg_i..$#ARGV];
476-
last;
485+
last;
477486
} elsif ( $arg =~ m/^-shared$/ ) {
478487
push @out, '-shared';
479488
} elsif ( $arg =~ m/^-transition=(.*)$/ ) {
@@ -614,6 +623,14 @@ while ( $arg_i < scalar(@ARGV) ) {
614623
} else {
615624
push @objects, $arg
616625
}
626+
627+
# On the last iteration we append the $DFLAGS, this way
628+
# the flags don't risk being appended to a possible
629+
# `-run` arguments
630+
if ( $extra_dflags_used == 0 && $arg_i >= scalar(@ARGV) ) {
631+
$extra_dflags_used = 1;
632+
push @ARGV, @extra_dflags;
633+
}
617634
}
618635

619636
if ($link || (! $lib && $output_file && scalar(@sources) > 1)) {

0 commit comments

Comments
 (0)