summaryrefslogtreecommitdiff
blob: 8eeda68c7a5e1545a194b42e5b43c01215b9466b (plain)
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
#!/usr/bin/perl -w
use strict;
use constant NO_DUP_ARGS => qw(-source -target -d -encoding);
use constant STRIP_ARGS => qw(-Werror -implicit:none -J-Xbootclasspath/p:);

my $ECJ_WARNINGS="-nowarn";

my ( @bcoption, @source15, @target15, @cp );
push @bcoption, '-bootclasspath', '@RT_JAR@:@TOOLS_JAR@'
    unless grep {$_ eq '-bootclasspath'} @ARGV;
push @source15, '-source', '1.5'
    unless grep {$_ eq '-source'} @ARGV;
push @target15, '-target', '1.5'
    unless grep {$_ eq '-target'} @ARGV;  
push @cp, '-cp', '.'
    unless grep {$_ =~ '\-c(p|lasspath)'} @ARGV or $ENV{CLASSPATH};
my @ecj_parms = ($ECJ_WARNINGS, @bcoption, @source15, @target15, @cp);

# Work around ecj's inability to handle duplicate command-line
# options and unknown javac options.
sub gen_ecj_opts
{
    my @new_args = @{$_[0]};

    for my $opt (NO_DUP_ARGS) 
    {
	my @indices = reverse grep {$new_args[$_] eq $opt} 0..$#new_args;
	if (@indices > 1) {
	    shift @indices;    # keep last instance only
	    splice @new_args, $_, 2 for @indices;
	}
    }

    for my $opt (STRIP_ARGS) 
    {
	my @indices = reverse grep {$new_args[$_] eq $opt} 0..$#new_args;
	splice @new_args, $_, 1 for @indices;
    }

    return \@new_args;
}

sub split_vm_args
{
    my @new_args = @{$_[0]};

    my @vm_args = map { substr $_, 2 } grep $_ =~ /^-J/, @new_args;
    my @javac_args = grep $_ !~ /^-J/, @new_args;

    return (\@vm_args, \@javac_args);
}

my ($vm_args, $javac_args) = split_vm_args (gen_ecj_opts( \@ARGV ));
my @CLASSPATH = ('@ECJ_JAR@');
push @CLASSPATH, split /:/, $ENV{"CLASSPATH"} if exists $ENV{"CLASSPATH"};
$ENV{"CLASSPATH"} = join ':', @CLASSPATH;
exec '@JAVA@', @$vm_args, 'org.eclipse.jdt.internal.compiler.batch.Main', @ecj_parms, @$javac_args;