blob: fbb5ec2d7350c92fe8fac44edf8fbcc4524c7415 [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
48function parse_version() {
49 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
56 VERSION="refs/heads/master"
57 fi
58
59 echo "${VERSION}"
60}
61
62# Must projects
Paul Sokolovsky9aaec7b2023-06-24 14:11:32 +030063if [ -n "${GERRIT_EVENT_HASH}" ]; then
64 # If triggered by Gerrit, use its variables
65 TFM_PROJECT="https://${GERRIT_HOST}/${GERRIT_PROJECT}"
66else
67 TFM_PROJECT="${CODE_REPO:?}"
68fi
Xinyu Zhang15362412023-02-10 15:57:07 +080069TFM_REFSPEC="${GERRIT_REFSPEC:?}"
70TFM_NAME="trusted-firmware-m"
71
72SCRIPTS_PROJECT="${CI_SCRIPTS_REPO:?}"
73SCRIPTS_REFSPEC="${CI_SCRIPTS_BRANCH:?}"
74SCRIPTS_NAME="tf-m-ci-scripts"
75
76# Array containing "<repo url>;"<repo name>;<refspec>" elements
77must_repos=(
78 "${TFM_PROJECT};${TFM_NAME};${TFM_REFSPEC}"
79 "${SCRIPTS_PROJECT};${SCRIPTS_NAME};${SCRIPTS_REFSPEC}"
80)
81
82for repo in ${must_repos[@]}; do
83 # Parse the repo elements
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050084 REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')"
85 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')"
86 REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')"
Paul Sokolovskybbbf5ec2023-08-17 21:24:24 +030087 echo "Repo: $REPO_URL $REPO_NAME $REPO_REFSPEC"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050088
Xinyu Zhang15362412023-02-10 15:57:07 +080089 if [ ! -d "${SHARE_FOLDER}/${REPO_NAME}" ]; then
90 git_clone $REPO_URL "${SHARE_FOLDER}/${REPO_NAME}"
91 git_checkout "${SHARE_FOLDER}/${REPO_NAME}" $REPO_REFSPEC
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050092 else
Xinyu Zhang15362412023-02-10 15:57:07 +080093 cd "${SHARE_FOLDER}/${REPO_NAME}"
94 echo -e "Share Folder ${REPO_NAME} $(git rev-parse --short HEAD)\n"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050095 cd $OLDPWD
96 fi
97
Xinyu Zhang15362412023-02-10 15:57:07 +080098 # Copy repos into pwd dir (workspace in CI), so each job would work
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050099 # on its own workspace
Xinyu Zhang15362412023-02-10 15:57:07 +0800100 cp -a -f "${SHARE_FOLDER}/${REPO_NAME}" "${WORKSPACE}/${REPO_NAME}"
101done
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500102
Xinyu Zhang15362412023-02-10 15:57:07 +0800103# Dependency projects
104TFM_TESTS_PROJECT="${TFM_TESTS_URL:-}"
105TFM_TESTS_REFSPEC="${TFM_TESTS_REFSPEC:-"$(parse_version lib/ext/tf-m-tests/repo_config_default.cmake TFM_TEST_REPO_VERSION)"}"
106TFM_TESTS_NAME="tf-m-tests"
107
108MBEDTLS_PROJECT="${MBEDTLS_URL:-}"
109MBEDTLS_REFSPEC="${MBEDTLS_VERSION:-"$(parse_version config/config_base.cmake MBEDCRYPTO_VERSION)"}"
110MBEDTLS_NAME="mbedtls"
111
112MCUBOOT_PROJECT="${MCUBOOT_URL:-}"
113MCUBOOT_REFSPEC="${MCUBOOT_REFSPEC:-"$(parse_version config/config_base.cmake MCUBOOT_VERSION)"}"
114MCUBOOT_NAME="mcuboot"
115
116PSA_ARCH_TESTS_PROJECT="${PSA_ARCH_TESTS_URL:-}"
117PSA_ARCH_TESTS_REFSPEC="${PSA_ARCH_TESTS_VERSION:-"$(parse_version config/config_base.cmake PSA_ARCH_TESTS_VERSION)"}"
118PSA_ARCH_TESTS_NAME="psa-arch-tests"
119
120QCBOR_PROJECT="${QCBOR_URL:-}"
121QCBOR_REFSPEC="${QCBOR_VERSION:-"$(parse_version lib/ext/qcbor/CMakeLists.txt QCBOR_VERSION)"}"
122QCBOR_NAME="qcbor"
123
124TFM_EXTRAS_PROJECT="${TFM_EXTRAS_URL:-}"
125TFM_EXTRAS_REFSPEC="${TFM_EXTRAS_REFSPEC:-"$(parse_version lib/ext/tf-m-extras/CMakeLists.txt TFM_EXTRAS_REPO_VERSION)"}"
126TFM_EXTRAS_NAME="tf-m-extras"
127
128QA_TOOLS_PROJECT="https://review.trustedfirmware.org/ci/qa-tools"
129QA_TOOLS_REFSPEC="openci"
130QA_TOOLS_NAME="qa-tools"
131
132# Array containing "<repo url>;"<repo name>;<refspec>" elements
133dependency_repos=(
134 "${TFM_TESTS_PROJECT};${TFM_TESTS_NAME};${TFM_TESTS_REFSPEC}"
135 "${MBEDTLS_PROJECT};${MBEDTLS_NAME};${MBEDTLS_REFSPEC}"
136 "${MCUBOOT_PROJECT};${MCUBOOT_NAME};${MCUBOOT_REFSPEC}"
137 "${PSA_ARCH_TESTS_PROJECT};${PSA_ARCH_TESTS_NAME};${PSA_ARCH_TESTS_REFSPEC}"
138 "${QCBOR_PROJECT};${QCBOR_NAME};${QCBOR_REFSPEC}"
139 "${TFM_EXTRAS_PROJECT};${TFM_EXTRAS_NAME};${TFM_EXTRAS_REFSPEC}"
140 "${QA_TOOLS_PROJECT};${QA_TOOLS_NAME};${QA_TOOLS_REFSPEC}"
141)
142
143for repo in ${dependency_repos[@]}; do
144 # Parse the repo elements
145 REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')"
146 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')"
147 REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')"
Paul Sokolovskybbbf5ec2023-08-17 21:24:24 +0300148 echo "Repo: $REPO_URL $REPO_NAME $REPO_REFSPEC"
Xinyu Zhang15362412023-02-10 15:57:07 +0800149
Xinyu Zhang63195e82023-07-18 10:31:26 +0800150 # In case repository is not defined, just skip it
151 if [ -z "${REPO_URL}" ]; then
152 continue
153 fi
154
Xinyu Zhang15362412023-02-10 15:57:07 +0800155 if [ ! -d "${SHARE_FOLDER}/${REPO_NAME}" ]; then
156 git_clone $REPO_URL "${SHARE_FOLDER}/${REPO_NAME}"
157 git_checkout "${SHARE_FOLDER}/${REPO_NAME}" $REPO_REFSPEC
158 else
159 cd "${SHARE_FOLDER}/${REPO_NAME}"
160 echo -e "Share Folder ${REPO_NAME} $(git rev-parse --short HEAD)\n"
161 cd $OLDPWD
162 fi
163
164 # Copy repos into pwd dir (workspace in CI), so each job would work
165 # on its own workspace
166 cp -a -f "${SHARE_FOLDER}/${REPO_NAME}" "${WORKSPACE}/${REPO_NAME}"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500167done