Utils: Refine codes to parse dependency version
This patch makes the following changes:
1. Create "util_parse_version.sh" for function to parse dependency
versions.
2. Expand parse_version() to support parsing versions from different
types of file.
With this patch, CI is able to auto-parse the tf-m-tests version from
the newly defined txt file instead of CMake file.
Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: Ib5b6d38ead6346ff5482f1e6baabf73ea185eff1
diff --git a/utils/util_parse_version.sh b/utils/util_parse_version.sh
new file mode 100644
index 0000000..51d73e2
--- /dev/null
+++ b/utils/util_parse_version.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2023 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Parse dependency version from file
+# Input parameters:
+# RELATIVE_PATH: Relative path to the dependency version config file in TF-M
+# PATTERN: Pattern used to search for the line containing target dependency version
+# SEPARATOR: Separator to split the string
+# COMPONENT_NUM: Decide which separated component is the dependency version
+function parse_version() {
+ RELATIVE_PATH=$1
+ PATTERN=$2
+ SEPARATOR=$3
+ COMPONENT_NUM=$4
+
+ ABSOLUTE_PATH="${SHARE_FOLDER}/${TFM_NAME}/${RELATIVE_PATH}"
+
+ VERSION="$(grep "${PATTERN}" ${ABSOLUTE_PATH} | cut -d${SEPARATOR} -f${COMPONENT_NUM})"
+
+ if [ -z "${VERSION}" ]; then
+ VERSION="refs/heads/main"
+ fi
+
+ echo "${VERSION}"
+}