blob: 51d73e268b8b42dd048188efd9cfc01a84f60cba [file] [log] [blame]
Xinyu Zhang849eac72023-10-11 17:02:36 +08001#!/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
14function 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}