source: PSPA/madxPSPA/testing/MadBuildPy.pl @ 478

Last change on this file since 478 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 7.4 KB
Line 
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
6use MIME::Lite; # to send e-mail
7
8if ( $#ARGV != 0 ) {
9    print "expect 1 argument (1) releaseTag! EXIT!\n" ;
10    exit ;
11} else {
12    $releaseTag = @ARGV[0];
13}
14
15open REPORT_FILE, ">MadBuild_Report.txt";
16my $now = localtime;
17print 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
29my $path = $ENV{'PATH'}; # should handle case of empty string
30my $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
33my $ldLibPath = $ENV{'LD_LIBRARY_PATH'}; # should handle case of empty string
34my $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`;
45chop $pwd;
46$extractDir = join("", $pwd, "/MadCvsExtract") ;
47
48
49mkdir($extractDir, 0777);
50chdir($extractDir);
51
52
53$cvsDir = ":gserver:isscvs.cern.ch:/local/reps/madx" ;
54
55
56foreach(@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
63my $buildReport = "";
64
65chdir('./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$compilationOK = 'true'; # default
76
77foreach $makefile (@makefiles){
78
79    TARGETS: foreach $target (@targets){ # this loop now useless
80
81        my $detailedBuildReport = "";
82        $detailedBuildReport = "<table width=\"75%\" border=\"0\">\n";
83        my $startTime  = localtime;
84
85        `make clean`;
86        `rm $target`;
87        `rm $target\_$makefile`; # later-on, $target copied into $target\_$makefile ...
88
89        my $warnings = 0; # default
90        my $makefileInvocation = 'undefined'; # default
91
92        if ($makefile eq 'Makefile'){
93            $makefileInvocation = 'Makefile f95=/opt/intel/Compiler/11.0/081/bin/ia32/ifort DEBUG=NO'; 
94            # intel compiler installed on pcslux99
95        } else {
96            if ($makefile eq 'Makefile_develop'){
97                $makefileInvocation = 'Makefile f95=lf95 DEBUG=YES'; # the Lahey Fortran compiler
98            } else {
99                if ($makefile eq 'Makefile_nag'){
100                    $makefileInvocation = 'Makefile f95=f95 DEBUG=YES'; # f95 is the NAG compiler
101                }
102            }
103        }
104
105        my $makeResult = `make -f $makefileInvocation $target 2>&1`; # for good
106        # $makeResult = "$makefileInvocation"; # for test
107
108        # if we wanted to redirect stdout and stderr into separate files...
109        # system("make -f $makefile $target 1>build_result_stdout 2>build_result_stderr");
110
111        my $warnings = lookForWarnings($makeResult);
112        # colorize warnings
113        $makeResult =~ s/([wW])arning(s?)/<font class=\"warning-font\">\1arning\2<\/font>/g;
114        # undo the above in case the warning appears as '0 warnings'
115        $makeResult =~ s/([\s\t]+0[\s\t]+)<font class=\"warning\-font\">([Ww])arning(s?)<\/font>/\1\2arning\3/g;
116        # make sure line feeds display correctly in HTML
117        $makeResult =~ s/\n/<\/td><\/tr>\n<tr><td>/g;
118        $makeResult = "<tr><td colspan=\"2\">" . $makeResult . "</td></tr>\n\n";
119
120       
121        my $nbOfTargets = `ls $target | wc -w`;
122        if ($nbOfTargets == 1) {
123                # keep all the targets as madx_Makefile_develop,
124                # madx_Makefile_nag and madx_Makefile, as needed by MadTest.pl
125                `cp $target $target\_$makefile`;
126                if ($warnings==0) {
127                        $compilationOutcome{$target} = 'success';
128                } else {
129                        $compilationOutcome{$target} = 'warning';
130                }
131        }
132        else { 
133            $compilationOutcome{$target} = 'failure';
134            $compilationOK = 'false';
135        }
136        $detailedBuildReport .= "<tr class =\"$compilationOutcome{$target}\"><td colspan=\"2\">$target</td><td>$compilationOutcome{$target}</td></tr>\n";
137        $detailedBuildReport .= "<tr><td>$makeResult</td><tr>\n";
138
139        my $outcome = $compilationOutcome{$target};
140        my $endTime = localtime;
141        $detailedBuildReport .= "</table>\n";
142        my $htmlFile = "build_" . $makefile . "_" . $target . ".htm";
143        $buildReport .= "<tr class=\"$outcome\"><td>make -f $makefile $target</td><td><a href=\"$htmlFile\">$outcome</a></td></tr>\n";
144       
145        print REPORT_FILE "Compiling '$target' with '$makefile' yields $outcome\n";
146       
147        createWebPage($htmlFile,$detailedBuildReport,$startTime,$endTime);
148
149    } # for each target
150       
151} # for each makefile
152
153# now create the 'madxp' as symbolic links:
154
155foreach $makefile (@makefiles){
156    # we no longer need to compile madxp, which is now merged with madx.
157    # for the time-being, we create a symbolic to madx so that the test-suite works as usual
158    # in the long-run, all the madx-related stuff should go away.
159    `rm ./madxp\_$makefile`; # just in case the file or link already exists ...
160    `ln -s ./madx\_$makefile ./madxp\_$makefile`;
161}
162
163`make clean`; # final make clean, mostly to remove all the .o files
164
165$buildReport .= "</table>\n";
166
167$endTime = localtime;
168
169createWebPage("build.htm",$buildReport, $startTime, $endTime ); # main page
170
171
172
173# then send an e-mail, in case a compilation trouble encountered
174if ($compilationOK eq 'false'){
175    $msg = MIME::Lite->new(
176                           From       => 'Jean-Luc.Nougaret@cern.ch', # if "" instead of '', '@'->'\@'
177                           'Reply-To' => 'mad-automation-admin@cern.ch',
178                           To         => 'mad-automation-admin@cern.ch', # for good
179#                        To         => 'Jean-Luc.Nougaret@cern.ch', # for test
180                           Subject    => "Automated MAD Build did not succeed",
181                           Data       => "This is an automated e-mail. Check report on\nhttp://test-mad-automation.web.cern.ch/test-mad-automation/build.htm"
182                           );
183    $msg->send;
184}
185
186# return status output, to be processed by the calling MadBuildAndTest.py
187print $compilationOK; # either 'true' or 'false'
188
189 print REPORT_FILE "MadBuild.pl completed\n";
190 close REPORT_FILE;
191
192sub lookForWarnings {
193
194        my $makeOutput = $_[0]; # global variable
195        my $warnings = 0;
196        my @lines = split /\n/, $makeOutput;
197       
198        foreach $line (@lines) {
199                while ( $line =~ /([\s\t]*([\w\d_\-:]+)[\s\t]+[Ww]arning(s?))/g ){
200                        # /g modifier to make it a progressive match
201                        my $prefix = $2;
202                        if ($prefix ne "0") { $warnings=1;}
203                }
204        }
205       
206        return $warnings;
207}
208 
209sub createWebPage {
210    my $file = $website . $_[0];
211    my $buildReport = $_[1];
212    my $startTime = $_[2];
213    my $endTime = $_[3];
214    $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">';
215    $html .= "<html>\n";
216    $html .= "<head>\n";
217    $html .= "<title>MAD build result</title>\n";
218    $html .= "<link rel=stylesheet href=\"./MadTestWebStyle.css\" type=\"text/css\">"; # CSS stylesheet
219    $html .= "</head>\n";
220    $html .= "<!-- automatically generated by the MAD build script -->\n";
221    $html .= "<body>\n";
222    $html .= "<p>Build started $startTime, ended $endTime</p>\n";
223    $html .= $buildReport;
224    $html .= "</body>\n";
225    $html .= "</html>\n";   
226    open(OUT_HTML,">$file");
227    print OUT_HTML $html;
228    close OUT_HTML;
229}
Note: See TracBrowser for help on using the repository browser.