-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqmake.pl
executable file
·127 lines (107 loc) · 3.75 KB
/
qmake.pl
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env perl
# wrapper script for qmake to remove newlines
use strict;
use warnings;
use Cwd;
my $cwd = getcwd;
my $fin_email_addrs = "qmake.finished\@raylim.mm.st charlottekyng+qmake.finished\@gmail.com defilippomr+qmake.finished\@gmail.com";
my $err_email_addrs = "qmake.error\@raylim.mm.st charlottekyng+qmake.error\@gmail.com defilippomr+qmake.error\@gmail.com";
my $start_email_addrs = "qmake.start\@raylim.mm.st charlottekyng+qmake.start\@gmail.com defilippomr+qmake.start\@gmail.com";
sub HELP_MESSAGE {
print "Usage: qmake.pl -n [name] -m -r [numAttempts]\n";
print "-m: e-mails notifications\n";
print "-r: number of attempts (default: 1)\n";
print "-l: parent log dir (default: log)\n";
print "-n: job name\n";
exit(1);
}
use File::Basename;
use File::Glob ':glob';
use File::Path;
use Getopt::Std;
my %opt;
getopts('n:mr:l:', \%opt);
my $attempts = 1;
my $name = "qmake";
my $logparent = "log";
$attempts = $opt{r} if defined $opt{r};
$name = $opt{n} if defined $opt{n};
$logparent = $opt{l} if defined $opt{l};
my $qmake = shift @ARGV;
my $args = join " ", @ARGV;
# makefile processing
=pod
my $orig_args = $args;
$args =~ s;-f (\S+);"-f " . dirname($1) . "/." . basename($1) . ".tmp";e;
my $optf = $1;
my @makefiles;
if (defined $optf) {
push @makefiles, $optf;
} else {
if ($args =~ /--/) {
$args .= " -f .Makefile.tmp";
} else {
$args .= "-- -f .Makefile.tmp";
}
push @makefiles, "Makefile";
}
do {
my $makefile = glob(shift(@makefiles));
open IN, "<$makefile" or die "Unable to open $makefile\n";
my $tmpfile = glob(dirname($makefile) . "/." . basename($makefile) . ".tmp");
open OUT, ">$tmpfile" or die "Unable to open $tmpfile\n";
while (<IN>) {
s/\\\n$//;
if (!/^include \S+\.tmp/ && s;^include (\S+);"include " . dirname($1) . "/." . basename($1) . ".tmp";e) {
push @makefiles, $1;
}
print OUT $_;
}
} until (scalar @makefiles == 0);
=cut
my $n = 0;
my $retcode;
do {
my $logdir = "$logparent/$name";
my $logfile = "$logdir.log";
my $i = 0;
while (-e $logdir || -e $logfile) {
$logdir = "log/$name.$i";
$logfile = "$logdir.log";
$i++;
}
mkpath $logdir;
my $pid = fork;
if ($pid == 0) {
#print "$qmake $args &> $logfile\n";
exec "$qmake $args LOGDIR=$logdir &> $logfile";
} else {
my $mail_msg = "Command: $qmake $args\n";
$mail_msg .= "Attempt #: " . ($n + 1) . " of $attempts\n";
$mail_msg .= "Hostname: " . $ENV{HOSTNAME}. "\n";
$mail_msg .= "PID: $pid\n";
$mail_msg .= "Dir: $cwd\n";
$mail_msg .= "Log dir: $cwd/$logdir\n";
$mail_msg .= "Log file: $cwd/$logfile\n";
if ($opt{m} && ($n == 0 || $n == 1 || $n + 1 == $attempts)) {
my $mail_subject = "$name: job started ($cwd)";
$mail_subject .= " Attempt " . ($n + 1) if $n > 0;
open(MAIL, "| mail -s '$mail_subject' $start_email_addrs");
print MAIL "$mail_msg";
close MAIL;
}
waitpid(-1, 0);
$retcode = $? >> 8; # shift bits to get the real return code
if ($opt{m} && ($retcode == 0 || $n == 0 || $n == 1 || $n + 1 == $attempts)) {
my $addrs = ($retcode > 0)? $err_email_addrs : $fin_email_addrs;
my $mail_subject = "[$retcode] $name: job finished ($cwd)";
$mail_subject = "**FINAL** $mail_subject" if ($n + 1 == $attempts);
$mail_subject .= " Attempt " . ($n + 1) if $n > 0;
open(MAIL, "| mail -s '$mail_subject' $addrs");
print MAIL "Return code: $retcode\n";
print MAIL "$mail_msg";
close MAIL;
}
}
} while ($retcode && ++$n < $attempts);
exit($retcode);