blob: 32dba6d6c9bb75e8c335fd40ca040cf60c67bd84 [file] [log] [blame]
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -05001#!/usr/bin/env bash
2#
Xinyu Zhang15362412023-02-10 15:57:07 +08003# Copyright (c) 2021-2023 Arm Limited. All rights reserved.
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -05004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# Clones and checkout TF-M related repositories in case these are not present
8# under SHARE_FOLDER, otherwise copy the share repositories into current folder
9# (workspace)
10
11#
12# The way it works is simple: the top level job sets the SHARE_FOLDER
13# parameter based on its name and number on top of the share
14# volume (/srv/shared/<job name>/<job number>) then it calls the clone
15# script (clone.sh), which in turn it fetches the repositories mentioned
16# above. Jobs triggered on behalf of the latter, share the same
17# SHARE_FOLDER value, and these in turn also call the clone script, but
18# in this case, the script detects that the folder is already populated so
19# its role is to simply copy the repositories into the job's
20# workspace. As seen, all jobs work with repositories on their own
21# workspace, which are just copies of the share folder, so there is no
22# change of a race condition, i.e every job works with its own copy. The
23# worst case scenario is where the down-level job,
24# i.e. tf-m-build-config, uses its default SHARE_FOLDER value, in this
25# case, it would simply clone its own repositories without reusing any
26# file however the current approach prevents the latter unless the job
27# is triggered manually from the buider job itself.
28#
29
Paul Sokolovsky0c5b5fa2022-11-09 17:42:20 +030030set -e
31
Xinyu Zhang15362412023-02-10 15:57:07 +080032. $(dirname $0)/util_git.sh
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050033
34# Take into consideration non-CI runs where SHARE_FOLDER variable
35# may not be present
36if [ -z "${SHARE_FOLDER}" ]; then
37 # Default Jenkins values
38 SHARE_VOLUME="${SHARE_VOLUME:-$PWD}"
39 JOB_NAME="${JOB_NAME:-local}"
40 BUILD_NUMBER="${BUILD_NUMBER:-0}"
41 SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER}
42fi
43
Paul Sokolovsky62a23e32022-12-23 18:34:50 +030044echo "Share Folder path: ${SHARE_FOLDER}"
45echo
46
Xinyu Zhang15362412023-02-10 15:57:07 +080047# Parse dependency version specified in TF-M CMake configs
Xinyu Zhang0e4d7722023-10-11 17:02:36 +080048function parse_version_from_cmake() {
Xinyu Zhang15362412023-02-10 15:57:07 +080049 CONFIG_FILE_NAME=$1
50 DEPENDENCY_NAME=$2
51 CONFIG_FILE_PATH="${SHARE_FOLDER}/${TFM_NAME}/${CONFIG_FILE_NAME}"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050052
Xinyu Zhang15362412023-02-10 15:57:07 +080053 VERSION="$(grep "set(${DEPENDENCY_NAME}" ${CONFIG_FILE_PATH} | cut -d\" -f2)"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050054
Xinyu Zhang15362412023-02-10 15:57:07 +080055 if [ -z "${VERSION}" ]; then
Xinyu Zhang83ef2442023-09-21 16:51:06 +080056 VERSION="refs/heads/main"
Xinyu Zhang15362412023-02-10 15:57:07 +080057 fi
58
59 echo "${VERSION}"
60}
61
Xinyu Zhangf3f15a32023-10-11 17:59:54 +080062# Parse dependency version specified in TF-M commit message
63function parse_version_from_commit_msg() {
64 DEPENDENCY_NAME=$1
65 TFM_PATH="${SHARE_FOLDER}/${TFM_NAME}"
66
67 cd ${SHARE_FOLDER}/${TFM_NAME}
68
69 VERSION="$(git log HEAD -n 1 | grep "Depend on ${DEPENDENCY_NAME}" | awk '{print $NF}')"
70
71 if [ -z "${VERSION}" ]; then
72 VERSION="refs/heads/feature-build-split-v2"
73 fi
74
75 cd $OLDPWD
76
77 echo "${VERSION}"
78}
79
Xinyu Zhang15362412023-02-10 15:57:07 +080080# Must projects
Paul Sokolovsky9aaec7b2023-06-24 14:11:32 +030081if [ -n "${GERRIT_EVENT_HASH}" ]; then
82 # If triggered by Gerrit, use its variables
83 TFM_PROJECT="https://${GERRIT_HOST}/${GERRIT_PROJECT}"
84else
85 TFM_PROJECT="${CODE_REPO:?}"
86fi
Xinyu Zhang15362412023-02-10 15:57:07 +080087TFM_REFSPEC="${GERRIT_REFSPEC:?}"
88TFM_NAME="trusted-firmware-m"
89
90SCRIPTS_PROJECT="${CI_SCRIPTS_REPO:?}"
91SCRIPTS_REFSPEC="${CI_SCRIPTS_BRANCH:?}"
92SCRIPTS_NAME="tf-m-ci-scripts"
93
94# Array containing "<repo url>;"<repo name>;<refspec>" elements
95must_repos=(
96 "${TFM_PROJECT};${TFM_NAME};${TFM_REFSPEC}"
97 "${SCRIPTS_PROJECT};${SCRIPTS_NAME};${SCRIPTS_REFSPEC}"
98)
99
100for repo in ${must_repos[@]}; do
101 # Parse the repo elements
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500102 REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')"
103 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')"
104 REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')"
Paul Sokolovskybbbf5ec2023-08-17 21:24:24 +0300105 echo "Repo: $REPO_URL $REPO_NAME $REPO_REFSPEC"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500106
Xinyu Zhang15362412023-02-10 15:57:07 +0800107 if [ ! -d "${SHARE_FOLDER}/${REPO_NAME}" ]; then
108 git_clone $REPO_URL "${SHARE_FOLDER}/${REPO_NAME}"
109 git_checkout "${SHARE_FOLDER}/${REPO_NAME}" $REPO_REFSPEC
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500110 else
Xinyu Zhang15362412023-02-10 15:57:07 +0800111 cd "${SHARE_FOLDER}/${REPO_NAME}"
112 echo -e "Share Folder ${REPO_NAME} $(git rev-parse --short HEAD)\n"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500113 cd $OLDPWD
114 fi
115
Xinyu Zhang15362412023-02-10 15:57:07 +0800116 # Copy repos into pwd dir (workspace in CI), so each job would work
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500117 # on its own workspace
Xinyu Zhang15362412023-02-10 15:57:07 +0800118 cp -a -f "${SHARE_FOLDER}/${REPO_NAME}" "${WORKSPACE}/${REPO_NAME}"
119done
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500120
Xinyu Zhang15362412023-02-10 15:57:07 +0800121# Dependency projects
122TFM_TESTS_PROJECT="${TFM_TESTS_URL:-}"
Xinyu Zhangf3f15a32023-10-11 17:59:54 +0800123TFM_TESTS_REFSPEC="${TFM_TESTS_REFSPEC:-"$(parse_version_from_commit_msg tf-m-tests)"}"
Xinyu Zhang15362412023-02-10 15:57:07 +0800124TFM_TESTS_NAME="tf-m-tests"
125
126MBEDTLS_PROJECT="${MBEDTLS_URL:-}"
Xinyu Zhang0e4d7722023-10-11 17:02:36 +0800127MBEDTLS_REFSPEC="${MBEDTLS_VERSION:-"$(parse_version_from_cmake config/config_base.cmake MBEDCRYPTO_VERSION)"}"
Xinyu Zhang15362412023-02-10 15:57:07 +0800128MBEDTLS_NAME="mbedtls"
129
130MCUBOOT_PROJECT="${MCUBOOT_URL:-}"
Xinyu Zhang0e4d7722023-10-11 17:02:36 +0800131MCUBOOT_REFSPEC="${MCUBOOT_REFSPEC:-"$(parse_version_from_cmake config/config_base.cmake MCUBOOT_VERSION)"}"
Xinyu Zhang15362412023-02-10 15:57:07 +0800132MCUBOOT_NAME="mcuboot"
133
134PSA_ARCH_TESTS_PROJECT="${PSA_ARCH_TESTS_URL:-}"
Xinyu Zhang00363c82023-10-11 15:40:19 +0800135PSA_ARCH_TESTS_REFSPEC="${PSA_ARCH_TESTS_VERSION:-}"
Xinyu Zhang15362412023-02-10 15:57:07 +0800136PSA_ARCH_TESTS_NAME="psa-arch-tests"
137
138QCBOR_PROJECT="${QCBOR_URL:-}"
Xinyu Zhang0e4d7722023-10-11 17:02:36 +0800139QCBOR_REFSPEC="${QCBOR_VERSION:-"$(parse_version_from_cmake lib/ext/qcbor/CMakeLists.txt QCBOR_VERSION)"}"
Xinyu Zhang15362412023-02-10 15:57:07 +0800140QCBOR_NAME="qcbor"
141
142TFM_EXTRAS_PROJECT="${TFM_EXTRAS_URL:-}"
Xinyu Zhang0e4d7722023-10-11 17:02:36 +0800143TFM_EXTRAS_REFSPEC="${TFM_EXTRAS_REFSPEC:-"$(parse_version_from_cmake lib/ext/tf-m-extras/CMakeLists.txt TFM_EXTRAS_REPO_VERSION)"}"
Xinyu Zhang15362412023-02-10 15:57:07 +0800144TFM_EXTRAS_NAME="tf-m-extras"
145
146QA_TOOLS_PROJECT="https://review.trustedfirmware.org/ci/qa-tools"
147QA_TOOLS_REFSPEC="openci"
148QA_TOOLS_NAME="qa-tools"
149
150# Array containing "<repo url>;"<repo name>;<refspec>" elements
151dependency_repos=(
152 "${TFM_TESTS_PROJECT};${TFM_TESTS_NAME};${TFM_TESTS_REFSPEC}"
153 "${MBEDTLS_PROJECT};${MBEDTLS_NAME};${MBEDTLS_REFSPEC}"
154 "${MCUBOOT_PROJECT};${MCUBOOT_NAME};${MCUBOOT_REFSPEC}"
155 "${PSA_ARCH_TESTS_PROJECT};${PSA_ARCH_TESTS_NAME};${PSA_ARCH_TESTS_REFSPEC}"
156 "${QCBOR_PROJECT};${QCBOR_NAME};${QCBOR_REFSPEC}"
157 "${TFM_EXTRAS_PROJECT};${TFM_EXTRAS_NAME};${TFM_EXTRAS_REFSPEC}"
158 "${QA_TOOLS_PROJECT};${QA_TOOLS_NAME};${QA_TOOLS_REFSPEC}"
159)
160
161for repo in ${dependency_repos[@]}; do
162 # Parse the repo elements
163 REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')"
164 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')"
165 REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')"
Paul Sokolovskybbbf5ec2023-08-17 21:24:24 +0300166 echo "Repo: $REPO_URL $REPO_NAME $REPO_REFSPEC"
Xinyu Zhang15362412023-02-10 15:57:07 +0800167
Xinyu Zhang63195e82023-07-18 10:31:26 +0800168 # In case repository is not defined, just skip it
169 if [ -z "${REPO_URL}" ]; then
170 continue
171 fi
172
Xinyu Zhang15362412023-02-10 15:57:07 +0800173 if [ ! -d "${SHARE_FOLDER}/${REPO_NAME}" ]; then
174 git_clone $REPO_URL "${SHARE_FOLDER}/${REPO_NAME}"
175 git_checkout "${SHARE_FOLDER}/${REPO_NAME}" $REPO_REFSPEC
176 else
177 cd "${SHARE_FOLDER}/${REPO_NAME}"
178 echo -e "Share Folder ${REPO_NAME} $(git rev-parse --short HEAD)\n"
179 cd $OLDPWD
180 fi
181
182 # Copy repos into pwd dir (workspace in CI), so each job would work
183 # on its own workspace
184 cp -a -f "${SHARE_FOLDER}/${REPO_NAME}" "${WORKSPACE}/${REPO_NAME}"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500185done