source: Jenkinsfile @ 8271891

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 8271891 was 85799aa, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Fixed bad copy-paste

  • Property mode set to 100644
File size: 16.9 KB
Line 
1#!groovy
2
3import groovy.transform.Field
4
5//===========================================================================================================
6// Main loop of the compilation
7//===========================================================================================================
8
9node('master') {
10        // Globals
11        BuildDir  = pwd tmp: true
12        SrcDir    = pwd tmp: false
13        Settings  = null
14        Tools     = null
15
16        // Local variables
17        def err = null
18        def log_needed = false
19
20        currentBuild.result = "SUCCESS"
21
22        try {
23                //Wrap build to add timestamp to command line
24                wrap([$class: 'TimestamperBuildWrapper']) {
25
26                        Settings = prepare_build()
27
28                        node(Settings.Architecture.node) {
29                                BuildDir  = pwd tmp: true
30                                SrcDir    = pwd tmp: false
31
32                                clean()
33
34                                checkout()
35
36                                build()
37
38                                test()
39
40                                benchmark()
41
42                                build_doc()
43
44                                publish()
45                        }
46
47                        // Update the build directories when exiting the node
48                        BuildDir  = pwd tmp: true
49                        SrcDir    = pwd tmp: false
50                }
51        }
52
53        //If an exception is caught we need to change the status and remember to
54        //attach the build log to the email
55        catch (Exception caughtError) {
56                //rethrow error later
57                err = caughtError
58
59                echo err.toString()
60
61                //An error has occured, the build log is relevent
62                log_needed = true
63
64                //Store the result of the build log
65                currentBuild.result = "${tools.StageName} FAILURE".trim()
66        }
67
68        finally {
69                //Send email with final results if this is not a full build
70                email(log_needed)
71
72                echo 'Build Completed'
73
74                /* Must re-throw exception to propagate error */
75                if (err) {
76                        throw err
77                }
78        }
79}
80//===========================================================================================================
81// Main compilation routines
82//===========================================================================================================
83def clean() {
84        Tools.BuildStage('Cleanup', true) {
85                // clean the build by wipping the build directory
86                dir(BuildDir) {
87                        deleteDir()
88                }
89        }
90}
91
92//Compilation script is done here but environnement set-up and error handling is done in main loop
93def checkout() {
94        Tools.BuildStage('Checkout', true) {
95                //checkout the source code and clean the repo
96                final scmVars = checkout scm
97                Settings.GitNewRef = scmVars.GIT_COMMIT
98                Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT
99
100                echo GitLogMessage()
101        }
102}
103
104def build() {
105        debug = true
106        release = Settings.RunAllTests || Settings.RunBenchmark
107        Tools.BuildStage('Build : configure', true) {
108                // Configure must be run inside the tree
109                dir (SrcDir) {
110                        // Generate the necessary build files
111                        sh './autogen.sh'
112                }
113
114                // Build outside of the src tree to ease cleaning
115                dir (BuildDir) {
116                        //Configure the conpilation (Output is not relevant)
117                        //Use the current directory as the installation target so nothing escapes the sandbox
118                        //Also specify the compiler by hand
119                        targets=""
120                        if( Settings.RunAllTests || Settings.RunBenchmark ) {
121                                targets="--with-target-hosts='host:debug,host:nodebug'"
122                        } else {
123                                targets="--with-target-hosts='host:debug'"
124                        }
125
126                        ast = Settings.NewAST ? "--enable-new-ast" : "--disable-new-ast"
127
128                        sh "${SrcDir}/configure CXX=${Settings.Compiler.CXX} CC=${Settings.Compiler.CC} ${Settings.Architecture.flags} AR=gcc-ar RANLIB=gcc-ranlib ${targets} ${ast} --quiet --prefix=${BuildDir}"
129
130                        // Configure libcfa
131                        sh 'make -j 8 --no-print-directory configure-libcfa'
132                }
133        }
134
135        Tools.BuildStage('Build : cfa-cpp', true) {
136                // Build outside of the src tree to ease cleaning
137                dir (BuildDir) {
138                        // Build driver
139                        sh 'make -j 8 --no-print-directory -C driver'
140
141                        // Build translator
142                        sh 'make -j 8 --no-print-directory -C src'
143                }
144        }
145
146        Tools.BuildStage('Build : libcfa(debug)', debug) {
147                // Build outside of the src tree to ease cleaning
148                dir (BuildDir) {
149                        sh "make -j 8 --no-print-directory -C libcfa/${Settings.Architecture.name}-debug"
150                }
151        }
152
153        Tools.BuildStage('Build : libcfa(nodebug)', release) {
154                // Build outside of the src tree to ease cleaning
155                dir (BuildDir) {
156                        sh "make -j 8 --no-print-directory -C libcfa/${Settings.Architecture.name}-nodebug"
157                }
158        }
159
160        Tools.BuildStage('Build : install', true) {
161                // Build outside of the src tree to ease cleaning
162                dir (BuildDir) {
163                        sh "make -j 8 --no-print-directory install"
164                }
165        }
166}
167
168def test() {
169        try {
170                Tools.BuildStage('Test: short', !Settings.RunAllTests) {
171                        dir (BuildDir) {
172                                //Run the tests from the tests directory
173                                sh "make --no-print-directory -C tests archiveerrors=${BuildDir}/tests/crashes/short"
174                        }
175                }
176
177                Tools.BuildStage('Test: full', Settings.RunAllTests) {
178                        dir (BuildDir) {
179                                        //Run the tests from the tests directory
180                                        sh """make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=yes archiveerrors=${BuildDir}/tests/crashes/full-debug"""
181                                        sh """make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=no  archiveerrors=${BuildDir}/tests/crashes/full-nodebug"""
182                        }
183                }
184        }
185        catch (Exception err) {
186                echo "Archiving core dumps"
187                dir (BuildDir) {
188                        archiveArtifacts artifacts: "tests/crashes/**/*,lib/**/lib*.so*", fingerprint: true
189                }
190                throw err
191        }
192}
193
194def benchmark() {
195        Tools.BuildStage('Benchmark', Settings.RunBenchmark) {
196                dir (BuildDir) {
197                        //Append bench results
198                        sh "make --no-print-directory -C benchmark jenkins arch=${Settings.Architecture.name}"
199                }
200        }
201}
202
203def build_doc() {
204        Tools.BuildStage('Documentation', Settings.BuildDocumentation) {
205                dir ('doc/user') {
206                        make_doc()
207                }
208
209                dir ('doc/refrat') {
210                        make_doc()
211                }
212        }
213}
214
215def publish() {
216        Tools.BuildStage('Publish', true) {
217
218                if( Settings.Publish && !Settings.RunBenchmark ) { echo 'No results to publish!!!' }
219
220                def groupCompile = new PlotGroup('Compilation', 'duration (s) - lower is better', true)
221                def groupConcurrency = new PlotGroup('Concurrency', 'duration (n) - lower is better', false)
222
223                //Then publish the results
224                do_plot(Settings.RunBenchmark && Settings.Publish, 'compile'        , groupCompile    , false, 'Compilation')
225                do_plot(Settings.RunBenchmark && Settings.Publish, 'compile.diff'   , groupCompile    , true , 'Compilation (relative)')
226                do_plot(Settings.RunBenchmark && Settings.Publish, 'ctxswitch'      , groupConcurrency, false, 'Context Switching')
227                do_plot(Settings.RunBenchmark && Settings.Publish, 'ctxswitch.diff' , groupConcurrency, true , 'Context Switching (relative)')
228                do_plot(Settings.RunBenchmark && Settings.Publish, 'mutex'          , groupConcurrency, false, 'Mutual Exclusion')
229                do_plot(Settings.RunBenchmark && Settings.Publish, 'mutex.diff'     , groupConcurrency, true , 'Mutual Exclusion (relative)')
230                do_plot(Settings.RunBenchmark && Settings.Publish, 'scheduling'     , groupConcurrency, false, 'Internal and External Scheduling')
231                do_plot(Settings.RunBenchmark && Settings.Publish, 'scheduling.diff', groupConcurrency, true , 'Internal and External Scheduling (relative)')
232        }
233}
234
235//===========================================================================================================
236//Routine responsible of sending the email notification once the build is completed
237//===========================================================================================================
238@NonCPS
239def SplitLines(String text) {
240        def list = []
241
242        text.eachLine {
243                list += it
244        }
245
246        return list
247}
248
249def GitLogMessage() {
250        if (!Settings || !Settings.GitOldRef || !Settings.GitNewRef) return "\nERROR retrieveing git information!\n"
251
252        def oldRef = Settings.GitOldRef
253        def newRef = Settings.GitNewRef
254
255        def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim()
256        def revList = SplitLines( revText )
257
258        def gitUpdate = ""
259        revList.each { rev ->
260                def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
261                gitUpdate = gitUpdate + "       via  ${rev} (${type})"
262        }
263
264        def rev = oldRef
265        def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
266        gitUpdate = gitUpdate + "      from  ${rev} (${type})"
267
268        def gitLog    = sh(returnStdout: true, script: "git rev-list --format=short ${oldRef}...${newRef}").trim()
269
270        def gitDiff   = sh(returnStdout: true, script: "git diff --stat --color ${newRef} ${oldRef}").trim()
271        gitDiff = gitDiff.replace('[32m', '<span style="color: #00AA00;">')
272        gitDiff = gitDiff.replace('[31m', '<span style="color: #AA0000;">')
273        gitDiff = gitDiff.replace('[m', '</span>')
274
275        return """
276<pre>
277The branch ${env.BRANCH_NAME} has been updated.
278${gitUpdate}
279</pre>
280
281<p>Check console output at ${env.BUILD_URL} to view the results.</p>
282
283<p>- Status --------------------------------------------------------------</p>
284
285<p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
286
287<p>- Log -----------------------------------------------------------------</p>
288
289<pre>
290${gitLog}
291</pre>
292
293<p>-----------------------------------------------------------------------</p>
294<pre>
295Summary of changes:
296${gitDiff}
297</pre>
298"""
299}
300
301//Standard build email notification
302def email(boolean log) {
303        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
304        //Configurations for email format
305        echo 'Notifying users of result'
306
307        def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
308        def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}"
309        def email_body = """<p>This is an automated email from the Jenkins build machine. It was
310generated because of a git hooks/post-receive script following
311a ref change which was pushed to the C\u2200 repository.</p>
312""" + GitLogMessage()
313
314        def email_to = !Settings.IsSandbox ? "cforall@lists.uwaterloo.ca" : "tdelisle@uwaterloo.ca"
315
316        if( Settings && !Settings.Silent ) {
317                //send email notification
318                emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
319        } else {
320                echo "Would send email to: ${email_to}"
321                echo "With title: ${email_subject}"
322                echo "Content: \n${email_body}"
323        }
324}
325
326//===========================================================================================================
327// Helper classes/variables/routines
328//===========================================================================================================
329//Description of a compiler (Must be serializable since pipelines are persistent)
330class CC_Desc implements Serializable {
331        public String name
332        public String CXX
333        public String CC
334        public String lto
335
336        CC_Desc(String name, String CXX, String CC, String lto) {
337                this.name = name
338                this.CXX = CXX
339                this.CC  = CC
340                this.lto = lto
341        }
342}
343
344//Description of an architecture (Must be serializable since pipelines are persistent)
345class Arch_Desc implements Serializable {
346        public String name
347        public String flags
348        public String node
349
350        Arch_Desc(String name, String flags, String node) {
351                this.name  = name
352                this.flags = flags
353                this.node  = node
354        }
355}
356
357class BuildSettings implements Serializable {
358        public final CC_Desc Compiler
359        public final Arch_Desc Architecture
360        public final Boolean NewAST
361        public final Boolean RunAllTests
362        public final Boolean RunBenchmark
363        public final Boolean BuildDocumentation
364        public final Boolean Publish
365        public final Boolean Silent
366        public final Boolean IsSandbox
367        public final String DescLong
368        public final String DescShort
369
370        public String GitNewRef
371        public String GitOldRef
372
373        BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) {
374                switch( param.Compiler ) {
375                        case 'gcc-9':
376                                this.Compiler = new CC_Desc('gcc-9', 'g++-9', 'gcc-9', '-flto=auto')
377                        break
378                        case 'gcc-8':
379                                this.Compiler = new CC_Desc('gcc-8', 'g++-8', 'gcc-8', '-flto=auto')
380                        break
381                        case 'gcc-7':
382                                this.Compiler = new CC_Desc('gcc-7', 'g++-7', 'gcc-7', '-flto=auto')
383                        break
384                        case 'gcc-6':
385                                this.Compiler = new CC_Desc('gcc-6', 'g++-6', 'gcc-6', '-flto=auto')
386                        break
387                        case 'gcc-5':
388                                this.Compiler = new CC_Desc('gcc-5', 'g++-5', 'gcc-5', '-flto=auto')
389                        break
390                        case 'gcc-4.9':
391                                this.Compiler = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9', '-flto=auto')
392                        break
393                        case 'clang':
394                                this.Compiler = new CC_Desc('clang', 'clang++-10', 'gcc-9', '-flto=thin -flto-jobs=0')
395                        break
396                        default :
397                                error "Unhandled compiler : ${cc}"
398                }
399
400                switch( param.Architecture ) {
401                        case 'x64':
402                                this.Architecture = new Arch_Desc('x64', '--host=x86_64', 'x64')
403                        break
404                        case 'x86':
405                                this.Architecture = new Arch_Desc('x86', '--host=i386', 'x86')
406                        break
407                        default :
408                                error "Unhandled architecture : ${arch}"
409                }
410
411                this.IsSandbox          = (branch == "jenkins-sandbox")
412                this.NewAST             = param.NewAST
413                this.RunAllTests        = param.RunAllTests
414                this.RunBenchmark       = param.RunBenchmark
415                this.BuildDocumentation = param.BuildDocumentation
416                this.Publish            = param.Publish
417                this.Silent             = param.Silent
418
419                def full = param.RunAllTests ? " (Full)" : ""
420                this.DescShort = "${ this.Compiler.name }:${ this.Architecture.name }${full}"
421
422                final ast = this.NewAST ? "New AST" : "Old AST"
423                this.DescLong = """Compiler              : ${ this.Compiler.name } (${ this.Compiler.CXX }/${ this.Compiler.CC })
424AST Version             : ${ ast.toString() }
425Architecture            : ${ this.Architecture.name }
426Arc Flags               : ${ this.Architecture.flags }
427Run All Tests           : ${ this.RunAllTests.toString() }
428Run Benchmark           : ${ this.RunBenchmark.toString() }
429Build Documentation     : ${ this.BuildDocumentation.toString() }
430Publish                 : ${ this.Publish.toString() }
431Silent                  : ${ this.Silent.toString() }
432"""
433
434                this.GitNewRef = ''
435                this.GitOldRef = ''
436        }
437}
438
439class PlotGroup implements Serializable {
440        public String name
441        public String unit
442        public boolean log
443
444        PlotGroup(String name, String unit, boolean log) {
445                this.name = name
446                this.unit = unit
447                this.log = log
448        }
449}
450
451def prepare_build() {
452        // prepare the properties
453        properties ([                                                                                                   \
454                buildDiscarder(logRotator(                                                                              \
455                        artifactDaysToKeepStr: '',                                                                      \
456                        artifactNumToKeepStr: '',                                                                       \
457                        daysToKeepStr: '730',                                                                           \
458                        numToKeepStr: '1000'                                                                            \
459                )),                                                                                                             \
460                [$class: 'ParametersDefinitionProperty',                                                                \
461                        parameterDefinitions: [                                                                         \
462                                [$class: 'ChoiceParameterDefinition',                                           \
463                                        description: 'Which compiler to use',                                   \
464                                        name: 'Compiler',                                                                       \
465                                        choices: 'gcc-9\ngcc-8\ngcc-7\ngcc-6\ngcc-5\ngcc-4.9\nclang',   \
466                                        defaultValue: 'gcc-8',                                                          \
467                                ],                                                                                              \
468                                [$class: 'ChoiceParameterDefinition',                                           \
469                                        description: 'The target architecture',                                 \
470                                        name: 'Architecture',                                                           \
471                                        choices: 'x64\nx86',                                                            \
472                                        defaultValue: 'x64',                                                            \
473                                ],                                                                                              \
474                                [$class: 'BooleanParameterDefinition',                                                  \
475                                        description: 'If true, build compiler using new AST',           \
476                                        name: 'NewAST',                                                                         \
477                                        defaultValue: false,                                                            \
478                                ],                                                                                              \
479                                [$class: 'BooleanParameterDefinition',                                                  \
480                                        description: 'If false, only the quick test suite is ran',              \
481                                        name: 'RunAllTests',                                                            \
482                                        defaultValue: false,                                                            \
483                                ],                                                                                              \
484                                [$class: 'BooleanParameterDefinition',                                                  \
485                                        description: 'If true, jenkins also runs benchmarks',           \
486                                        name: 'RunBenchmark',                                                           \
487                                        defaultValue: false,                                                            \
488                                ],                                                                                              \
489                                [$class: 'BooleanParameterDefinition',                                                  \
490                                        description: 'If true, jenkins also builds documentation',              \
491                                        name: 'BuildDocumentation',                                                     \
492                                        defaultValue: true,                                                             \
493                                ],                                                                                              \
494                                [$class: 'BooleanParameterDefinition',                                                  \
495                                        description: 'If true, jenkins also publishes results',                 \
496                                        name: 'Publish',                                                                        \
497                                        defaultValue: false,                                                            \
498                                ],                                                                                              \
499                                [$class: 'BooleanParameterDefinition',                                                  \
500                                        description: 'If true, jenkins will not send emails',           \
501                                        name: 'Silent',                                                                         \
502                                        defaultValue: false,                                                            \
503                                ],                                                                                              \
504                        ],
505                ]])
506
507        // It's unfortunate but it looks like we need to checkout the entire repo just to get
508        // - the pretty git printer
509        // - Jenkins.tools
510        checkout scm
511
512        Tools = load "Jenkins/tools.groovy"
513
514        final settings = new BuildSettings(params, env.BRANCH_NAME)
515
516        currentBuild.description = settings.DescShort
517        echo                       settings.DescLong
518
519        return settings
520}
521
522def make_doc() {
523        def err = null
524        try {
525                sh 'make clean > /dev/null'
526                sh 'make > /dev/null 2>&1'
527        }
528        catch (Exception caughtError) {
529                err = caughtError //rethrow error later
530                sh 'cat build/*.log'
531        }
532        finally {
533                if (err) throw err // Must re-throw exception to propagate error
534        }
535}
536
537def do_plot(boolean new_data, String file, PlotGroup group, boolean relative, String title) {
538
539        if(new_data) {
540                echo "Publishing new data"
541        }
542
543        def series = new_data ? [[
544                                file: "${file}.csv",
545                                exclusionValues: '',
546                                displayTableFlag: false,
547                                inclusionFlag: 'OFF',
548                                url: ''
549                        ]] : [];
550
551        echo "file is ${BuildDir}/benchmark/${file}.csv, group ${group}, title ${title}"
552        dir("${BuildDir}/benchmark/") {
553                plot csvFileName: "cforall-${env.BRANCH_NAME}-${file}.csv",
554                        csvSeries: series,
555                        group: "${group.name}",
556                        title: "${title}",
557                        style: 'lineSimple',
558                        exclZero: false,
559                        keepRecords: false,
560                        logarithmic: !relative && group.log,
561                        numBuilds: '120',
562                        useDescr: true,
563                        yaxis: group.unit,
564                        yaxisMaximum: '',
565                        yaxisMinimum: ''
566        }
567}
Note: See TracBrowser for help on using the repository browser.