Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # This file is meant to be SOURCED only after setting $ci_root. $ci_root must be |
| 9 | # the absolute path to the root of the CI repository |
| 10 | # |
| 11 | # A convenient way to set ci_root from the calling script like this: |
| 12 | # ci_root="$(readlink -f "$(dirname "$0")/..")" |
| 13 | # |
| 14 | |
| 15 | # Accept root of CI location from $CI_ROOT or $ci_root, in that order |
| 16 | ci_root="${ci_root:-$CI_ROOT}" |
| 17 | ci_root="${ci_root:?}" |
| 18 | |
| 19 | # Storage area to host toolchains, rootfs, tools, models, binaries, etc... |
| 20 | nfs_volume="${nfs_volume:-$NFS_VOLUME}" |
| 21 | nfs_volume="${nfs_volume:?}" |
| 22 | |
| 23 | # Override workspace for local runs |
| 24 | workspace="${workspace:-$WORKSPACE}" |
| 25 | workspace="${workspace:?}" |
| 26 | workspace="$(readlink -f "$workspace")" |
| 27 | artefacts="$workspace/artefacts" |
| 28 | |
| 29 | # pushd and popd outputs the directory stack every time, which could be |
| 30 | # confusing when shown on the log. Suppress its output. |
| 31 | pushd() { |
| 32 | builtin pushd "$1" &>/dev/null |
| 33 | } |
| 34 | popd() { |
| 35 | builtin popd &>/dev/null |
| 36 | } |
| 37 | |
| 38 | # Copy a file to the $archive directory |
| 39 | archive_file() { |
| 40 | local f out target md5 |
| 41 | f="${1:?}" |
| 42 | |
| 43 | out="${archive:?}" |
| 44 | [ ! -d "$out" ] && die "$out is not a directory" |
| 45 | |
| 46 | target="$out/$(basename $f)" |
| 47 | if [ -f "$target" ]; then |
| 48 | # Prevent same file error |
| 49 | if [ "$(stat --format=%i "$target")" = \ |
| 50 | "$(stat --format=%i "$f")" ]; then |
| 51 | return |
| 52 | fi |
| 53 | fi |
| 54 | |
| 55 | md5="$(md5sum "$f" | awk '{print $1}')" |
| 56 | cp -t "$out" "$f" |
| 57 | echo "Archived: $f (md5: $md5)" |
| 58 | } |
| 59 | |
| 60 | die() { |
| 61 | [ "$1" ] && echo "$1" >&2 |
| 62 | exit 1 |
| 63 | } |
| 64 | |
| 65 | # Emit environment variables for the purpose of sourcing from shells and as |
| 66 | # Jenkins property files. Whether the RHS is quoted depends on "$quote". |
| 67 | emit_env() { |
| 68 | local env_file="${env_file:?}" |
| 69 | local var="${1:?}" |
| 70 | |
| 71 | # Value parameter is mandatory, but allow for it to be empty |
| 72 | local val="${2?}" |
| 73 | |
| 74 | if upon "$quote"; then |
| 75 | val="\"$val\"" |
| 76 | else |
| 77 | # If RHS is not required to be quoted, any white space in it |
| 78 | # won't go well with a shell sourcing this file. |
| 79 | if echo "$var" | grep -q '\s'; then |
| 80 | die "$var: value '$val' has white space" |
| 81 | fi |
| 82 | fi |
| 83 | |
| 84 | echo "$var=$val" >> "$env_file" |
| 85 | } |
| 86 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 87 | fetch_directory() { |
| 88 | local base="$(basename "${url:?}")" |
| 89 | local sa |
| 90 | |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 91 | case "${url}" in |
| 92 | http*://*) |
| 93 | # Have exactly one trailing / |
| 94 | local modified_url="$(echo "${url}" | sed 's#/*$##')/" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 95 | |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 96 | # Figure out the number of components between hostname and the |
| 97 | # final one |
| 98 | local cut_dirs="$(echo "$modified_url" | awk -F/ '{print NF - 5}')" |
| 99 | sa="${saveas:-$base}" |
| 100 | echo "Fetch: $modified_url -> $sa" |
| 101 | wget -rq -nH --cut-dirs="$cut_dirs" --no-parent \ |
| 102 | --reject="index.html*" "$modified_url" |
| 103 | if [ "$sa" != "$base" ]; then |
| 104 | mv "$base" "$sa" |
| 105 | fi |
| 106 | ;; |
| 107 | file://*) |
| 108 | sa="${saveas:-.}" |
| 109 | echo "Fetch: ${url} -> $sa" |
| 110 | cp -r "${url#file://}" "$sa" |
| 111 | ;; |
| 112 | *) |
| 113 | sa="${saveas:-.}" |
| 114 | echo "Fetch: ${url} -> $sa" |
| 115 | cp -r "${url}" "$sa" |
| 116 | ;; |
| 117 | esac |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | fetch_file() { |
| 121 | local url="${url:?}" |
| 122 | local sa |
| 123 | local saveas |
| 124 | |
| 125 | if is_url "$url"; then |
| 126 | sa="${saveas+-o $saveas}" |
| 127 | saveas="${saveas-"$(basename "$url")"}" |
| 128 | echo "Fetch: $url -> $saveas" |
| 129 | # Use curl to support file protocol |
| 130 | curl -sLS -C - $sa "$url" |
| 131 | else |
| 132 | sa="${saveas-.}" |
| 133 | echo "Fetch: $url -> $sa" |
| 134 | cp "$url" "$sa" |
| 135 | fi |
| 136 | } |
| 137 | |
| 138 | # Make a temporary directory/file insdie workspace, so that it doesn't need to |
| 139 | # be cleaned up. Jenkins is setup to clean up workspace before a job runs. |
| 140 | mktempdir() { |
| 141 | local ws="${workspace:?}" |
| 142 | |
| 143 | mktemp -d --tmpdir="$ws" |
| 144 | } |
| 145 | mktempfile() { |
| 146 | local ws="${workspace:?}" |
| 147 | |
| 148 | mktemp --tmpdir="$ws" |
| 149 | } |
| 150 | |
| 151 | not_upon() { |
| 152 | ! upon "$1" |
| 153 | } |
| 154 | |
| 155 | # Use "$1" as a boolean |
| 156 | upon() { |
| 157 | case "$1" in |
| 158 | "" | "0" | "false") return 1;; |
| 159 | *) return 0;; |
| 160 | esac |
| 161 | } |
| 162 | |
| 163 | # Check if the argument is a URL |
| 164 | is_url() { |
| 165 | echo "$1" | grep -q "://" |
| 166 | } |
| 167 | |
| 168 | # Check if a path is absolute |
| 169 | is_abs() { |
| 170 | [ "${1:0:1}" = "/" ] |
| 171 | } |
| 172 | |
| 173 | # Unset a variable based on its boolean value |
| 174 | # If foo=, foo will be unset |
| 175 | # If foo=blah, then leave it as is |
| 176 | reset_var() { |
| 177 | local var="$1" |
| 178 | local val="${!var}" |
| 179 | |
| 180 | if [ -z "$val" ]; then |
| 181 | unset "$var" |
| 182 | else |
| 183 | var="$val" |
| 184 | fi |
| 185 | } |
| 186 | |
| 187 | default_var() { |
| 188 | local var="$1" |
| 189 | local val="${!var}" |
| 190 | local default="$2" |
| 191 | |
| 192 | if [ -z "$val" ]; then |
| 193 | eval "$var=$default" |
| 194 | fi |
| 195 | } |
| 196 | |
| 197 | # String various items joined by ":" to form a path. Items are prepended by |
| 198 | # default; or 'op' can be set to 'append' to have them appended. |
| 199 | # For example, to set: PATH=foo:bar:baz:$PATH |
| 200 | extend_path() { |
| 201 | local path_var="$1" |
| 202 | local array_var="$2" |
| 203 | local tmp_path="${!path_var}" |
| 204 | local tmp_array |
| 205 | local item |
| 206 | local op="${op:-prepend}" |
| 207 | |
| 208 | eval "tmp_array=\"\${$array_var[@]}\"" |
| 209 | for item in $tmp_array; do |
| 210 | if [ "$op" = "prepend" ]; then |
| 211 | tmp_path="$item${tmp_path+:}$tmp_path" |
| 212 | elif [ "$op" = "append" ]; then |
| 213 | tmp_path="$tmp_path${tmp_path+:}$item" |
| 214 | fi |
| 215 | done |
| 216 | eval "$path_var=\"$tmp_path\"" |
| 217 | } |
| 218 | |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 219 | # Extract files from compressed archive to target directory. Supports .zip and |
| 220 | # .tar.gz format |
| 221 | extract_tarball() { |
| 222 | local archive="$1" |
| 223 | local target_dir="$2" |
| 224 | |
| 225 | pushd "$target_dir" |
| 226 | case $(file --mime-type -b "$archive") in |
| 227 | application/gzip) |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 228 | tar -xzf $archive |
| 229 | ;; |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 230 | application/zip) |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 231 | unzip -q $archive |
| 232 | ;; |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 233 | esac |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 234 | popd "$target_dir" |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 235 | } |
| 236 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 237 | # Assume running on Jenkins if JENKINS_HOME is set |
| 238 | if [ "$JENKINS_HOME" ]; then |
| 239 | jenkins_run=1 |
| 240 | umask 0002 |
| 241 | else |
| 242 | unset jenkins_run |
| 243 | fi |
| 244 | |
| 245 | # Project scratch location for Trusted Firmware CI |
| 246 | project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw" |
| 247 | project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}" |
| 248 | warehouse="${nfs_volume}/warehouse" |
| 249 | jenkins_url="${JENKINS_URL%/*}" |
| 250 | jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}" |
| 251 | |
| 252 | # Model revisions |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 253 | model_version="${model_version:-11.9}" |
| 254 | model_build="${model_build:-41}" |
| 255 | model_flavour="${model_flavour:-Linux64_GCC-6.4}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 256 | |
| 257 | # Model snapshots from filer are not normally not accessible from developer |
| 258 | # systems. Ignore failures from picking real path for local runs. |
| 259 | pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true |
| 260 | pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true |
| 261 | |
| 262 | #arm_gerrit_url="gerrit.oss.arm.com" |
| 263 | tforg_gerrit_url="review.trustedfirmware.org" |
| 264 | |
| 265 | # Repository URLs. We're using anonymous HTTP as they appear to be faster rather |
| 266 | # than any scheme with authentication. |
| 267 | #tf_ci_repo_url="http://$arm_gerrit_url/pdswinf/ci/pdcs-platforms/platform-ci" |
| 268 | tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}" |
| 269 | tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}" |
| 270 | #tf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/pdcs-platforms/ap/tf-topics.git" |
| 271 | tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}" |
| 272 | tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}" |
| 273 | #tftf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/trusted-firmware/tf-a-tests.git" |
| 274 | scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 275 | #cc_src_repo_url="${cc_src_repo_url:-https://$arm_gerrit_url/tests/lava/test-definitions.git}" |
| 276 | #cc_src_repo_tag="${cc_src_repo_tag:-kernel-team-workflow_2019-09-20}" |
| 277 | |
| 278 | #scp_tools_src_repo_url="${scp_tools_src_repo_url:-http://$arm_gerrit_url/scp/tools-non-public}" |
| 279 | #tf_for_scp_tools_src_repo_url="https://gerrit.oss.arm.com/scp/test-framework" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 280 | |
| 281 | # FIXME set a sane default for tfa_downloads |
| 282 | tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}" |
| 283 | css_downloads="${css_downloads:-$tfa_downloads/css}" |
| 284 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 285 | linaro_1906_release="$tfa_downloads/linaro/19.06" |
| 286 | linaro_release="${linaro_release:-$linaro_1906_release}" |
| 287 | |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 288 | # mbedTLS archive public hosting available at github.com |
| 289 | mbedtls_archive="${mbedtls_archive:-https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.18.0.zip}" |
| 290 | # The tar file contains mbedtls-mbedtls-2.18.0 repo which holds the necessary |
| 291 | # source files of mbedTLS project |
| 292 | mbedtls_repo_name="${mbedtls_repo_name:-mbedtls-mbedtls-2.18.0}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 293 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 294 | coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2019.09}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 295 | #coverity_host="${coverity_host:-coverity.cambridge.arm.com}" |
| 296 | coverity_default_checkers=( |
| 297 | "--all" |
| 298 | "--checker-option DEADCODE:no_dead_default:true" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 299 | "--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 300 | "--enable ENUM_AS_BOOLEAN" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 301 | "--enable-constraint-fpp" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 302 | "--ticker-mode none" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 303 | "--hfa" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 304 | ) |
| 305 | |
| 306 | #export coverity_host |
| 307 | |
| 308 | path_list=( |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 309 | #Need to upgrade gcc to the following version |
| 310 | #"/arm/pdsw/tools/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin" |
| 311 | #"/arm/pdsw/tools/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 312 | "${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin" |
| 313 | "${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin" |
| 314 | "${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin" |
| 315 | "$coverity_path/bin" |
| 316 | ) |
| 317 | |
| 318 | ld_library_path_list=( |
| 319 | ) |
| 320 | |
| 321 | license_path_list=( |
| 322 | ) |
| 323 | |
| 324 | # Setup various paths |
| 325 | if upon "$retain_paths"; then |
| 326 | # If explicitly requested, retain local paths; apppend CI paths to the |
| 327 | # existing ones. |
| 328 | op="append" extend_path "PATH" "path_list" |
| 329 | op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 330 | op="append" extend_path "LM_LICENSE_FILE" "license_path_list" |
| 331 | else |
| 332 | # Otherwise, prepend CI paths so that they take effect before local ones |
| 333 | extend_path "PATH" "path_list" |
| 334 | extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 335 | extend_path "LM_LICENSE_FILE" "license_path_list" |
| 336 | fi |
| 337 | |
| 338 | export LD_LIBRARY_PATH |
| 339 | export LM_LICENSE_FILE |
| 340 | export ARMLMD_LICENSE_FILE="$LM_LICENSE_FILE" |
| 341 | export ARM_TOOL_VARIANT=ult |
| 342 | |
| 343 | # vim: set tw=80 sw=8 noet: |