1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # acrontab command: 25 * * * * lxplus (/afs/cern.ch/user/n/nougaret/myMAD/madX/AUTOMATION/MadBuild.pl) > /afs/cern.ch/user/n/nougaret/MADbuilt.out 2>&1 |
---|
4 | |
---|
5 | |
---|
6 | use MIME::Lite; # to send e-mail |
---|
7 | |
---|
8 | if ( $#ARGV != 0 ) { |
---|
9 | print "expect 1 argument (1) releaseTag! EXIT!\n" ; |
---|
10 | exit ; |
---|
11 | } else { |
---|
12 | $releaseTag = @ARGV[0]; |
---|
13 | } |
---|
14 | |
---|
15 | open REPORT_FILE, ">MadBuild_Report.txt"; |
---|
16 | my $now = localtime; |
---|
17 | print REPORT_FILE "MadBuild.pl report from $now\n"; |
---|
18 | |
---|
19 | $startTime = localtime; |
---|
20 | |
---|
21 | #$htmlFile = '/afs/cern.ch/user/n/nougaret/www/mad/build.htm'; # for the time being |
---|
22 | |
---|
23 | $website = "/afs/cern.ch/user/n/nougaret/www/mad/"; |
---|
24 | |
---|
25 | # first set environment variables for lf95 and NAG compilers |
---|
26 | # this is necessary for the acron job which does not perform a login |
---|
27 | # that would set the variables transparently. |
---|
28 | |
---|
29 | my $path = $ENV{'PATH'}; # should handle case of empty string |
---|
30 | my $newPath = $path . ":/afs/cern.ch/sw/fortran/nag/f95.5.361/bin:/afs/cern.ch/sw/fortran/lahey/lf9562/bin"; |
---|
31 | $ENV{'PATH'}=$newPath; |
---|
32 | |
---|
33 | my $ldLibPath = $ENV{'LD_LIBRARY_PATH'}; # should handle case of empty string |
---|
34 | my $newLdLibPath = $ldLlibPath . ":/afs/cern.ch/sw/fortran/lahey/lf9562/lib"; |
---|
35 | $ENV{'LD_LIBRARY_PATH'}=$newLdLibPath; |
---|
36 | |
---|
37 | # flexlm license manager for NAG compiler |
---|
38 | $ENV{'NAGF95_ROOT'}="/afs/cern.ch/sw/fortran/nag/f95.5.361"; |
---|
39 | $ENV{'LM_LICENSE_FILE'}="/afs/cern.ch/sw/fortran/nag/f95.5.361/license.dat"; |
---|
40 | |
---|
41 | @extractedPackages = ('madX'); |
---|
42 | |
---|
43 | |
---|
44 | $pwd = `pwd`; |
---|
45 | chop $pwd; |
---|
46 | $extractDir = join("", $pwd, "/MadCvsExtract") ; |
---|
47 | |
---|
48 | |
---|
49 | mkdir($extractDir, 0777); |
---|
50 | chdir($extractDir); |
---|
51 | |
---|
52 | |
---|
53 | $cvsDir = ":gserver:isscvs.cern.ch:/local/reps/madx" ; |
---|
54 | |
---|
55 | |
---|
56 | foreach(@extractedPackages) { |
---|
57 | my $pack = $_; |
---|
58 | print REPORT_FILE "Extract package $pack from CVS\n"; |
---|
59 | `cvs -d $cvsDir checkout -r $releaseTag $pack`; # now extract for specified release tag |
---|
60 | } |
---|
61 | |
---|
62 | # build |
---|
63 | my $buildReport = ""; |
---|
64 | |
---|
65 | chdir('./madX'); |
---|
66 | |
---|
67 | $buildReport = "<table width=\"75%\" border=\"0\">\n"; |
---|
68 | |
---|
69 | @makefiles = ("Makefile_develop","Makefile_nag","Makefile"); # last one overwrites madx, madxp |
---|
70 | |
---|
71 | #@targets = ("madx","madxp"); # note that madxp is just a link on madx => should clean-up later on... |
---|
72 | # note: we must do the clean-up everywhere, up to TestScenario.xml... |
---|
73 | @targets = ("madx"); |
---|
74 | |
---|
75 | foreach $makefile (@makefiles){ |
---|
76 | |
---|
77 | TARGETS: foreach $target (@targets){ # this loop now useless |
---|
78 | |
---|
79 | my $detailedBuildReport = ""; |
---|
80 | $detailedBuildReport = "<table width=\"75%\" border=\"0\">\n"; |
---|
81 | my $startTime = localtime; |
---|
82 | |
---|
83 | `make clean`; |
---|
84 | `rm $target`; |
---|
85 | `rm $target\_$makefile`; # later-on, $target copied into $target\_$makefile ... |
---|
86 | |
---|
87 | my $warnings = 0; # default |
---|
88 | my $makefileInvocation = 'undefined'; # default |
---|
89 | |
---|
90 | if ($makefile eq 'Makefile'){ |
---|
91 | $makefileInvocation = 'Makefile f95=/opt/intel/Compiler/11.0/081/bin/ia32/ifort DEBUG=NO'; |
---|
92 | # intel compiler installed on pcslux99 |
---|
93 | } else { |
---|
94 | if ($makefile eq 'Makefile_develop'){ |
---|
95 | $makefileInvocation = 'Makefile f95=lf95 DEBUG=YES'; # the Lahey Fortran compiler |
---|
96 | } else { |
---|
97 | if ($makefile eq 'Makefile_nag'){ |
---|
98 | $makefileInvocation = 'Makefile f95=f95 DEBUG=YES'; # f95 is the NAG compiler |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | my $makeResult = `make -f $makefileInvocation $target 2>&1`; # for good |
---|
104 | # $makeResult = "$makefileInvocation"; # for test |
---|
105 | |
---|
106 | # if we wanted to redirect stdout and stderr into separate files... |
---|
107 | # system("make -f $makefile $target 1>build_result_stdout 2>build_result_stderr"); |
---|
108 | |
---|
109 | my $warnings = lookForWarnings($makeResult); |
---|
110 | # colorize warnings |
---|
111 | $makeResult =~ s/([wW])arning(s?)/<font class=\"warning-font\">\1arning\2<\/font>/g; |
---|
112 | # undo the above in case the warning appears as '0 warnings' |
---|
113 | $makeResult =~ s/([\s\t]+0[\s\t]+)<font class=\"warning\-font\">([Ww])arning(s?)<\/font>/\1\2arning\3/g; |
---|
114 | # make sure line feeds display correctly in HTML |
---|
115 | $makeResult =~ s/\n/<\/td><\/tr>\n<tr><td>/g; |
---|
116 | $makeResult = "<tr><td colspan=\"2\">" . $makeResult . "</td></tr>\n\n"; |
---|
117 | |
---|
118 | |
---|
119 | my $nbOfTargets = `ls $target | wc -w`; |
---|
120 | if ($nbOfTargets == 1) { |
---|
121 | # keep all the targets as madx_Makefile_develop, |
---|
122 | # madx_Makefile_nag and madx_Makefile, as needed by MadTest.pl |
---|
123 | `cp $target $target\_$makefile`; |
---|
124 | if ($warnings==0) { |
---|
125 | $compilationOutcome{$target} = 'success'; |
---|
126 | } else { |
---|
127 | $compilationOutcome{$target} = 'warning'; |
---|
128 | } |
---|
129 | } |
---|
130 | else { |
---|
131 | $compilationOutcome{$target} = 'failure'; |
---|
132 | } |
---|
133 | $detailedBuildReport .= "<tr class =\"$compilationOutcome{$target}\"><td colspan=\"2\">$target</td><td>$compilationOutcome{$target}</td></tr>\n"; |
---|
134 | $detailedBuildReport .= "<tr><td>$makeResult</td><tr>\n"; |
---|
135 | |
---|
136 | my $outcome = $compilationOutcome{$target}; |
---|
137 | my $endTime = localtime; |
---|
138 | $detailedBuildReport .= "</table>\n"; |
---|
139 | my $htmlFile = "build_" . $makefile . "_" . $target . ".htm"; |
---|
140 | $buildReport .= "<tr class=\"$outcome\"><td>make -f $makefile $target</td><td><a href=\"$htmlFile\">$outcome</a></td></tr>\n"; |
---|
141 | |
---|
142 | print REPORT_FILE "Compiling '$target' with '$makefile' yields $outcome\n"; |
---|
143 | |
---|
144 | createWebPage($htmlFile,$detailedBuildReport,$startTime,$endTime); |
---|
145 | |
---|
146 | } # for each target |
---|
147 | |
---|
148 | } # for each makefile |
---|
149 | |
---|
150 | # now create the 'madxp' as symbolic links: |
---|
151 | |
---|
152 | foreach $makefile (@makefiles){ |
---|
153 | # we no longer need to compile madxp, which is now merged with madx. |
---|
154 | # for the time-being, we create a symbolic to madx so that the test-suite works as usual |
---|
155 | # in the long-run, all the madx-related stuff should go away. |
---|
156 | `rm ./madxp\_$makefile`; # just in case the file or link already exists ... |
---|
157 | `ln -s ./madx\_$makefile ./madxp\_$makefile`; |
---|
158 | } |
---|
159 | |
---|
160 | `make clean`; # final make clean, mostly to remove all the .o files |
---|
161 | |
---|
162 | $buildReport .= "</table>\n"; |
---|
163 | |
---|
164 | $endTime = localtime; |
---|
165 | |
---|
166 | createWebPage("build.htm",$buildReport, $startTime, $endTime ); # main page |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | # then send an e-mail |
---|
171 | $msg = MIME::Lite->new( |
---|
172 | From => 'Jean-Luc.Nougaret@cern.ch', # if "" instead of '', '@'->'\@' |
---|
173 | 'Reply-To' => 'mad-automation-admin@cern.ch', |
---|
174 | To => 'mad-automation-admin@cern.ch', # for good |
---|
175 | # To => 'Jean-Luc.Nougaret@cern.ch', # for test |
---|
176 | Subject => "Automated MAD Build $compilationOutcome{'madx'} for madx, $compilationOutcome{'madxp'} for madxp", |
---|
177 | Data => "This is an automated e-mail. Check report on\nhttp://test-mad-automation.web.cern.ch/test-mad-automation/build.htm" |
---|
178 | ); |
---|
179 | $msg->send; |
---|
180 | |
---|
181 | print REPORT_FILE "MadBuild.pl completed\n"; |
---|
182 | close REPORT_FILE; |
---|
183 | |
---|
184 | sub lookForWarnings { |
---|
185 | |
---|
186 | my $makeOutput = $_[0]; # global variable |
---|
187 | my $warnings = 0; |
---|
188 | my @lines = split /\n/, $makeOutput; |
---|
189 | |
---|
190 | foreach $line (@lines) { |
---|
191 | while ( $line =~ /([\s\t]*([\w\d_\-:]+)[\s\t]+[Ww]arning(s?))/g ){ |
---|
192 | # /g modifier to make it a progressive match |
---|
193 | my $prefix = $2; |
---|
194 | if ($prefix ne "0") { $warnings=1;} |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | return $warnings; |
---|
199 | } |
---|
200 | |
---|
201 | sub createWebPage { |
---|
202 | my $file = $website . $_[0]; |
---|
203 | my $buildReport = $_[1]; |
---|
204 | my $startTime = $_[2]; |
---|
205 | my $endTime = $_[3]; |
---|
206 | $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">'; |
---|
207 | $html .= "<html>\n"; |
---|
208 | $html .= "<head>\n"; |
---|
209 | $html .= "<title>MAD build result</title>\n"; |
---|
210 | $html .= "<link rel=stylesheet href=\"./MadTestWebStyle.css\" type=\"text/css\">"; # CSS stylesheet |
---|
211 | $html .= "</head>\n"; |
---|
212 | $html .= "<!-- automatically generated by the MAD build script -->\n"; |
---|
213 | $html .= "<body>\n"; |
---|
214 | $html .= "<p>Build started $startTime, ended $endTime</p>\n"; |
---|
215 | $html .= $buildReport; |
---|
216 | $html .= "</body>\n"; |
---|
217 | $html .= "</html>\n"; |
---|
218 | open(OUT_HTML,">$file"); |
---|
219 | print OUT_HTML $html; |
---|
220 | close OUT_HTML; |
---|
221 | } |
---|