Xinyu Zhang | a73e677 | 2023-10-11 17:02:36 +0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2023 Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Parse dependency version from file |
| 9 | # Input parameters: |
| 10 | # RELATIVE_PATH: Relative path to the dependency version config file in TF-M |
| 11 | # PATTERN: Pattern used to search for the line containing target dependency version |
| 12 | # SEPARATOR: Separator to split the string |
| 13 | # COMPONENT_NUM: Decide which separated component is the dependency version |
| 14 | function parse_version() { |
| 15 | RELATIVE_PATH=$1 |
| 16 | PATTERN=$2 |
| 17 | SEPARATOR=$3 |
| 18 | COMPONENT_NUM=$4 |
| 19 | |
| 20 | ABSOLUTE_PATH="${SHARE_FOLDER}/${TFM_NAME}/${RELATIVE_PATH}" |
| 21 | |
| 22 | VERSION="$(grep "${PATTERN}" ${ABSOLUTE_PATH} | cut -d${SEPARATOR} -f${COMPONENT_NUM})" |
| 23 | |
| 24 | if [ -z "${VERSION}" ]; then |
| 25 | VERSION="refs/heads/main" |
| 26 | fi |
| 27 | |
| 28 | echo "${VERSION}" |
| 29 | } |