Changeset 692de479 for Jenkinsfile


Ignore:
Timestamp:
Feb 22, 2017, 5:22:49 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
734891d
Parents:
396ee0a (diff), 8fa3c7e6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'jenkins-sandbox'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Jenkinsfile

    r396ee0a r692de479  
    22
    33//===========================================================================================================
    4 // Main compilation routines
    5 //===========================================================================================================
    6 //Compilation script is done here but environnement set-up and error handling is done in main loop
    7 def cfa_build(boolean full_build, String flags) {
    8         build_stage 'Checkout'
    9                 def install_dir = pwd tmp: true
    10                 //checkout the source code and clean the repo
    11                 checkout scm
    12 
    13                 //Clean all temporary files to make sure no artifacts of the previous build remain
    14                 sh 'git clean -fdqx'
    15 
    16                 //Reset the git repo so no local changes persist
    17                 sh 'git reset --hard'
    18 
    19         build_stage 'Build'
    20 
    21                 //Configure the conpilation (Output is not relevant)
    22                 //Use the current directory as the installation target so nothing
    23                 //escapes the sandbox
    24                 //Also specify the compiler by hand
    25                 sh "./configure CXX=${currentCC.cpp_cc} ${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
    26 
    27                 //Compile the project
    28                 sh 'make -j 8 --no-print-directory V=0 install'
    29 
    30         build_stage 'Test'
    31 
    32                 //Run the tests from the tests directory
    33                 if (full_build) {
    34                         sh 'make -C src/tests all-tests debug=yes'
    35                         sh 'make -C src/tests all-tests debug=no'
    36                 }
    37                 else {
    38                         sh 'make -C src/tests'
    39                 }
    40 
    41         build_stage 'Cleanup'
    42 
    43                 //do a maintainer-clean to make sure we need to remake from scratch
    44                 sh 'make maintainer-clean > /dev/null'
    45 }
    46 
    47 def make_doc() {
    48         def err = null
    49 
    50         try {
    51                 sh 'make clean > /dev/null'
    52                 sh 'make > /dev/null 2>&1'
    53         }
    54 
    55         catch (Exception caughtError) {
    56                 //rethrow error later
    57                 err = caughtError
    58 
    59                 sh 'cat *.log'
    60         }
    61 
    62         finally {
    63                 /* Must re-throw exception to propagate error */
    64                 if (err) {
    65                         throw err
    66                 }
    67         }
    68 }
    69 
    70 def doc_build() {
    71         stage 'Documentation'
    72 
    73                 status_prefix = 'Documentation'
    74 
    75                 dir ('doc/user') {
    76                         make_doc()
    77                 }
    78 
    79                 dir ('doc/refrat') {
    80                         make_doc()
    81                 }
    82 }
    83 
    84 def benchmark() {
    85         stage 'Benchmark'
    86 
    87                 status_prefix = 'Documentation'
    88 
    89                 // //We can't just write to a file outside our repo
    90                 // //Copy the file locally using ssh
    91                 // sh 'scp plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv bench.csv'
    92 
    93                 // //Then append to the local file
    94                 // sh 'make -C src/benchmark csv-data >> bench.csv'
    95 
    96                 // //Then publish the file again
    97                 // sh 'scp bench.csv plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv'         
    98 }
    99 
    100 //===========================================================================================================
    101 // Helper classes/variables/routines to make the status and stage name easier to use
    102 //===========================================================================================================
    103 //Description of a compiler (Must be serializable since pipelines are persistent)
    104 class CC_Desc implements Serializable {
    105         public String cc_name
    106         public String cpp_cc
    107         public String cfa_backend_cc
    108 
    109         CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) {
    110                 this.cc_name = cc_name
    111                 this.cpp_cc = cpp_cc
    112                 this.cfa_backend_cc = cfa_backend_cc
    113         }
    114 }
    115 
    116 //Global Variables defining the compiler and at which point in the build we are
    117 // These variables are used but can't be declared before hand because of wierd scripting rules
    118 // @Field String currentCC
    119 // @Field String status_prefix
    120 
    121 //Wrapper to sync stage name and status name
    122 def build_stage(String name) {
    123         def stage_name = "${currentCC.cc_name} ${name}".trim()
    124         stage stage_name
    125 
    126                 status_prefix = stage_name
    127 }
    128 
    129 //Helper routine to collect information about the git history
    130 def collect_git_info() {
    131 
    132         //create the temporary output directory in case it doesn't already exist
    133         def out_dir = pwd tmp: true
    134         sh "mkdir -p ${out_dir}"
    135 
    136         //parse git logs to find what changed
    137         gitRefName = env.BRANCH_NAME
    138         dir("../${gitRefName}@script") {
    139                 sh "git reflog > ${out_dir}/GIT_COMMIT"
    140         }
    141         git_reflog = readFile("${out_dir}/GIT_COMMIT")
    142         gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
    143         gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
    144 }
    145 
    146 //===========================================================================================================
    1474// Main loop of the compilation
    1485//===========================================================================================================
    1496node ('master'){
    1507
    151         boolean bIsFullBuild
     8        boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
    1529        def err = null
    15310        def log_needed = false
     11
     12        compiler                = null
     13        architecture    = ''
     14       
     15        do_alltests             = false
     16        do_benchmark    = false
     17        do_doc          = false
     18        do_publish              = false
     19        do_sendemail    = true
     20
    15421        currentBuild.result = "SUCCESS"
    155         status_prefix = ''
    15622
    15723        try {
    158                 //Prevent the build from exceeding 30 minutes
    159                 timeout(60) {
    160 
    161                         //Wrap build to add timestamp to command line
    162                         wrap([$class: 'TimestamperBuildWrapper']) {
    163 
    164                                 collect_git_info()
    165 
    166                                 properties ([                                                                   \
    167                                         [$class: 'ParametersDefinitionProperty',                                \
    168                                                 parameterDefinitions: [                                         \
    169                                                 [$class: 'BooleanParameterDefinition',                          \
    170                                                   defaultValue: false,                                          \
    171                                                   description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
    172                                                   name: 'isFullBuild'                                   \
    173                                                 ],                                                              \
    174                                                 [$class: 'ChoiceParameterDefinition',                           \
    175                                                   choices: '64-bit\n32-bit',                                    \
    176                                                   defaultValue: '64-bit',                                       \
    177                                                   description: 'The architecture to use for compilation',       \
    178                                                   name: 'buildArchitecture'                                     \
    179                                                 ]]                                                              \
    180                                         ]])
    181 
    182                                 bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
    183                                 bIsFullBuild = isFullBuild == 'true'
    184                                 architectureFlag = ''
    185                                 if (buildArchitecture == '64-bit') {
    186                                         architectureFlag = '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
    187                                 } else if (buildArchitecture == '32-bit'){
    188                                         architectureFlag = '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
    189                                 } else {
    190                                         architectureFlag = 'ERROR'
    191                                 }
    192 
    193                                 echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
    194 
    195                                 //Compile using gcc-4.9
    196                                 currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
    197                                 cfa_build(bIsFullBuild, architectureFlag)
    198 
    199                                 //Compile latex documentation
    200                                 doc_build()
    201 
    202                                 //Run benchmark and save result
     24                //Wrap build to add timestamp to command line
     25                wrap([$class: 'TimestamperBuildWrapper']) {
     26
     27                        //Prevent the build from exceeding 60 minutes
     28                        timeout(60) {
     29
     30                                notify_server()
     31
     32                                prepare_build()
     33
     34                                checkout()
     35
     36                                build()
     37
     38                                test()
     39
    20340                                benchmark()
    20441
    205                                 if( bIsFullBuild ) {
    206                                         //Compile using gcc-5
    207                                         currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
    208                                         cfa_build(true, architectureFlag)
    209 
    210                                         //Compile using gcc-4.9
    211                                         currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
    212                                         cfa_build(true, architectureFlag)
    213                                 }
     42                                clean()
     43
     44                                build_doc()
     45
     46                                publish()
     47
     48                                notify_server()
    21449                        }
    21550                }
     
    23368
    23469                //Send email with final results if this is not a full build
    235                 if( !bIsFullBuild && !bIsSandbox ) {
     70                if( !do_sendemail && !bIsSandbox ) {
    23671                        echo 'Notifying users of result'
    23772                        email(currentBuild.result, log_needed)
     
    24378                }
    24479        }
     80}
     81
     82//===========================================================================================================
     83// Helper classes/variables/routines
     84//===========================================================================================================
     85//Helper routine to collect information about the git history
     86def collect_git_info() {
     87
     88        //create the temporary output directory in case it doesn't already exist
     89        def out_dir = pwd tmp: true
     90        sh "mkdir -p ${out_dir}"
     91
     92        //parse git logs to find what changed
     93        gitRefName = env.BRANCH_NAME
     94        dir("../${gitRefName}@script") {
     95                sh "git reflog > ${out_dir}/GIT_COMMIT"
     96        }
     97        git_reflog = readFile("${out_dir}/GIT_COMMIT")
     98        gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
     99        gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
     100}
     101
     102def prepare_build() {
     103        properties ([                                                                                                   \
     104                [$class: 'ParametersDefinitionProperty',                                                                \
     105                        parameterDefinitions: [                                                                         \
     106                                [$class: 'ChoiceParameterDefinition',                                           \
     107                                        description: 'Which compiler to use',                                   \
     108                                        name: 'pCompiler',                                                              \
     109                                        choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang',                                        \
     110                                        defaultValue: 'gcc-6',                                                          \
     111                                ],                                                                                              \
     112                                [$class: 'ChoiceParameterDefinition',                                           \
     113                                        description: 'The target architecture',                                 \
     114                                        name: 'pArchitecture',                                                          \
     115                                        choices: 'x64\nx86',                                                            \
     116                                        defaultValue: 'x64',                                                            \
     117                                ],                                                                                              \
     118                                [$class: 'BooleanParameterDefinition',                                                  \
     119                                        description: 'If false, only the quick test suite is ran',              \
     120                                        name: 'pRunAllTests',                                                           \
     121                                        defaultValue: false,                                                            \
     122                                ],                                                                                              \
     123                                [$class: 'BooleanParameterDefinition',                                                  \
     124                                        description: 'If true, jenkins also runs benchmarks',           \
     125                                        name: 'pRunBenchmark',                                                          \
     126                                        defaultValue: true,                                                             \
     127                                ],                                                                                              \
     128                                [$class: 'BooleanParameterDefinition',                                                  \
     129                                        description: 'If true, jenkins also builds documentation',              \
     130                                        name: 'pBuildDocumentation',                                                            \
     131                                        defaultValue: true,                                                             \
     132                                ],                                                                                              \
     133                                [$class: 'BooleanParameterDefinition',                                                  \
     134                                        description: 'If true, jenkins also publishes results',                 \
     135                                        name: 'pPublish',                                                               \
     136                                        defaultValue: true,                                                             \
     137                                ],                                                                                              \
     138                                [$class: 'BooleanParameterDefinition',                                                  \
     139                                        description: 'If true, jenkins will not send emails',           \
     140                                        name: 'pSilent',                                                \
     141                                        defaultValue: false,                                                            \
     142                                ],                                                                                              \
     143                        ],
     144                ]])
     145
     146        compiler                = compiler_from_params( pCompiler )
     147        architecture    = architecture_from_params( pArchitecture )
     148
     149        do_alltests             = (pRunAllTests == 'true')
     150        do_benchmark    = (pRunBenchmark == 'true')
     151        do_doc          = (pBuildDocumentation == 'true')
     152        do_publish              = (pPublish == 'true')
     153        do_sendemail    = ! (pSilent == 'true')
     154
     155        echo """Compiler                : ${compiler.cc_name} (${compiler.cpp_cc}/${compiler.cfa_cc})
     156Architecture            : ${architecture}
     157Run All Tests           : ${ pRunAllTests.toString() }
     158Run Benchmark           : ${ pRunBenchmark.toString() }
     159Build Documentation     : ${ pBuildDocumentation.toString() }
     160Publish         : ${ pPublish.toString() }
     161Silent                  : ${ pSilent.toString() }
     162"""
     163
     164        collect_git_info()
     165}
     166
     167def notify_server() {
     168        sh 'curl --silent -X POST http://plg2:8082/jenkins/notify > /dev/null'
     169        return
     170}
     171
     172def make_doc() {
     173        def err = null
     174        try {
     175                sh 'make clean > /dev/null'
     176                sh 'make > /dev/null 2>&1'
     177        }
     178        catch (Exception caughtError) {
     179                err = caughtError //rethrow error later
     180                sh 'cat *.log'
     181        }
     182        finally {
     183                if (err) throw err // Must re-throw exception to propagate error
     184        }
     185}
     186
     187//Description of a compiler (Must be serializable since pipelines are persistent)
     188class CC_Desc implements Serializable {
     189        public String cc_name
     190        public String cpp_cc
     191        public String cfa_cc
     192
     193        CC_Desc(String cc_name, String cpp_cc, String cfa_cc) {
     194                this.cc_name = cc_name
     195                this.cpp_cc = cpp_cc
     196                this.cfa_cc = cfa_cc
     197        }
     198}
     199
     200def compiler_from_params(cc) {
     201        switch( cc ) {
     202                case 'gcc-6':
     203                        return new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
     204                break
     205                case 'gcc-5':
     206                        return new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
     207                break
     208                case 'gcc-4.9':
     209                        return new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
     210                break
     211                case 'clang':
     212                        return new CC_Desc('clang', 'clang++', 'gcc-6')
     213                break
     214                default :
     215                        error "Unhandled compiler : ${cc}"
     216        }
     217}
     218
     219def architecture_from_params( arch ) {
     220        switch( arch ) {
     221                case 'x64':
     222                        return '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
     223                break
     224                case 'x86':
     225                        return '--host=i386   CXXFLAGS="-m32" CFAFLAGS="-m32"'
     226                break
     227                default :
     228                        error "Unhandled architecture : ${arch}"
     229        }
     230}
     231
     232//===========================================================================================================
     233// Main compilation routines
     234//===========================================================================================================
     235//Compilation script is done here but environnement set-up and error handling is done in main loop
     236def checkout() {
     237        stage 'Checkout'
     238                //checkout the source code and clean the repo
     239                checkout scm
     240
     241                //Clean all temporary files to make sure no artifacts of the previous build remain
     242                sh 'git clean -fdqx'
     243
     244                //Reset the git repo so no local changes persist
     245                sh 'git reset --hard'
     246}
     247
     248def build() {
     249        stage 'Build'
     250       
     251                def install_dir = pwd tmp: true
     252               
     253                //Configure the conpilation (Output is not relevant)
     254                //Use the current directory as the installation target so nothing
     255                //escapes the sandbox
     256                //Also specify the compiler by hand
     257                sh "./configure CXX=${compiler.cpp_cc} ${architecture} --with-backend-compiler=${compiler.cfa_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
     258
     259                //Compile the project
     260                sh 'make -j 8 --no-print-directory V=0 install'
     261}
     262
     263def test() {
     264        stage 'Test'
     265
     266                //Run the tests from the tests directory
     267                if ( do_alltests ) {
     268                        sh 'make -C src/tests all-tests debug=yes'
     269                        sh 'make -C src/tests all-tests debug=no'
     270                }
     271                else {
     272                        sh 'make -C src/tests'
     273                }
     274}
     275
     276def benchmark() {
     277        stage 'Benchmark'
     278
     279                if( !do_benchmark ) return
     280
     281                //Write the commit id to Benchmark
     282                writeFile  file: 'bench.csv', text:'data=' + gitRefNewValue + ','
     283 
     284                //Append bench results
     285                sh 'make -C src/benchmark --no-print-directory csv-data >> bench.csv'
     286}
     287
     288def clean() {
     289        stage 'Cleanup'
     290
     291                //do a maintainer-clean to make sure we need to remake from scratch
     292                sh 'make maintainer-clean > /dev/null'
     293}
     294
     295def build_doc() {
     296        stage 'Documentation'
     297
     298                if( !do_doc ) return
     299
     300                dir ('doc/user') {
     301                        make_doc()
     302                }
     303
     304                dir ('doc/refrat') {
     305                        make_doc()
     306                }
     307}
     308
     309def publish() {
     310        stage 'Publish'
     311
     312                if( !do_publish ) return
     313
     314                //Then publish the results
     315                sh 'curl --silent --data @bench.csv http://plg2:8082/jenkins/publish > /dev/null'
    245316}
    246317
Note: See TracChangeset for help on using the changeset viewer.