| [64bc131] | 1 | #!groovy | 
|---|
|  | 2 |  | 
|---|
|  | 3 | node ('master') { | 
|---|
|  | 4 |  | 
|---|
|  | 5 | user_email = '' | 
|---|
|  | 6 | test_list = '' | 
|---|
|  | 7 |  | 
|---|
|  | 8 | prepare_build() | 
|---|
|  | 9 |  | 
|---|
|  | 10 | try { | 
|---|
|  | 11 |  | 
|---|
| [ce34152] | 12 | stage('Checkout') { | 
|---|
|  | 13 | checkout scm | 
|---|
| [5d41e22] | 14 |  | 
|---|
|  | 15 | sh 'git clean -xdf' | 
|---|
|  | 16 |  | 
|---|
|  | 17 | sh 'git reset --hard' | 
|---|
| [ce34152] | 18 | } | 
|---|
| [64bc131] | 19 |  | 
|---|
| [ce34152] | 20 | stage('Building x86') { | 
|---|
|  | 21 | regen_tests('i386') | 
|---|
|  | 22 | } | 
|---|
| [64bc131] | 23 |  | 
|---|
| [ce34152] | 24 | stage('Building x64') { | 
|---|
|  | 25 | regen_tests('x86_64') | 
|---|
|  | 26 | } | 
|---|
| [64bc131] | 27 |  | 
|---|
| [ce34152] | 28 | stage('Patching') { | 
|---|
|  | 29 | make_patch() | 
|---|
|  | 30 | } | 
|---|
| [64bc131] | 31 |  | 
|---|
| [ce34152] | 32 | stage('Email') { | 
|---|
|  | 33 | email() | 
|---|
|  | 34 | } | 
|---|
| [64bc131] | 35 | } | 
|---|
|  | 36 | catch (Exception caughtError) { | 
|---|
|  | 37 | email_error() | 
|---|
| [c429ec2] | 38 |  | 
|---|
|  | 39 | throw caughtError | 
|---|
| [64bc131] | 40 | } | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | def prepare_build() { | 
|---|
|  | 44 | properties ([                                                                                                   \ | 
|---|
|  | 45 | [$class: 'ParametersDefinitionProperty',                                                                \ | 
|---|
|  | 46 | parameterDefinitions: [                                                                         \ | 
|---|
|  | 47 | [$class: 'StringParameterDefinition',                                           \ | 
|---|
|  | 48 | description: 'Who required the test',                                   \ | 
|---|
|  | 49 | name: 'pEmail',                                                                 \ | 
|---|
|  | 50 | ],                                                                                              \ | 
|---|
|  | 51 | [$class: 'StringParameterDefinition',                                           \ | 
|---|
|  | 52 | description: 'Space separated list of tests to run',                    \ | 
|---|
|  | 53 | name: 'pTests',                                                                 \ | 
|---|
|  | 54 | ],                                                                                              \ | 
|---|
|  | 55 | ], | 
|---|
|  | 56 | ]]) | 
|---|
|  | 57 |  | 
|---|
|  | 58 | user_email = pEmail; | 
|---|
|  | 59 | test_list  = pTests; | 
|---|
| [f5dfc86] | 60 |  | 
|---|
|  | 61 | echo "User ${user_email} requested regenerating tests : ${ test_list }" | 
|---|
| [64bc131] | 62 | } | 
|---|
|  | 63 |  | 
|---|
|  | 64 | def regen_tests( String arch ) { | 
|---|
|  | 65 |  | 
|---|
|  | 66 | def install_dir = pwd tmp: true | 
|---|
|  | 67 |  | 
|---|
|  | 68 | //Configure the conpilation (Output is not relevant) | 
|---|
|  | 69 | //Use the current directory as the installation target so nothing | 
|---|
|  | 70 | //escapes the sandbox | 
|---|
|  | 71 | //Also specify the compiler by hand | 
|---|
| [eb220ca] | 72 | sh "./configure CXX=clang++ --host=${arch} --with-backend-compiler=gcc-6 --prefix=${install_dir} --enable-silent-rules --quiet" | 
|---|
| [64bc131] | 73 |  | 
|---|
|  | 74 | //Compile the project | 
|---|
|  | 75 | sh 'make -j 8 --no-print-directory install' | 
|---|
|  | 76 |  | 
|---|
|  | 77 | //Regenerate the desired tests | 
|---|
|  | 78 | sh "src/tests/test.py --regenerate-expected ${test_list}" | 
|---|
| [c429ec2] | 79 |  | 
|---|
|  | 80 | //Clean everything from the last build | 
|---|
|  | 81 | sh 'make maintainer-clean > /dev/null' | 
|---|
| [64bc131] | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | def make_patch() { | 
|---|
|  | 85 |  | 
|---|
|  | 86 | def target_dir = pwd tmp: true | 
|---|
|  | 87 |  | 
|---|
|  | 88 | //Add every file so new files appear in the diff | 
|---|
|  | 89 | sh 'git add .' | 
|---|
|  | 90 |  | 
|---|
|  | 91 | //Create a patch file | 
|---|
|  | 92 | sh "git diff --cached --binary > ${target_dir}/result.patch" | 
|---|
|  | 93 | } | 
|---|
|  | 94 |  | 
|---|
|  | 95 | def email() { | 
|---|
|  | 96 |  | 
|---|
| [d0cf7409] | 97 | def target_dir = pwd tmp: true | 
|---|
|  | 98 |  | 
|---|
| [c344406] | 99 | dir( target_dir ) { | 
|---|
|  | 100 |  | 
|---|
|  | 101 | def email_subject = "[cforall dashboard][TEST REGEN# ${env.BUILD_NUMBER}] - Result" | 
|---|
|  | 102 | def email_body = """This is an automated email from the Jenkins build machine. It was | 
|---|
| [d8e14e39] | 103 | generated http://plg2:8082/dashboard. | 
|---|
|  | 104 |  | 
|---|
|  | 105 | Please apply the required changes using the following method : | 
|---|
|  | 106 | - copy result.patch to your cforall repository of choice. | 
|---|
|  | 107 | - call 'git apply [patch file name]' (WARNING: the changes may conflict with any current changes to the test expected results). | 
|---|
|  | 108 | - validate that the changes are correct. | 
|---|
|  | 109 | - commit the changes as usual.""" | 
|---|
| [64bc131] | 110 |  | 
|---|
| [c344406] | 111 | //send email notification | 
|---|
|  | 112 | emailext body: email_body, subject: email_subject, to: user_email, attachmentsPattern: "**/*.patch" | 
|---|
|  | 113 | } | 
|---|
| [64bc131] | 114 | } | 
|---|
|  | 115 |  | 
|---|
|  | 116 | def email_error() { | 
|---|
|  | 117 |  | 
|---|
|  | 118 | def email_subject = "[cforall dashboard][TEST REGEN# ${env.BUILD_NUMBER}] - FAILURE" | 
|---|
|  | 119 | def email_body = """This is an automated email from the Jenkins build machine. It was | 
|---|
|  | 120 | generated http://plg2:8082/dashboard. | 
|---|
|  | 121 |  | 
|---|
|  | 122 | Test generation encoutered an error please see attached logs | 
|---|
|  | 123 |  | 
|---|
|  | 124 | -----------------------------------------------------------------------""" | 
|---|
|  | 125 |  | 
|---|
|  | 126 | //send email notification | 
|---|
|  | 127 | emailext body: email_body, subject: email_subject, to: user_email, attachLog: true | 
|---|
|  | 128 | } | 
|---|