-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute.cmd
236 lines (182 loc) · 7.94 KB
/
execute.cmd
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
::
:: NAME
::
:: execute - source code execution script for Microsoft Windows
::
:: SYNOPSIS
::
:: execute SOURCE
::
:: DESCRIPTION
::
:: This script chooses the proper toolchain to (optionally) compile and then
:: execute a C/C++, PHP, JavaScript, TypeScript, Python, Bash, Docker or the
:: docker-compose YML source code.
::
:: Use "execute SOURCE" to execute the desired source files, where SOURCE is
:: the wild card mask of the desired files.
::
:: COPYRIGHT
::
:: Copyright 2018 Quasis - The MIT Licence
::
@echo off
@setLocal enableDelayedExpansion
@set DenoHome=%ProgramFiles%\Deno
@set DockerHome=%ProgramFiles%\Docker
@set LLVMHome=%ProgramFiles%\LLVM
@set NodeHome=%ProgramFiles%\Node
@set PHPHome=%ProgramFiles%\PHP
@set PythonHome=%ProgramFiles%\Python
@set WSLHome=%WINDIR%\System32
:execute
setLocal
set source=%~1
if "%source%" equ "" (
echo No source file specified && exit /b 1
)
for %%f in (%source%) do if exist "%%f" (
if "%%~xf" == ".cmd" (call "%%f")
if "%%~xf" == ".h" (call :c "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".c" (call :c "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".hh" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".cc" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".hpp" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".cpp" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".hxx" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".cxx" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".h++" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".c++" (call :cpp "%%f" "%TEMP%\%%~nf")
if "%%~xf" == ".js" (call :js "%%f")
if "%%~xf" == ".ts" (call :js "%%f")
if "%%~xf" == ".php" (call :php "%%f")
if "%%~xf" == ".py" (call :py "%%f")
if "%%~xf" == ".rs" (call :rs "%%f" "%TEMP%\%%~nf")
if "%%~nxf" == "Cargo.toml" (call :cargo "%%f" "%TEMP%")
if "%%~xf" == ".sh" (call :sh "%%f" "./%%~nxf")
if "%%~xf" == ".mk" (call :makefile "%%f")
if "%%~xf" == ".makefile" (call :makefile "%%f")
if "%%~xnf" == "Makefile" (call :makefile "%%f")
if "%%~xf" == ".dockerfile" (call :dockerfile "%%f")
if "%%~nxf" == "Dockerfile" (call :dockerfile "%%f")
if "%%~nxf" == "docker-compose.yaml" (call :dockercompose "%%f")
if "%%~nxf" == "docker-compose.yml" (call :dockercompose "%%f")
if "%%~nxf" == "compose.yaml" (call :dockercompose "%%f")
if "%%~nxf" == "compose.yml" (call :dockercompose "%%f")
if "%%~nxf" == "stack.yaml" (call :dockercompose "%%f")
if "%%~nxf" == "stack.yml" (call :dockercompose "%%f")
)
endLocal
goto :eof
:c
set "source=%~1"
set "target=%~2"
set /p header=< "!source!"
if "!header:~0,3!" == "/*^!" (
"%WSLHome%\wsl.exe" -u root sh -c "!header:~3!"
) else if exist "%LLVMHome%\bin\clang.exe" (
"%LLVMHome%\bin\clang.exe" -Wall -Wextra -Wpedantic -O3 -s -m64 -static --target=x86_64-pc-windows-msvc "!source!" -o "!target!.exe" && "!target!.exe"
) else if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "clang -Wall -Wextra -Wpedantic -O3 -s -m64 -static '$(wslpath -au !source:\=/!)' -o '$(wslpath -au !target:\=/!)' && ls -l '$(wslpath -au !target:\=/!)' && exec '$(wslpath -au !target:\=/!)'"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:cpp
set "source=%~1"
set "target=%~2"
set /p header=< "!source!"
if "!header:~0,3!" == "/*^!" (
"%WSLHome%\wsl.exe" -u root sh -c "!header:~3!"
) else if exist "%LLVMHome%\bin\clang++.exe" (
"%LLVMHome%\bin\clang++.exe" -xc++ -std=c++2b -Wall -Wextra -Wpedantic -O3 -s -m64 -static --target=x86_64-pc-windows-msvc "!source!" -o "!target!.exe" && "!target!.exe"
) else if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "clang++ -xc++ -std=c++2b -Wall -Wextra -Wpedantic -O3 -s -m64 '$(wslpath -au !source:\=/!)' -o '$(wslpath -au !target:\=/!)' && ls -l '$(wslpath -au !target:\=/!)' && exec '$(wslpath -au !target:\=/!)'"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:js
set "source=%~1"
if exist "%DenoHome%\deno.exe" (
set NO_COLOR=1 && "%DenoHome%\deno.exe" run --allow-all "!source!"
) else if exist "%NodeHome%\node.exe" (
"%NodeHome%\node.exe" "!source!"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:php
set "source=%~1"
if exist "%PHPHome%\php.exe" (
"%PHPHome%\php.exe" "!source!"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:py
set "source=%~1"
if exist "%PythonHome%\python.exe" (
"%PythonHome%\python.exe" -B "!source!"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:rs
set "source=%~1"
set "target=%~2"
set /p header=< "!source!"
if "!header:~0,3!" == "/*^!" (
"%WSLHome%\wsl.exe" -u root sh -c "!header:~3!"
) else if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "rustc -Ccodegen-units=1 -Copt-level=3 -Cstrip=symbols -Cprefer-dynamic=yes '$(wslpath -au !source:\=/!)' -o '$(wslpath -au !target:\=/!)' && ls -l '$(wslpath -au !target:\=/!)' && exec '$(wslpath -au !target:\=/!)'"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:cargo
set "source=%~1"
set "target=%~2"
if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "cargo run --release --manifest-path '$(wslpath -au !source:\=/!)' --target-dir '$(wslpath -au !target:\=/!)'"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:sh
set "source=%~1"
if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root "$(wslpath -au !source:\=/!)"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:makefile
set "source=%~1"
if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "make -f $(wslpath -au !source:\=/!)"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:dockerfile
set "source=%~1"
if exist "%DockerHome%\docker.exe" (
"%DockerHome%\docker.exe" rm --force auto && "%DockerHome%\docker.exe" buildx build --network host --file="!source!" --tag auto:latest . && "%DockerHome%\docker.exe" run --rm --network host --name=auto auto:latest
) else if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "docker rm --force auto && docker buildx build --network host --file='$(wslpath -au !source:\=/!)' --tag auto:latest . && docker run --rm --network host --user $USER -v $(pwd):/mnt/cwd --name=auto auto:latest"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:dockercompose
set "source=%~1"
if exist "%DockerHome%\docker.exe" (
"%DockerHome%\docker.exe" compose --file "!source!" up --build --force-recreate --renew-anon-volumes --remove-orphans
) else if exist "%WSLHome%\wsl.exe" (
"%WSLHome%\wsl.exe" -u root sh -c "DOCKER_BUILDKIT=1 docker compose --file '$(wslpath -au !source:\=/!)' up --build --force-recreate --renew-anon-volumes --remove-orphans"
) else (
echo Failed to locate execution chain for "!source!" && exit /b 1
)
goto :eof
:eof