Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 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 | |
| 87 | # # FIXME add support for file:// protocol |
| 88 | fetch_directory() { |
| 89 | local base="$(basename "${url:?}")" |
| 90 | local sa |
| 91 | |
| 92 | if is_url "$url"; then |
| 93 | # Have exactly one trailing / |
| 94 | local modified_url="$(echo "$url" | sed 's#/*$##')/" |
| 95 | |
| 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 | else |
| 107 | sa="${saveas:-.}" |
| 108 | echo "Fetch: $url -> $sa" |
| 109 | cp -r "$url" "$sa" |
| 110 | fi |
| 111 | } |
| 112 | |
| 113 | fetch_file() { |
| 114 | local url="${url:?}" |
| 115 | local sa |
| 116 | local saveas |
| 117 | |
| 118 | if is_url "$url"; then |
| 119 | sa="${saveas+-o $saveas}" |
| 120 | saveas="${saveas-"$(basename "$url")"}" |
| 121 | echo "Fetch: $url -> $saveas" |
| 122 | # Use curl to support file protocol |
| 123 | curl -sLS -C - $sa "$url" |
| 124 | else |
| 125 | sa="${saveas-.}" |
| 126 | echo "Fetch: $url -> $sa" |
| 127 | cp "$url" "$sa" |
| 128 | fi |
| 129 | } |
| 130 | |
| 131 | # Make a temporary directory/file insdie workspace, so that it doesn't need to |
| 132 | # be cleaned up. Jenkins is setup to clean up workspace before a job runs. |
| 133 | mktempdir() { |
| 134 | local ws="${workspace:?}" |
| 135 | |
| 136 | mktemp -d --tmpdir="$ws" |
| 137 | } |
| 138 | mktempfile() { |
| 139 | local ws="${workspace:?}" |
| 140 | |
| 141 | mktemp --tmpdir="$ws" |
| 142 | } |
| 143 | |
| 144 | not_upon() { |
| 145 | ! upon "$1" |
| 146 | } |
| 147 | |
| 148 | # Use "$1" as a boolean |
| 149 | upon() { |
| 150 | case "$1" in |
| 151 | "" | "0" | "false") return 1;; |
| 152 | *) return 0;; |
| 153 | esac |
| 154 | } |
| 155 | |
| 156 | # Check if the argument is a URL |
| 157 | is_url() { |
| 158 | echo "$1" | grep -q "://" |
| 159 | } |
| 160 | |
| 161 | # Check if a path is absolute |
| 162 | is_abs() { |
| 163 | [ "${1:0:1}" = "/" ] |
| 164 | } |
| 165 | |
| 166 | # Unset a variable based on its boolean value |
| 167 | # If foo=, foo will be unset |
| 168 | # If foo=blah, then leave it as is |
| 169 | reset_var() { |
| 170 | local var="$1" |
| 171 | local val="${!var}" |
| 172 | |
| 173 | if [ -z "$val" ]; then |
| 174 | unset "$var" |
| 175 | else |
| 176 | var="$val" |
| 177 | fi |
| 178 | } |
| 179 | |
| 180 | default_var() { |
| 181 | local var="$1" |
| 182 | local val="${!var}" |
| 183 | local default="$2" |
| 184 | |
| 185 | if [ -z "$val" ]; then |
| 186 | eval "$var=$default" |
| 187 | fi |
| 188 | } |
| 189 | |
| 190 | # String various items joined by ":" to form a path. Items are prepended by |
| 191 | # default; or 'op' can be set to 'append' to have them appended. |
| 192 | # For example, to set: PATH=foo:bar:baz:$PATH |
| 193 | extend_path() { |
| 194 | local path_var="$1" |
| 195 | local array_var="$2" |
| 196 | local tmp_path="${!path_var}" |
| 197 | local tmp_array |
| 198 | local item |
| 199 | local op="${op:-prepend}" |
| 200 | |
| 201 | eval "tmp_array=\"\${$array_var[@]}\"" |
| 202 | for item in $tmp_array; do |
| 203 | if [ "$op" = "prepend" ]; then |
| 204 | tmp_path="$item${tmp_path+:}$tmp_path" |
| 205 | elif [ "$op" = "append" ]; then |
| 206 | tmp_path="$tmp_path${tmp_path+:}$item" |
| 207 | fi |
| 208 | done |
| 209 | eval "$path_var=\"$tmp_path\"" |
| 210 | } |
| 211 | |
| 212 | # Assume running on Jenkins if JENKINS_HOME is set |
| 213 | if [ "$JENKINS_HOME" ]; then |
| 214 | jenkins_run=1 |
| 215 | umask 0002 |
| 216 | else |
| 217 | unset jenkins_run |
| 218 | fi |
| 219 | |
| 220 | # Project scratch location for Trusted Firmware CI |
| 221 | project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw" |
| 222 | project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}" |
| 223 | warehouse="${nfs_volume}/warehouse" |
| 224 | jenkins_url="${JENKINS_URL%/*}" |
| 225 | jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}" |
| 226 | |
| 227 | # Model revisions |
| 228 | model_version="${model_version:-11.6}" |
| 229 | model_build="${model_build:-45}" |
| 230 | |
| 231 | # Model snapshots from filer are not normally not accessible from developer |
| 232 | # systems. Ignore failures from picking real path for local runs. |
| 233 | pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true |
| 234 | pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true |
| 235 | |
| 236 | #arm_gerrit_url="gerrit.oss.arm.com" |
| 237 | tforg_gerrit_url="review.trustedfirmware.org" |
| 238 | |
| 239 | # Repository URLs. We're using anonymous HTTP as they appear to be faster rather |
| 240 | # than any scheme with authentication. |
| 241 | #tf_ci_repo_url="http://$arm_gerrit_url/pdswinf/ci/pdcs-platforms/platform-ci" |
| 242 | tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}" |
| 243 | tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}" |
| 244 | #tf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/pdcs-platforms/ap/tf-topics.git" |
| 245 | tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}" |
| 246 | tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}" |
| 247 | #tftf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/trusted-firmware/tf-a-tests.git" |
| 248 | scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}" |
| 249 | #scp_src_repo_url="${scp_src_repo_url:-http://$arm_gerrit_url/scp/firmware}" |
| 250 | |
| 251 | # FIXME set a sane default for tfa_downloads |
| 252 | tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}" |
| 253 | css_downloads="${css_downloads:-$tfa_downloads/css}" |
| 254 | |
| 255 | # FIXME public hosting has mbedtls-2.16.0-apache.tgz or mbedtls-2.16.0-gpl.tgz" |
| 256 | # See https://tls.mbed.org/download/start/ |
| 257 | mbedtls_archive="${mbedtls_archive:-$tfa_downloads/mbedtls/mbedtls-2.16.0.tar.gz}" |
| 258 | linaro_release="${linaro_release:-$tfa_downloads/linaro/18.04}" |
| 259 | |
| 260 | coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2018.06}" |
| 261 | #coverity_host="${coverity_host:-coverity.cambridge.arm.com}" |
| 262 | coverity_default_checkers=( |
| 263 | "--all" |
| 264 | "--checker-option DEADCODE:no_dead_default:true" |
| 265 | "--concurrency" |
| 266 | "--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK" |
| 267 | "--enable-constraint-fpp" |
| 268 | "--security" |
| 269 | "--ticker-mode none" |
| 270 | ) |
| 271 | |
| 272 | #export coverity_host |
| 273 | |
| 274 | path_list=( |
| 275 | "${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin" |
| 276 | "${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin" |
| 277 | "${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin" |
| 278 | "$coverity_path/bin" |
| 279 | ) |
| 280 | |
| 281 | ld_library_path_list=( |
| 282 | ) |
| 283 | |
| 284 | license_path_list=( |
| 285 | ) |
| 286 | |
| 287 | # Setup various paths |
| 288 | if upon "$retain_paths"; then |
| 289 | # If explicitly requested, retain local paths; apppend CI paths to the |
| 290 | # existing ones. |
| 291 | op="append" extend_path "PATH" "path_list" |
| 292 | op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 293 | op="append" extend_path "LM_LICENSE_FILE" "license_path_list" |
| 294 | else |
| 295 | # Otherwise, prepend CI paths so that they take effect before local ones |
| 296 | extend_path "PATH" "path_list" |
| 297 | extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 298 | extend_path "LM_LICENSE_FILE" "license_path_list" |
| 299 | fi |
| 300 | |
| 301 | export LD_LIBRARY_PATH |
| 302 | export LM_LICENSE_FILE |
| 303 | export ARMLMD_LICENSE_FILE="$LM_LICENSE_FILE" |
| 304 | export ARM_TOOL_VARIANT=ult |
| 305 | |
| 306 | # vim: set tw=80 sw=8 noet: |