blob: 1bcaa3ae31bb2b159987128f2b094c55d41da08a [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#!/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
16ci_root="${ci_root:-$CI_ROOT}"
17ci_root="${ci_root:?}"
18
19# Storage area to host toolchains, rootfs, tools, models, binaries, etc...
20nfs_volume="${nfs_volume:-$NFS_VOLUME}"
21nfs_volume="${nfs_volume:?}"
22
23# Override workspace for local runs
24workspace="${workspace:-$WORKSPACE}"
25workspace="${workspace:?}"
26workspace="$(readlink -f "$workspace")"
27artefacts="$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.
31pushd() {
32 builtin pushd "$1" &>/dev/null
33}
34popd() {
35 builtin popd &>/dev/null
36}
37
38# Copy a file to the $archive directory
39archive_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
60die() {
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".
67emit_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 Boudra422bf772019-12-02 11:10:16 +020087fetch_directory() {
88 local base="$(basename "${url:?}")"
89 local sa
90
Fathi Boudradd31e7b2020-01-29 15:44:42 +020091 case "${url}" in
92 http*://*)
93 # Have exactly one trailing /
94 local modified_url="$(echo "${url}" | sed 's#/*$##')/"
Fathi Boudra422bf772019-12-02 11:10:16 +020095
Fathi Boudradd31e7b2020-01-29 15:44:42 +020096 # 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 Boudra422bf772019-12-02 11:10:16 +0200118}
119
120fetch_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.
140mktempdir() {
141 local ws="${workspace:?}"
142
143 mktemp -d --tmpdir="$ws"
144}
145mktempfile() {
146 local ws="${workspace:?}"
147
148 mktemp --tmpdir="$ws"
149}
150
151not_upon() {
152 ! upon "$1"
153}
154
155# Use "$1" as a boolean
156upon() {
157 case "$1" in
158 "" | "0" | "false") return 1;;
159 *) return 0;;
160 esac
161}
162
163# Check if the argument is a URL
164is_url() {
165 echo "$1" | grep -q "://"
166}
167
168# Check if a path is absolute
169is_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
176reset_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
187default_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
200extend_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 Pappireddy4b686cf2020-03-31 13:05:14 -0500219# Extract files from compressed archive to target directory. Supports .zip and
220# .tar.gz format
221extract_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)
228 tar -xzf $archive
229 ;;
230 application/zip)
231 unzip -q $archive
232 ;;
233 *)
234 die "Unsupported tarball format"
235 ;;
236 esac
237 popd
238}
239
Fathi Boudra422bf772019-12-02 11:10:16 +0200240# Assume running on Jenkins if JENKINS_HOME is set
241if [ "$JENKINS_HOME" ]; then
242 jenkins_run=1
243 umask 0002
244else
245 unset jenkins_run
246fi
247
248# Project scratch location for Trusted Firmware CI
249project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw"
250project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}"
251warehouse="${nfs_volume}/warehouse"
252jenkins_url="${JENKINS_URL%/*}"
253jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}"
254
255# Model revisions
256model_version="${model_version:-11.6}"
257model_build="${model_build:-45}"
258
259# Model snapshots from filer are not normally not accessible from developer
260# systems. Ignore failures from picking real path for local runs.
261pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true
262pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true
263
264#arm_gerrit_url="gerrit.oss.arm.com"
265tforg_gerrit_url="review.trustedfirmware.org"
266
267# Repository URLs. We're using anonymous HTTP as they appear to be faster rather
268# than any scheme with authentication.
269#tf_ci_repo_url="http://$arm_gerrit_url/pdswinf/ci/pdcs-platforms/platform-ci"
270tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}"
271tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}"
272#tf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/pdcs-platforms/ap/tf-topics.git"
273tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}"
274tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}"
275#tftf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/trusted-firmware/tf-a-tests.git"
276scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}"
277#scp_src_repo_url="${scp_src_repo_url:-http://$arm_gerrit_url/scp/firmware}"
278
279# FIXME set a sane default for tfa_downloads
280tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}"
281css_downloads="${css_downloads:-$tfa_downloads/css}"
282
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500283# mbedTLS archive public hosting available at github.com
284mbedtls_archive="${mbedtls_archive:-https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.18.0.zip}"
285# The tar file contains mbedtls-mbedtls-2.18.0 repo which holds the necessary
286# source files of mbedTLS project
287mbedtls_repo_name="${mbedtls_repo_name:-mbedtls-mbedtls-2.18.0}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200288linaro_release="${linaro_release:-$tfa_downloads/linaro/18.04}"
289
290coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2018.06}"
291#coverity_host="${coverity_host:-coverity.cambridge.arm.com}"
292coverity_default_checkers=(
293"--all"
294"--checker-option DEADCODE:no_dead_default:true"
295"--concurrency"
296"--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK"
297"--enable-constraint-fpp"
298"--security"
299"--ticker-mode none"
300)
301
302#export coverity_host
303
304path_list=(
305"${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin"
306"${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin"
307"${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin"
308"$coverity_path/bin"
309)
310
311ld_library_path_list=(
312)
313
314license_path_list=(
315)
316
317# Setup various paths
318if upon "$retain_paths"; then
319 # If explicitly requested, retain local paths; apppend CI paths to the
320 # existing ones.
321 op="append" extend_path "PATH" "path_list"
322 op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list"
323 op="append" extend_path "LM_LICENSE_FILE" "license_path_list"
324else
325 # Otherwise, prepend CI paths so that they take effect before local ones
326 extend_path "PATH" "path_list"
327 extend_path "LD_LIBRARY_PATH" "ld_library_path_list"
328 extend_path "LM_LICENSE_FILE" "license_path_list"
329fi
330
331export LD_LIBRARY_PATH
332export LM_LICENSE_FILE
333export ARMLMD_LICENSE_FILE="$LM_LICENSE_FILE"
334export ARM_TOOL_VARIANT=ult
335
336# vim: set tw=80 sw=8 noet: