forked from WebAssembly/testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-testsuite.sh
executable file
·168 lines (141 loc) · 4.14 KB
/
update-testsuite.sh
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
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Update tests based on upstream repositories.
set -e
set -u
set -o pipefail
ignore_dirs='document interpreter test/harness'
repos='
spec
threads
simd
exception-handling
gc
bulk-memory-operations
tail-call
host-bindings
reference-types
annotations
function-references
memory64
'
log_and_run() {
echo ">>" $*
if ! $*; then
echo "sub-command failed: $*"
exit
fi
}
try_log_and_run() {
echo ">>" $*
$*
}
pushdir() {
pushd $1 >/dev/null || exit
}
popdir() {
popd >/dev/null || exit
}
update_repo() {
local repo=$1
local branch=$2
pushdir repos
if [ -d ${repo} ]; then
log_and_run git -C ${repo} fetch origin
log_and_run git -C ${repo} reset origin/${branch} --hard
else
log_and_run git clone https://github.com/WebAssembly/${repo}
fi
# Add upstream spec as "spec" remote.
if [ "${repo}" != "spec" ]; then
pushdir ${repo}
if ! git remote | grep spec >/dev/null; then
log_and_run git remote add spec https://github.com/WebAssembly/spec
fi
log_and_run git fetch spec
popdir
fi
popdir
}
merge_with_spec() {
local repo=$1
local branch=$2
[ "${repo}" == "spec" ] && return
pushdir repos/${repo}
# Create and checkout "try-merge" branch.
if ! git branch | grep try-merge >/dev/null; then
log_and_run git branch try-merge origin/${branch}
fi
log_and_run git checkout try-merge
# Attempt to merge with spec/master.
log_and_run git reset origin/${branch} --hard
try_log_and_run git merge -q spec/master -m "merged"
if [ $? -ne 0 ]; then
# Ignore merge conflicts in non-test directories.
# We don't care about those changes.
try_log_and_run git checkout --ours ${ignore_dirs}
try_log_and_run git add ${ignore_dirs}
try_log_and_run git -c core.editor=true merge --continue
if [ $? -ne 0 ]; then
git merge --abort
popdir
return 1
fi
fi
popdir
return 0
}
echo -e "Update repos\n" > commit_message
failed_repos=
for repo in ${repos}; do
echo "++ updating ${repo}"
if [ "${repo}" = "simd" ]; then
branch=main
else
branch=master
fi
update_repo ${repo} ${branch}
if ! merge_with_spec ${repo} ${branch}; then
echo -e "!! error merging ${repo}, skipping\n"
failed_repos="${failed_repos} ${repo}"
continue
fi
if [ "${repo}" = "spec" ]; then
wast_dir=.
log_and_run cp $(find repos/${repo}/test/core -name \*.wast) ${wast_dir}
else
wast_dir=proposals/${repo}
mkdir -p ${wast_dir}
# Don't add tests from proposal that are the same as spec.
pushdir repos/${repo}
for new in $(find test/core -name \*.wast); do
old=../../repos/spec/${new}
if [[ ! -f ${old} ]] || ! diff ${old} ${new} >/dev/null; then
log_and_run cp ${new} ../../${wast_dir}
fi
done
popdir
fi
# Check whether any files were removed.
for old in $(find ${wast_dir} -maxdepth 1 -name \*.wast); do
new=$(find repos/${repo}/test/core -name ${old##*/})
if [[ ! -f ${new} ]]; then
log_and_run git rm ${old}
fi
done
# Check whether any files were updated.
if [ $(git status -s ${wast_dir} | wc -l) -ne 0 ]; then
log_and_run git add ${wast_dir}/*.wast
repo_sha=$(git -C repos/${repo} log --max-count=1 --oneline origin/${branch}| sed -e 's/ .*//')
echo " ${repo}:" >> commit_message
echo " https://github.com/WebAssembly/${repo}/commit/${repo_sha}" >> commit_message
fi
echo -e "-- ${repo}\n"
done
echo "" >> commit_message
echo "This change was automatically generated by \`update-testsuite.sh\`" >> commit_message
git commit -a -F commit_message
# git push
echo "done"
if [ -n "${failed_repos}" ]; then
echo "!! failed to update repos: ${failed_repos}"
fi