summaryrefslogtreecommitdiff
path: root/tcwg-lnt/create-server.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tcwg-lnt/create-server.sh')
-rwxr-xr-xtcwg-lnt/create-server.sh151
1 files changed, 151 insertions, 0 deletions
diff --git a/tcwg-lnt/create-server.sh b/tcwg-lnt/create-server.sh
new file mode 100755
index 00000000..86b7a5a7
--- /dev/null
+++ b/tcwg-lnt/create-server.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+
+set -euf -o pipefail
+
+# glob variable declarations
+script_dir="$(readlink -f "$(dirname "$0")")"
+
+# ####################################################################
+# read server configuration
+
+config_name="$1"
+
+# shellcheck disable=SC1090
+. $script_dir/$config_name/config
+
+lnt_repo_url=${lnt_repo_url-https://git.linaro.org/toolchain/llvm-lnt.git}
+lnt_repo_branch=${lnt_repo_branch?}
+lnt_root_dir="${lnt_root_dir-$PWD/$config_name/lntserver/}"
+
+echo "[$config_name] server name is : ${lnt_server_name?}"
+echo "[$config_name] lnt repository : ${lnt_repo_url?}"
+echo "[$config_name] lnt branch : ${lnt_repo_url?}"
+echo "[$config_name] local root_dir : ${lnt_root_dir}"
+# shellcheck disable=SC2154
+echo "[$config_name] lnt projects : ${!lnt_projects[*]}"
+
+# ####################################################################
+#
+
+lnt_sandbox_dir="$lnt_root_dir/sandbox"
+lnt_repo_dir="$lnt_root_dir/llvm-lnt"
+lnt_db_dir="$lnt_root_dir/lnt-database"
+lnt_schemas_dir="$script_dir/$config_name"
+
+# ####################################################################
+#
+# get LLVM-LNT sources
+
+if [ ! -d "$lnt_repo_dir" ]; then
+ git clone "$lnt_repo_url" "$lnt_repo_dir"
+fi
+
+git -C "$lnt_repo_dir" fetch origin "$lnt_repo_branch"
+
+git -C "$lnt_repo_dir" checkout --force FETCH_HEAD
+
+# ####################################################################
+#
+# create LNT sandbox
+
+if [ ! -d "$lnt_sandbox_dir" ]; then
+ (
+ virtualenv "$lnt_sandbox_dir"
+
+ cd "$lnt_sandbox_dir"
+
+ # shellcheck disable=SC1091
+ source bin/activate
+
+ python "$lnt_repo_dir"/setup.py develop
+
+ # temporary workaround for jammy
+ case "$(lsb_release -sc)" in
+ focal)
+ ;;
+ jammy)
+ (
+ set +f
+ sed -i 's/from collections /from collections.abc /' \
+ lib/python3.10/site-packages/Werkzeug-0.12.2-py3.10.egg/werkzeug/datastructures.py \
+ lib/python3.10/site-packages/Jinja2-2.7.2-py3.10.egg/jinja2/_compat.py \
+ lib/python3.10/site-packages/MarkupSafe-0.23-py3.10-*.egg/markupsafe/__init__.py
+ )
+ ;;
+ *)
+ echo >&2 "distro not supported"
+ exit 1
+ ;;
+ esac
+ )
+fi
+
+# shellcheck disable=SC1091
+source "$lnt_sandbox_dir/bin/activate"
+
+
+# ####################################################################
+#
+# create LNT database
+
+generate_schema()
+{
+ local template=${1?}
+ local tsname=${2?}
+ local outdir="$3"
+
+ cat "${lnt_schemas_dir?}/$template.yaml.in" \
+ | sed "s/TSNAME/$tsname/g" > "$outdir/$tsname.yaml"
+}
+
+tmp_schemas=$(mktemp -d)
+
+for project in "${!lnt_projects[@]}"; do
+ generate_schema "${lnt_projects[$project]}" "$project" "$tmp_schemas"
+done
+
+if [ -d "$lnt_db_dir" ]; then
+ if ! diff -rq "$lnt_db_dir/schemas" "$tmp_schemas"; then
+ # Schemas have changed, so start from a fresh database.
+ rm -rf "$lnt_db_dir"
+ fi
+fi
+
+if [ ! -d "$lnt_db_dir" ]; then
+ lnt create "$lnt_db_dir" --name "$lnt_server_name" --stable-urls
+
+ lnt_secret_token="$(echo $RANDOM | md5sum | cut -d' ' -f1)"
+
+ sed -i "s/# \(api_auth_token =\).*/\1 '$lnt_secret_token'/" "$lnt_db_dir"/lnt.cfg
+
+ rsync -a --del "$tmp_schemas/" "$lnt_db_dir/schemas/"
+fi
+
+rm -rf "$tmp_schemas"
+
+# TODO schema update not yet supported
+# eventually delete everything
+# or just delete the updated testsuite (not supported yet in lnt)
+
+
+# ####################################################################
+#
+# run the LNT server
+
+# only one server on the machine for now
+pkill --echo --full "lnt runserver .* --port 80" || true
+
+exec lnt runserver "$lnt_db_dir" --hostname 0.0.0.0 --port 80 --processes 4
+
+# ####################################################################
+
+# TODO
+#
+# - remove temporary workaround for jammy (update dependencies version)
+#
+# - look at github.com/llvm/llvm-lnt/blob/main/docker/docker-entrypoint.sh
+#
+# - also apply local LNT patches
+#
+# - option to restart everything from scratch ? just the db ?
+#