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

235 lines, 79 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
85build-create-process() {
86 wine cmd /c "g++ win32/create-process.c -o $DIR/create-process.exe"
87}
88
89run-create-process() {
90 wine $DIR/create-process.exe
91}
92
93test-powershell() {
94 # this doesn't work? It's a stub?
95 wine cmd /c 'powershell.exe -Command "Write-Host hello from powershell"'
96}
97
98test-pipelines() {
99 #wine cmd /c 'dir win32/demo_asyncio.py'
100
101 echo 'UNIX SUBPROCESS'
102 win32/demo_subprocess.py
103 echo
104
105 echo 'UNIX ASYNCIO'
106 win32/demo_asyncio.py
107 echo
108
109 echo 'WIN32 SUBPROCESS'
110 wine cmd /c 'python.exe win32/demo_subprocess.py'
111 echo
112
113 echo 'WIN32 ASYNCIO'
114 wine cmd /c 'python.exe win32/demo_asyncio.py'
115}
116
117readonly WIN32_TAR_DIR=_tmp/hello-tar-win32
118
119extract-tar() {
120 local tmp=$WIN32_TAR_DIR
121
122 rm -r -f $tmp
123 mkdir -p $tmp
124 pushd $tmp
125
126 tar -x < ../../_release/hello.tar
127
128 popd
129}
130
131test-mycpp-hello() {
132 #wine cmd /c 'cd _tmp/hello-tar-test/hello-0.29.0; bash.exe -c "echo bash"'
133
134 extract-tar
135
136 local my_mkdir="$WIN32_TAR_DIR/hello-0.29.0/_build/my-mkdir.sh"
137 pwd
138 set -x
139 ls -l $(dirname $my_mkdir)
140
141 cat >$my_mkdir <<'EOF'
142#!/bin/sh
143
144. build/ninja-rules-cpp.sh
145
146set -x
147echo 'my-mkdir'
148main() {
149 local compiler=g++
150 local variant=opt
151 local translator=mycpp
152
153 which mkdir
154 type mkdir
155 command -v mkdir
156 ls -l /usr/bin/mkdir
157 file /usr/bin/mkdir
158
159 mkdir -p \
160 "_bin/$compiler-$variant-sh/$translator" \
161 "_build/obj/$compiler-$variant-sh/_gen/bin" \
162 "_build/obj/$compiler-$variant-sh/mycpp"
163 echo mkdir=$?
164}
165main "$@"
166
167EOF
168 chmod +x $my_mkdir
169 ls -l $my_mkdir
170
171 time wine "$BASH" -c '
172echo "hi from bash"
173
174set -o errexit
175
176# cross-shell tracing works!
177set -x
178pwd
179
180# mkdir works!
181mkdir -p _tmp/hi-from-wine _tmp/hi2
182echo mkdir hi=$?
183
184cd _tmp/hello-tar-win32/hello-0.29.0
185pwd
186ls -l
187
188#export SHELLOPTS
189
190# g++ to /dev/null fails here
191# ./configure --cxx-for-configure g++
192
193# fake it
194touch _build/detected-config.sh
195
196# git-bash bug: This causes a segmentation fault when there is no shebang!
197_build/my-mkdir.sh
198
199set +o errexit
200
201_build/oils.sh --cxx g++
202
203echo status=$?
204'
205}
206
207test-mkdir() {
208 #wine cmd /c 'cd _tmp/hello-tar-test/hello-0.29.0; bash.exe -c "echo bash"'
209
210 chmod +x _tmp/hello-tar-test/hello-0.29.0/_build/mkdir-test.sh
211
212 time wine "$BASH" -c '
213echo "hi from bash"
214
215set -o errexit
216
217# cross-shell tracing works!
218set -x
219
220# mkdir works!
221mkdir -p _tmp/hi-from-wine
222
223cd _tmp/hello-tar-test/hello-0.29.0
224pwd
225ls -l
226
227set +e
228mkdir -p _bin/cxx-opt-sh/mycpp _build/obj/cxx-opt-sh/_gen/bin _build/obj/cxx-opt-sh/mycpp
229echo mkdir=$?
230
231_build/mkdir-test.sh
232'
233}
234
235"$@"