refactor: move LAVA job definition templates into independent files
This change introduces a new script function to expand the variables in
a file. With this, we can move the LAVA YAML job template descriptions,
which are currently embedded inside individual HEREDOCs, into their own
files.
Signed-off-by: Chris Kay <chris.kay@arm.com>
Change-Id: I09805ab4b6894a371e63a944d113ca2f475a806b
diff --git a/utils.sh b/utils.sh
index 1a56e10..17eee28 100644
--- a/utils.sh
+++ b/utils.sh
@@ -229,6 +229,34 @@
eval "$path_var=\"$array_val\""
}
+# Expand and evaluate Bash variables and expressions in a file, whose path is
+# given by the first parameter.
+#
+# For example, to expand a file containing the following:
+#
+# My name is ${name}!
+#
+# You might use:
+#
+# name="Chris" expand_template "path-to-my-file.txt"
+#
+# This would yield:
+#
+# My name is Chris!
+#
+# If you need to run multiple expansions on a file (e.g. to fill out information
+# incrementally), then you can escape expansion of a variable with a backslash,
+# e.g. `\${name}`.
+#
+# The expanded output is printed to the standard output stream.
+expand_template() {
+ local path="$1"
+
+ eval "cat <<-EOF
+ $(<${path})
+ EOF"
+}
+
# Fetch and extract the latest supported version of the LLVM toolchain from
# a compressed archive file to a target directory, if it is required.
setup_llvm_toolchain() {