1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Test bash, python3, C and C++ under Wine!
|
4 | #
|
5 | # Notes:
|
6 | # python3 is called python.exe on Windows
|
7 | #
|
8 | # Other things to try:
|
9 |
|
10 | # - python3
|
11 | # - test out asyncio on Windows!
|
12 | # - especially process creation
|
13 | # - a test framework for stdin/stdout/stderr would be nice
|
14 | # - can sh_spec.py work with non-shell scripts?
|
15 | #
|
16 | # - git
|
17 | # - can we clone our repo? commit?
|
18 | #
|
19 | # And then do this all inside QEMU - it seems more automated than VirtualBox
|
20 | #
|
21 | # - do automated installation of everything?
|
22 |
|
23 | set -o nounset
|
24 | set -o pipefail
|
25 | set -o errexit
|
26 |
|
27 |
|
28 | readonly DIR=_tmp/win32
|
29 |
|
30 | my-curl() {
|
31 | curl --location --continue-at - \
|
32 | --remote-name --output-dir $DIR "$@"
|
33 | }
|
34 |
|
35 | download() {
|
36 | mkdir -p $DIR
|
37 |
|
38 | my-curl 'https://www.python.org/ftp/python/3.13.3/python-3.13.3-amd64.exe'
|
39 |
|
40 | my-curl \
|
41 | 'https://github.com/git-for-windows/git/releases/download/v2.49.0.windows.1/Git-2.49.0-64-bit.exe'
|
42 |
|
43 | my-curl \
|
44 | 'https://github.com/jmeubank/tdm-gcc/releases/download/v10.3.0-tdm64-2/tdm64-gcc-10.3.0-2.exe'
|
45 | }
|
46 |
|
47 | find-python() {
|
48 | find ~/.wine/drive_c/|grep python.exe
|
49 | }
|
50 |
|
51 | test-python3() {
|
52 | # takes 326 ms
|
53 | time wine \
|
54 | ~/.wine/drive_c/users/andy/AppData/Local/Programs/Python/Python313/python.exe \
|
55 | -c 'print("hi")'
|
56 | }
|
57 |
|
58 | readonly BASH=~/'.wine/drive_c/Program Files/Git/bin/bash.exe'
|
59 | readonly GIT_BASH=~/'.wine/drive_c/Program Files/Git/git-bash.exe'
|
60 |
|
61 | test-bash() {
|
62 | # 378 ms
|
63 | # works, but getting a bunch of warnings
|
64 |
|
65 | # Hm this respects $PATH, finds python
|
66 | time wine "$BASH" -c 'echo "hi from bash"; python.exe -c "print(\"hi from python3\")"'
|
67 |
|
68 | #time wine "$GIT_BASH" -c 'echo hi'
|
69 | }
|
70 |
|
71 | test-gcc() {
|
72 | echo '
|
73 | #include <iostream>
|
74 | int main() {
|
75 | std::cout << "Hello from C++ in Wine!" << std::endl;
|
76 | return 0;
|
77 | }' > $DIR/hello.cpp
|
78 |
|
79 | wine cmd /c "g++ $DIR/hello.cpp -o $DIR/hello.exe"
|
80 |
|
81 | wine $DIR/hello.exe
|
82 |
|
83 | }
|
84 |
|
85 | test-mkdir() {
|
86 | # need to use \ separators
|
87 | wine cmd /c "mkdir $DIR\\win\\32\\test"
|
88 | }
|
89 |
|
90 | build-create-process() {
|
91 | mkdir -p $DIR
|
92 | wine cmd /c "g++ win32/create-process.c -o $DIR/create-process.exe"
|
93 | }
|
94 |
|
95 | run-create-process() {
|
96 | wine $DIR/create-process.exe
|
97 | }
|
98 |
|
99 | test-powershell() {
|
100 | # this doesn't work? It's a stub?
|
101 | wine cmd /c 'powershell.exe -Command "Write-Host hello from powershell"'
|
102 | }
|
103 |
|
104 | test-pipelines() {
|
105 | #wine cmd /c 'dir win32/demo_asyncio.py'
|
106 |
|
107 | echo 'UNIX SUBPROCESS'
|
108 | win32/demo_subprocess.py
|
109 | echo
|
110 |
|
111 | echo 'UNIX ASYNCIO'
|
112 | win32/demo_asyncio.py
|
113 | echo
|
114 |
|
115 | echo 'WIN32 SUBPROCESS'
|
116 | wine cmd /c 'python.exe win32/demo_subprocess.py'
|
117 | echo
|
118 |
|
119 | echo 'WIN32 ASYNCIO'
|
120 | wine cmd /c 'python.exe win32/demo_asyncio.py'
|
121 | }
|
122 |
|
123 | readonly WIN32_TAR_DIR=_tmp/hello-tar-win32
|
124 |
|
125 | extract-tar() {
|
126 | local tmp=$WIN32_TAR_DIR
|
127 |
|
128 | rm -r -f $tmp
|
129 | mkdir -p $tmp
|
130 | pushd $tmp
|
131 |
|
132 | tar -x < ../../_release/hello.tar
|
133 |
|
134 | popd
|
135 | }
|
136 |
|
137 | test-mycpp-hello() {
|
138 | extract-tar
|
139 |
|
140 | # Uh why are error messages missing filenames?
|
141 |
|
142 | time wine "$BASH" -c '
|
143 | echo "hi from bash"
|
144 |
|
145 | tar_dir=$1
|
146 |
|
147 | cd $tar_dir/hello-0.29.0
|
148 |
|
149 | ls
|
150 |
|
151 | touch _build/detected-cpp-config.h
|
152 |
|
153 | _build/hello.bat
|
154 |
|
155 | ' dummy $WIN32_TAR_DIR
|
156 |
|
157 | run-hello
|
158 | }
|
159 |
|
160 | run-hello() {
|
161 | local hello=$WIN32_TAR_DIR/hello-0.29.0/_bin/cxx-dbg/hello.exe
|
162 |
|
163 | set +o errexit
|
164 |
|
165 | time wine $hello
|
166 | echo status=$?
|
167 |
|
168 | time wine $hello a b c
|
169 | echo status=$?
|
170 | }
|
171 |
|
172 | OLD-test-mycpp-hello() {
|
173 | #wine cmd /c 'cd _tmp/hello-tar-test/hello-0.29.0; bash.exe -c "echo bash"'
|
174 |
|
175 | extract-tar
|
176 |
|
177 | local my_mkdir="$WIN32_TAR_DIR/hello-0.29.0/_build/my-mkdir.sh"
|
178 | pwd
|
179 | set -x
|
180 | ls -l $(dirname $my_mkdir)
|
181 |
|
182 | cat >$my_mkdir <<'EOF'
|
183 | #!/bin/sh
|
184 |
|
185 | . build/ninja-rules-cpp.sh
|
186 |
|
187 | set -x
|
188 | echo 'my-mkdir'
|
189 | main() {
|
190 | local compiler=g++
|
191 | local variant=opt
|
192 | local translator=mycpp
|
193 |
|
194 | which mkdir
|
195 | type mkdir
|
196 | command -v mkdir
|
197 | ls -l /usr/bin/mkdir
|
198 | file /usr/bin/mkdir
|
199 |
|
200 | mkdir -p \
|
201 | "_bin/$compiler-$variant-sh/$translator" \
|
202 | "_build/obj/$compiler-$variant-sh/_gen/bin" \
|
203 | "_build/obj/$compiler-$variant-sh/mycpp"
|
204 | echo mkdir=$?
|
205 | }
|
206 | main "$@"
|
207 |
|
208 | EOF
|
209 | chmod +x $my_mkdir
|
210 | ls -l $my_mkdir
|
211 |
|
212 | time wine "$BASH" -c '
|
213 | echo "hi from bash"
|
214 |
|
215 | set -o errexit
|
216 |
|
217 | # cross-shell tracing works!
|
218 | set -x
|
219 | pwd
|
220 |
|
221 | # mkdir works!
|
222 | mkdir -p _tmp/hi-from-wine _tmp/hi2
|
223 | echo mkdir hi=$?
|
224 |
|
225 | cd _tmp/hello-tar-win32/hello-0.29.0
|
226 | pwd
|
227 | ls -l
|
228 |
|
229 | #export SHELLOPTS
|
230 |
|
231 | # g++ to /dev/null fails here
|
232 | # ./configure --cxx-for-configure g++
|
233 |
|
234 | # fake it
|
235 | touch _build/detected-config.sh
|
236 |
|
237 | # git-bash bug: This causes a segmentation fault when there is no shebang!
|
238 | _build/my-mkdir.sh
|
239 |
|
240 | set +o errexit
|
241 |
|
242 | _build/oils.sh --cxx g++
|
243 |
|
244 | echo status=$?
|
245 | '
|
246 | }
|
247 |
|
248 | OLD-test-mkdir() {
|
249 | #wine cmd /c 'cd _tmp/hello-tar-test/hello-0.29.0; bash.exe -c "echo bash"'
|
250 |
|
251 | chmod +x _tmp/hello-tar-test/hello-0.29.0/_build/mkdir-test.sh
|
252 |
|
253 | time wine "$BASH" -c '
|
254 | echo "hi from bash"
|
255 |
|
256 | set -o errexit
|
257 |
|
258 | # cross-shell tracing works!
|
259 | set -x
|
260 |
|
261 | # mkdir works!
|
262 | mkdir -p _tmp/hi-from-wine
|
263 |
|
264 | cd _tmp/hello-tar-test/hello-0.29.0
|
265 | pwd
|
266 | ls -l
|
267 |
|
268 | set +e
|
269 | mkdir -p _bin/cxx-opt-sh/mycpp _build/obj/cxx-opt-sh/_gen/bin _build/obj/cxx-opt-sh/mycpp
|
270 | echo mkdir=$?
|
271 |
|
272 | _build/mkdir-test.sh
|
273 | '
|
274 | }
|
275 |
|
276 | "$@"
|