OILS / win32 / deps.sh View on Github | oils.pub

276 lines, 97 significant
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
23set -o nounset
24set -o pipefail
25set -o errexit
26
27
28readonly DIR=_tmp/win32
29
30my-curl() {
31 curl --location --continue-at - \
32 --remote-name --output-dir $DIR "$@"
33}
34
35download() {
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
47find-python() {
48 find ~/.wine/drive_c/|grep python.exe
49}
50
51test-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
58readonly BASH=~/'.wine/drive_c/Program Files/Git/bin/bash.exe'
59readonly GIT_BASH=~/'.wine/drive_c/Program Files/Git/git-bash.exe'
60
61test-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
71test-gcc() {
72 echo '
73#include <iostream>
74int 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
85test-mkdir() {
86 # need to use \ separators
87 wine cmd /c "mkdir $DIR\\win\\32\\test"
88}
89
90build-create-process() {
91 mkdir -p $DIR
92 wine cmd /c "g++ win32/create-process.c -o $DIR/create-process.exe"
93}
94
95run-create-process() {
96 wine $DIR/create-process.exe
97}
98
99test-powershell() {
100 # this doesn't work? It's a stub?
101 wine cmd /c 'powershell.exe -Command "Write-Host hello from powershell"'
102}
103
104test-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
123readonly WIN32_TAR_DIR=_tmp/hello-tar-win32
124
125extract-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
137test-mycpp-hello() {
138 extract-tar
139
140 # Uh why are error messages missing filenames?
141
142 time wine "$BASH" -c '
143echo "hi from bash"
144
145tar_dir=$1
146
147cd $tar_dir/hello-0.29.0
148
149ls
150
151touch _build/detected-cpp-config.h
152
153_build/hello.bat
154
155' dummy $WIN32_TAR_DIR
156
157 run-hello
158}
159
160run-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
172OLD-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
187set -x
188echo 'my-mkdir'
189main() {
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}
206main "$@"
207
208EOF
209 chmod +x $my_mkdir
210 ls -l $my_mkdir
211
212 time wine "$BASH" -c '
213echo "hi from bash"
214
215set -o errexit
216
217# cross-shell tracing works!
218set -x
219pwd
220
221# mkdir works!
222mkdir -p _tmp/hi-from-wine _tmp/hi2
223echo mkdir hi=$?
224
225cd _tmp/hello-tar-win32/hello-0.29.0
226pwd
227ls -l
228
229#export SHELLOPTS
230
231# g++ to /dev/null fails here
232# ./configure --cxx-for-configure g++
233
234# fake it
235touch _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
240set +o errexit
241
242_build/oils.sh --cxx g++
243
244echo status=$?
245'
246}
247
248OLD-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 '
254echo "hi from bash"
255
256set -o errexit
257
258# cross-shell tracing works!
259set -x
260
261# mkdir works!
262mkdir -p _tmp/hi-from-wine
263
264cd _tmp/hello-tar-test/hello-0.29.0
265pwd
266ls -l
267
268set +e
269mkdir -p _bin/cxx-opt-sh/mycpp _build/obj/cxx-opt-sh/_gen/bin _build/obj/cxx-opt-sh/mycpp
270echo mkdir=$?
271
272_build/mkdir-test.sh
273'
274}
275
276"$@"