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