02f59c3fefc0a58c0897ea2b1e2afd37c1dbed66
[platform/framework/web/lwnode.git] /
1 #!/bin/bash
2 # Update tests based on upstream repositories.
3 set -e
4 set -u
5 set -o pipefail
6
7 ignore_dirs='document interpreter test/harness'
8
9 repos='
10   spec
11   threads
12   simd
13   exception-handling
14   gc
15   bulk-memory-operations
16   tail-call
17   host-bindings
18   reference-types
19   annotations
20   function-references
21   memory64
22 '
23
24 log_and_run() {
25     echo ">>" $*
26     if ! $*; then
27         echo "sub-command failed: $*"
28         exit
29     fi
30 }
31
32 try_log_and_run() {
33     echo ">>" $*
34     $*
35 }
36
37 pushdir() {
38     pushd $1 >/dev/null || exit
39 }
40
41 popdir() {
42     popd >/dev/null || exit
43 }
44
45 update_repo() {
46     local repo=$1
47     pushdir repos
48         if [ -d ${repo} ]; then
49             log_and_run git -C ${repo} fetch origin
50             log_and_run git -C ${repo} reset origin/master --hard
51         else
52             log_and_run git clone https://github.com/WebAssembly/${repo}
53         fi
54
55         # Add upstream spec as "spec" remote.
56         if [ "${repo}" != "spec" ]; then
57             pushdir ${repo}
58                 if ! git remote | grep spec >/dev/null; then
59                     log_and_run git remote add spec https://github.com/WebAssembly/spec
60                 fi
61
62                 log_and_run git fetch spec
63             popdir
64         fi
65     popdir
66 }
67
68 merge_with_spec() {
69     local repo=$1
70
71     [ "${repo}" == "spec" ] && return
72
73     pushdir repos/${repo}
74         # Create and checkout "try-merge" branch.
75         if ! git branch | grep try-merge >/dev/null; then
76             log_and_run git branch try-merge origin/master
77         fi
78         log_and_run git checkout try-merge
79
80         # Attempt to merge with spec/master.
81         log_and_run git reset origin/master --hard
82         try_log_and_run git merge -q spec/master -m "merged"
83         if [ $? -ne 0 ]; then
84             # Ignore merge conflicts in non-test directories.
85             # We don't care about those changes.
86             try_log_and_run git checkout --ours ${ignore_dirs}
87             try_log_and_run git add ${ignore_dirs}
88             try_log_and_run git -c core.editor=true merge --continue
89             if [ $? -ne 0 ]; then
90                 git merge --abort
91                 popdir
92                 return 1
93             fi
94         fi
95     popdir
96     return 0
97 }
98
99
100 echo -e "Update repos\n" > commit_message
101
102 failed_repos=
103
104 for repo in ${repos}; do
105     echo "++ updating ${repo}"
106     update_repo ${repo}
107
108     if ! merge_with_spec ${repo}; then
109         echo -e "!! error merging ${repo}, skipping\n"
110         failed_repos="${failed_repos} ${repo}"
111         continue
112     fi
113
114     if [ "${repo}" = "spec" ]; then
115         wast_dir=.
116         log_and_run cp $(find repos/${repo}/test/core -name \*.wast) ${wast_dir}
117     else
118         wast_dir=proposals/${repo}
119         mkdir -p ${wast_dir}
120
121         # Don't add tests from proposal that are the same as spec.
122         pushdir repos/${repo}
123             for new in $(find test/core -name \*.wast); do
124                 old=../../repos/spec/${new}
125                 if [[ ! -f ${old} ]] || ! diff ${old} ${new} >/dev/null; then
126                     log_and_run cp ${new} ../../${wast_dir}
127                 fi
128             done
129         popdir
130     fi
131
132     # Check whether any files were removed.
133     for old in $(find ${wast_dir} -maxdepth 1 -name \*.wast); do
134       new=$(find repos/${repo}/test/core -name ${old##*/})
135       if [[ ! -f ${new} ]]; then
136           log_and_run git rm ${old}
137       fi
138     done
139
140     # Check whether any files were updated.
141     if [ $(git status -s ${wast_dir} | wc -l) -ne 0 ]; then
142         log_and_run git add ${wast_dir}/*.wast
143
144         repo_sha=$(git -C repos/${repo} log --max-count=1 --oneline origin/master| sed -e 's/ .*//')
145         echo "  ${repo}:" >> commit_message
146         echo "    https://github.com/WebAssembly/${repo}/commit/${repo_sha}" >> commit_message
147     fi
148
149     echo -e "-- ${repo}\n"
150 done
151
152 echo "" >> commit_message
153 echo "This change was automatically generated by \`update-testsuite.sh\`" >> commit_message
154 git commit -a -F commit_message
155 # git push
156
157 echo "done"
158
159 if [ -n "${failed_repos}" ]; then
160   echo "!! failed to update repos: ${failed_repos}"
161 fi