summaryrefslogtreecommitdiff
path: root/tcwg-lnt/create-server.sh
blob: ec70564e5809fe11c3ba7919a4d7c3b9994c6a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/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] server port is  : ${lnt_server_port?}"
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] check projects  : ${check_configs[*]}"
# shellcheck disable=SC2154
echo "[$config_name] bmk projects    : ${bmk_configs[*]}"

# ####################################################################
#

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?}

    cat "${lnt_schemas_dir?}/$template.yaml.in" \
           | sed "s/TSNAME/$tsname/g" \
           > "${lnt_db_dir?}/schemas/$tsname.yaml"
}

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

    for config in "${bmk_configs[@]}"; do
        generate_schema tcwg_bmk "$config"
    done

    for config in "${check_configs[@]}"; do
        generate_schema tcwg_check "$config"
    done

fi

# 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 $lnt_server_port" || true

lnt runserver \
    "$lnt_db_dir" \
    --hostname 0.0.0.0 \
    --port $lnt_server_port \
    --processes 4 \
    &


# ####################################################################

exit 0


# ####################################################################

# 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 ?
#