Harrison Mutai | 7f8cbb9 | 2025-04-02 14:36:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | pipeline { |
| 8 | agent { |
| 9 | label 'docker-amd64-tf-a-jammy' |
| 10 | } |
| 11 | |
| 12 | parameters { |
| 13 | string(name: 'REPO_URL', |
| 14 | defaultValue: 'https://review.trustedfirmware.org/shared/transfer-list-library', |
| 15 | description: 'Git repository URL.') |
| 16 | |
| 17 | string( |
| 18 | name: 'REPO_REFSPEC', |
| 19 | defaultValue: '+refs/heads/main:refs/remotes/origin/main', |
| 20 | description: 'Refspec to fetch from the repository.' |
| 21 | ) |
| 22 | |
| 23 | string( |
| 24 | name: 'REPO_REFNAME', |
| 25 | defaultValue: 'origin/main', |
| 26 | description: 'Branch or reference to check out.' |
| 27 | ) |
| 28 | |
| 29 | string(name: 'BASE_REF', |
| 30 | defaultValue: 'origin/main', |
| 31 | description: 'Git base reference for formatting comparison.') |
| 32 | |
| 33 | } |
| 34 | |
| 35 | stages { |
| 36 | stage('Checkout') { |
| 37 | steps { |
| 38 | script { |
| 39 | def refspec = params.GERRIT_REFSPEC ?: params.REPO_REFSPEC |
| 40 | def refname = params.GERRIT_PATCHSET_REVISION ?: params.REPO_REFNAME |
| 41 | |
| 42 | checkout([ |
| 43 | $class: 'GitSCM', |
| 44 | branches: [[ name: refname ]], |
| 45 | userRemoteConfigs: [ |
| 46 | [ url: params.REPO_URL, refspec: refspec] |
| 47 | ] |
| 48 | ]) |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | stage('Code style') { |
| 54 | steps { |
| 55 | script { |
| 56 | sh "git-clang-format ${params.BASE_REF} HEAD --diff -q | tee formatted.patch" |
| 57 | sh "[ -s formatted.patch ] || rm formatted.patch" |
| 58 | |
| 59 | if (fileExists('formatted.patch')) { |
| 60 | archiveArtifacts artifacts: "formatted.patch", fingerprint: true |
| 61 | error("Code style check failed. See 'formatted.patch' for suggested changes.") |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | stage('Build') { |
| 68 | matrix { |
| 69 | axes { |
| 70 | axis { |
| 71 | name 'COMPILER' |
| 72 | values 'aarch64-clang', 'aarch64-gcc', 'aarch32-clang', 'aarch32-gcc', 'clang', 'gcc' |
| 73 | } |
| 74 | axis { |
| 75 | name 'BUILD_TYPE' |
| 76 | values 'Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel' |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | stages { |
| 81 | stage('Compile') { |
| 82 | steps { |
| 83 | script { |
| 84 | def toolchains = [ |
| 85 | 'gcc': [ |
| 86 | cc: 'gcc', |
| 87 | cmakeArgs: [], |
| 88 | ], |
| 89 | |
| 90 | 'clang': [ |
| 91 | cc: 'clang', |
| 92 | cmakeArgs: [], |
| 93 | ], |
| 94 | |
| 95 | 'aarch32-gcc': [ |
| 96 | cc: 'arm-none-eabi-gcc', |
| 97 | cmakeArgs: ['-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY'], |
| 98 | ], |
| 99 | |
| 100 | 'aarch64-gcc': [ |
| 101 | cc: 'aarch64-none-elf-gcc', |
| 102 | cmakeArgs: ['-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY'], |
| 103 | ], |
| 104 | |
| 105 | 'aarch32-clang': [ |
| 106 | cc: 'clang', |
| 107 | clangTarget: 'arm-none-eabi', |
| 108 | cmakeArgs: ['-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY'], |
| 109 | ], |
| 110 | |
| 111 | 'aarch64-clang': [ |
| 112 | cc: 'clang', |
| 113 | clangTarget: 'aarch64-none-elf', |
| 114 | cmakeArgs: ['-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY'], |
| 115 | ], |
| 116 | ] |
| 117 | |
| 118 | def buildDir = "build/${COMPILER}/${BUILD_TYPE}" |
| 119 | def cmakeArgs = toolchains[COMPILER].cmakeArgs |
| 120 | |
| 121 | cmakeArgs << "-DCMAKE_C_COMPILER=${toolchains[COMPILER].cc}" |
| 122 | |
| 123 | if (toolchains[COMPILER].clangTarget) { |
| 124 | def sysroot = sh( |
| 125 | script: "${toolchains[COMPILER].clangTarget}-gcc -print-sysroot", |
| 126 | returnStdout: true |
| 127 | ).trim() |
| 128 | |
| 129 | cmakeArgs << "-DCMAKE_C_COMPILER_TARGET=${toolchains[COMPILER].clangTarget}" |
| 130 | cmakeArgs << "-DCMAKE_SYSROOT=${sysroot}" |
| 131 | } |
| 132 | |
| 133 | sh """ |
| 134 | cmake -B ${buildDir} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${cmakeArgs.join(' ')} |
| 135 | cmake --build ${buildDir} |
| 136 | """ |
| 137 | |
| 138 | archiveArtifacts artifacts: "${buildDir}/**", fingerprint: true |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | stage('Test') { |
| 147 | steps { |
| 148 | script { |
| 149 | def testDir = "build/test" |
| 150 | |
| 151 | sh """ |
| 152 | cmake -B ${testDir} -DTARGET_GROUP=test |
| 153 | cmake --build ${testDir} |
| 154 | cmake --build ${testDir} -- test |
| 155 | """ |
| 156 | |
| 157 | archiveArtifacts artifacts: "${testDir}/**", fingerprint: true |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |