forked from WebAssembly/testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-testsuite.sh
executable file
·137 lines (112 loc) · 3.66 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
#!/bin/bash
set -e
set -u
set -o pipefail
repos='spec threads simd exception-handling gc bulk-memory-operations tail-call nontrapping-float-to-int-conversions multi-value host-bindings sign-extension-ops reference-types'
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
pushdir repos
if [ -d ${repo} ]; then
log_and_run git -C ${repo} fetch origin
log_and_run git -C ${repo} reset origin/master --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
[ "${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/master
fi
log_and_run git checkout try-merge
# Attempt to merge with spec/master.
log_and_run git reset origin/master --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 document interpreter
try_log_and_run git add document interpreter
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}"
update_repo ${repo}
if ! merge_with_spec ${repo}; 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 propsoal 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 updated.
if [ $(git status -s ${wast_dir}/*.wast | 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/master| 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