xref: /aoo41x/main/solenv/bin/subsequenttests (revision 12c405ff)
1cdf0e10cSrcweireval 'exec "$PERL" -Sw "$0" "$@"'
2cdf0e10cSrcweir    if 0;
3cdf0e10cSrcweir#*************************************************************************
4cdf0e10cSrcweir#
5cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6cdf0e10cSrcweir#
7cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
8cdf0e10cSrcweir#
9cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
10cdf0e10cSrcweir#
11cdf0e10cSrcweir# This file is part of OpenOffice.org.
12cdf0e10cSrcweir#
13cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
14cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
15cdf0e10cSrcweir# only, as published by the Free Software Foundation.
16cdf0e10cSrcweir#
17cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
18cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
19cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
21cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
22cdf0e10cSrcweir#
23cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
24cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
25cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
26cdf0e10cSrcweir# for a copy of the LGPLv3 License.
27cdf0e10cSrcweir#
28cdf0e10cSrcweir#***********************************************************************/
29cdf0e10cSrcweir
30cdf0e10cSrcweiruse lib("$ENV{SOLARENV}/bin/modules");
31cdf0e10cSrcweiruse SourceConfig;
32cdf0e10cSrcweir
33cdf0e10cSrcweirmy $keep_going = 0;
34cdf0e10cSrcweirmy $dry_run = 0;
35cdf0e10cSrcweirmy $max_running = 1;
36cdf0e10cSrcweirwhile (@ARGV) {
37cdf0e10cSrcweir    my $arg = shift(@ARGV);
38cdf0e10cSrcweir    if ($arg =~ /^-P([1-9]\d*)$/) {
39cdf0e10cSrcweir        $max_running = $1;
40cdf0e10cSrcweir    } elsif ($arg eq '--') {
41cdf0e10cSrcweir        last;
42cdf0e10cSrcweir    } else {
43cdf0e10cSrcweir        my $n = substr($arg, 0, 1) eq '-' ? 1 : 0;
44cdf0e10cSrcweir        while ($n && $n < length($arg)) {
45cdf0e10cSrcweir            my $c = substr($arg, $n++, 1);
46cdf0e10cSrcweir            if ($c eq 'k') {
47cdf0e10cSrcweir                $keep_going = 1;
48cdf0e10cSrcweir            } elsif ($c eq 'n') {
49cdf0e10cSrcweir                $dry_run = 1;
50cdf0e10cSrcweir            } else {
51cdf0e10cSrcweir                $n = 0;
52cdf0e10cSrcweir                last;
53cdf0e10cSrcweir            }
54cdf0e10cSrcweir        }
55cdf0e10cSrcweir        if (!$n) {
56cdf0e10cSrcweir            print STDERR "unknown argument \"$arg\"\n";
57cdf0e10cSrcweir            print STDERR "usage: $0 [-kn] [-P<n>] [-- <args>]\n";
58cdf0e10cSrcweir            print STDERR " -k     continue with other dmake invocations upon\n";
59cdf0e10cSrcweir            print STDERR "        failure\n";
60cdf0e10cSrcweir            print STDERR " -n     write directories that would be processed\n";
61cdf0e10cSrcweir            print STDERR "        to standard output\n";
62cdf0e10cSrcweir            print STDERR " -P<n>  number of parallel dmake invocations\n";
63cdf0e10cSrcweir            print STDERR " <args> are passed to dmake invocations\n";
64cdf0e10cSrcweir            exit(1);
65cdf0e10cSrcweir        }
66cdf0e10cSrcweir    }
67cdf0e10cSrcweir}
68cdf0e10cSrcweir
69cdf0e10cSrcweirmy @testpaths = ();
70cdf0e10cSrcweirmy $sc = SourceConfig->new($ENV{'SOLARSRC'});
71cdf0e10cSrcweirmy $module;
72cdf0e10cSrcweirmy $gbuildpath = "$ENV{'SOLARSRC'}/GNUmakefile";
73cdf0e10cSrcweirforeach $module ($sc->get_active_modules()) {
74cdf0e10cSrcweir    my $buildlst = $sc->get_module_build_list($module);
75cdf0e10cSrcweir    next unless defined($buildlst);
76cdf0e10cSrcweir    my %deps = ();
77cdf0e10cSrcweir    open(BUILDLST, $buildlst) or die("cannot open $buildlst");
78cdf0e10cSrcweir    while (<BUILDLST>) {
79cdf0e10cSrcweir        next unless
80cdf0e10cSrcweir            /^\s*\w+\s+(\S+)\s+nmake\s+-\s+all\s+(\S+)(\s+(:?\S+\s+)*)NULL\s*$/;
81cdf0e10cSrcweir        my ($dir, $id, $ids) = ($1, $2, $3);
82cdf0e10cSrcweir        $dir =~ s|\\|/|g;
83cdf0e10cSrcweir        $dir =~ s|^[^/]+||;
84cdf0e10cSrcweir        my $path = $sc->get_module_path($module) . $dir;
85cdf0e10cSrcweir        my $makefile = $path . '/makefile.mk';
86cdf0e10cSrcweir        open(MAKEFILE, $makefile) or die("cannot open $makefile");
87cdf0e10cSrcweir        while (<MAKEFILE>) {
88cdf0e10cSrcweir            if (/\bOOO_SUBSEQUENT_TESTS\b/) {
89cdf0e10cSrcweir                push(@testpaths, $path);
90cdf0e10cSrcweir                $deps{$id} = $ids;
91cdf0e10cSrcweir                last;
92cdf0e10cSrcweir            }
93cdf0e10cSrcweir        }
94cdf0e10cSrcweir        close(MAKEFILE);
95cdf0e10cSrcweir    }
96cdf0e10cSrcweir    close(BUILDLST);
97cdf0e10cSrcweir    my $id1;
98cdf0e10cSrcweir    foreach $id1 (keys(%deps)) {
99cdf0e10cSrcweir        my ($id2, $ids);
100cdf0e10cSrcweir        while (($id2, $ids) = each(%deps)) {
101cdf0e10cSrcweir            $ids !~ /\s\Q$id1\E\s/ or die("$module: $id2 depends on $id1");
102cdf0e10cSrcweir        }
103cdf0e10cSrcweir    }
104cdf0e10cSrcweir}
105cdf0e10cSrcweir
106cdf0e10cSrcweirif ($dry_run) {
107cdf0e10cSrcweir    foreach $path (@testpaths) {
108cdf0e10cSrcweir        print "$path\n";
109cdf0e10cSrcweir    }
110cdf0e10cSrcweir    print "$gbuildpath\n";
111cdf0e10cSrcweir    exit(0);
112cdf0e10cSrcweir}
113cdf0e10cSrcweir
114cdf0e10cSrcweirmy @failedpaths = ();
115*12c405ffSMichael Stahlmy @gbuildargs = ("-j$max_running", "-s", "-r");
116cdf0e10cSrcweirif ($keep_going) {
117cdf0e10cSrcweir    push(@gbuildargs,"-k");
118cdf0e10cSrcweir}
119cdf0e10cSrcweirpush(@gbuildargs, "--file=$gbuildpath");
120cdf0e10cSrcweirpush(@gbuildargs, "subsequentcheck");
121cdf0e10cSrcweirif (system($ENV{'GNUMAKE'}, @gbuildargs) != 0) {
122cdf0e10cSrcweir	push(@failedpaths,$gbuildpath);
123cdf0e10cSrcweir	@testpaths = () unless $keep_going;
124cdf0e10cSrcweir}
125cdf0e10cSrcweir
126cdf0e10cSrcweirmy $cmd = 'dmake';
127cdf0e10cSrcweirforeach (@ARGV) {
128cdf0e10cSrcweir    s/'/'\''/g;
129cdf0e10cSrcweir    $cmd .= " '" . $_ . "'";
130cdf0e10cSrcweir}
131cdf0e10cSrcweir$cmd .= ' 2>&1 |';
132cdf0e10cSrcweir
133cdf0e10cSrcweirmy %pids = ();
134cdf0e10cSrcweirmy $running = 0;
135cdf0e10cSrcweirmy $counter = 0;
136cdf0e10cSrcweirwhile (@testpaths || $running > 0) {
137cdf0e10cSrcweir    while (@testpaths && $running < $max_running) {
138cdf0e10cSrcweir        my $testpath = shift(@testpaths);
139cdf0e10cSrcweir        ++$counter;
140cdf0e10cSrcweir        print("$counter: make $testpath\n");
141cdf0e10cSrcweir        my $pid = fork();
142cdf0e10cSrcweir        defined($pid) or die("$counter: $!");
143cdf0e10cSrcweir        if ($pid == 0) {
144cdf0e10cSrcweir            chdir($testpath) or die("$counter: $!");
145cdf0e10cSrcweir            $ENV{'OOO_SUBSEQUENT_TESTS'} = 'TRUE';
146cdf0e10cSrcweir            open(OUTPUT, $cmd) or die("$counter: $!");
147cdf0e10cSrcweir            while (<OUTPUT>) {
148cdf0e10cSrcweir                s/\r?\n$//;
149cdf0e10cSrcweir                print("$counter: $_\n");
150cdf0e10cSrcweir            }
151cdf0e10cSrcweir            close(OUTPUT);
152cdf0e10cSrcweir            exit($? == 0 ? 0 : 1);
153cdf0e10cSrcweir        }
154cdf0e10cSrcweir        $pids{$pid} = $testpath;
155cdf0e10cSrcweir        ++$running;
156cdf0e10cSrcweir    }
157cdf0e10cSrcweir    my $pid = wait();
158cdf0e10cSrcweir    $pid != -1 or die($!);
159cdf0e10cSrcweir    my $testpath = delete($pids{$pid});
160cdf0e10cSrcweir    defined($testpath) or die("unmatched PID $pid");
161cdf0e10cSrcweir    if ($? != 0) {
162cdf0e10cSrcweir        push(@failedpaths, $testpath);
163cdf0e10cSrcweir        @testpaths = () unless $keep_going;
164cdf0e10cSrcweir    }
165cdf0e10cSrcweir    --$running;
166cdf0e10cSrcweir}
167cdf0e10cSrcweirmy $failedpath;
168cdf0e10cSrcweirforeach $failedpath (@failedpaths) {
169cdf0e10cSrcweir    print STDERR "failed in $failedpath\n";
170cdf0e10cSrcweir}
171cdf0e10cSrcweirexit(scalar(@failedpaths) == 0 ? 0 : 1);
172