summaryrefslogtreecommitdiff
path: root/lib/delphi/test/codegen/run-Pascal-Codegen-Tests.bat.tmpl
blob: 79cf0e3396af8265cf2bbc35add21938e6c476d9 (plain)
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
REM /*
REM * Licensed to the Apache Software Foundation (ASF) under one
REM * or more contributor license agreements. See the NOTICE file
REM * distributed with this work for additional information
REM * regarding copyright ownership. The ASF licenses this file
REM * to you under the Apache License, Version 2.0 (the
REM * "License"); you may not use this file except in compliance
REM * with the License. You may obtain a copy of the License at
REM *
REM *   http://www.apache.org/licenses/LICENSE-2.0
REM *
REM * Unless required by applicable law or agreed to in writing,
REM * software distributed under the License is distributed on an
REM * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
REM * KIND, either express or implied. See the License for the
REM * specific language governing permissions and limitations
REM * under the License.
REM */
@echo off
if ""=="%1" goto CONFIG
goto HANDLEDIR

REM -----------------------------------------------------
:CONFIG
REM -----------------------------------------------------

rem * CONFIGURATION BEGIN
rem * configuration settings, adjust as necessary to meet your system setup
set SVNWORKDIR=
set MY_THRIFT_FILES=
set BIN=C:\MSys10\local\bin
set MINGW_BIN=C:\MinGW\bin
set DCC=
set SUBDIR=gen-delphi
rem * CONFIGURATION END


REM -----------------------------------------------------
:START
REM -----------------------------------------------------

rem * configured?
if "%SVNWORKDIR%"=="" goto CONFIG_ERROR

rem * try to find dcc32.exe
echo Looking for dcc32.exe ...
if not exist "%DCC%" set DCC=%ProgramFiles%\Embarcadero\RAD Studio\8.0\bin\dcc32.exe
if not exist "%DCC%" set DCC=%ProgramFiles(x86)%\Embarcadero\RAD Studio\8.0\bin\dcc32.exe
if not exist "%DCC%" goto CONFIG_ERROR
echo Found %DCC%
echo.

rem * some helpers
set PATH=%BIN%;%MINGW_BIN%;%PATH%
set TARGET=%SVNWORKDIR%\..\thrift-testing
set SOURCE=%SVNWORKDIR%
set TESTAPP=TestProject
set UNITSEARCH=%SOURCE%\lib\pas\src;%SOURCE%\lib\delphi\src
set OUTDCU="%TARGET%\dcu"
set LOGFILE=%TARGET%\%SUBDIR%\codegen.log

rem * create and/or empty target dirs
if not exist "%TARGET%"           md "%TARGET%"
if not exist "%TARGET%\%SUBDIR%"  md "%TARGET%\%SUBDIR%"
if not exist "%OUTDCU%"           md "%OUTDCU%"
if exist "%TARGET%\*.thrift"      del "%TARGET%\*.thrift"       /Q
if exist "%TARGET%\%SUBDIR%\*.*"  del "%TARGET%\%SUBDIR%\*.*"   /Q
if exist "%OUTDCU%\*.*"           del "%OUTDCU%\*.*"            /Q

rem init logfile
echo Errors > "%LOGFILE%"
echo ---------------- >> "%LOGFILE%"

rem * recurse through thrift WC and "my thrift files" folder
rem * copies all .thrift files into thrift-testing
call %0 %SOURCE%
if not "%MY_THRIFT_FILES%"=="" call %0 %MY_THRIFT_FILES%

rem * compile all thrift files, generate PAS and C++ code
echo.
echo Generating code, please wait ...
cd "%TARGET%"
for %%a in (*.thrift) do "%BIN%\thrift.exe" -v --gen delphi:register_types,constprefix,events,xmldoc "%%a" 2>> "%LOGFILE%"
REM * for %%a in (*.thrift) do "%BIN%\thrift.exe" -v --gen cpp "%%a" >> NUL:
cmd /c start notepad "%LOGFILE%"
cd ..

rem * check for special Delphi testcases being processed
if not exist "%TARGET%\%SUBDIR%\ReservedKeywords.pas" goto TESTCASE_MISSING


rem * generate a minimal DPR file that uses all generated pascal units
cd "%TARGET%\%SUBDIR%\"
if exist inherited.*  ren inherited.*  _inherited.*
echo program %TESTAPP%;                                           > %TESTAPP%.dpr
echo {$APPTYPE CONSOLE}                                          >> %TESTAPP%.dpr
echo.                                                            >> %TESTAPP%.dpr
echo uses                                                        >> %TESTAPP%.dpr
for %%a in (*.pas) do echo   %%~na,                              >> %TESTAPP%.dpr
echo   Windows, Classes, SysUtils;                               >> %TESTAPP%.dpr
echo.                                                            >> %TESTAPP%.dpr
echo begin                                                       >> %TESTAPP%.dpr
echo   Writeln('Successfully compiled!');                        >> %TESTAPP%.dpr
echo   Writeln('List of units:');                                >> %TESTAPP%.dpr
for %%a in (*.pas) do echo   Write('%%~na':30,'':10);            >> %TESTAPP%.dpr
echo   Writeln;                                                  >> %TESTAPP%.dpr
echo end.                                                        >> %TESTAPP%.dpr
echo.                                                            >> %TESTAPP%.dpr
cd ..\..

rem * try to compile the DPR
rem * this should not throw any errors, warnings or hints
"%DCC%"  -B "%TARGET%\%SUBDIR%\%TESTAPP%" -U"%UNITSEARCH%" -I"%UNITSEARCH%" -N"%OUTDCU%" -E"%TARGET%\%SUBDIR%"
dir "%TARGET%\%SUBDIR%\%TESTAPP%.exe"
if not exist "%TARGET%\%SUBDIR%\%TESTAPP%.exe"  goto CODEGEN_FAILED
echo.
echo -----------------------------------------------------------------
echo The compiled program is now executed. If it hangs or crashes, we
echo have a serious problem with the generated code. Expected output
echo is "Successfully compiled:" followed by a list of generated units.
echo -----------------------------------------------------------------
"%TARGET%\%SUBDIR%\%TESTAPP%.exe"
echo -----------------------------------------------------------------
echo.
pause
GOTO EOF

REM -----------------------------------------------------
:DXE_NOT_FOUND
REM -----------------------------------------------------
echo Delphi Compiler (dcc32.exe) not found.
echo Please check the "DCC" setting in this batch.
echo.
cmd /c start notepad README.MD
cmd /c start notepad %0
pause
GOTO EOF


REM -----------------------------------------------------
:CONFIG_ERROR
REM -----------------------------------------------------
echo Missing, incomplete or wrong configuration settings!
cmd /c start notepad README.MD
cmd /c start notepad %0
pause
GOTO EOF


REM -----------------------------------------------------
:TESTCASE_MISSING
REM -----------------------------------------------------
echo Missing an expected Delphi testcase!
pause
GOTO EOF


REM -----------------------------------------------------
:CODEGEN_FAILED
REM -----------------------------------------------------
echo Code generation FAILED!
pause
GOTO EOF


REM -----------------------------------------------------
:HANDLEDIR
REM -----------------------------------------------------
REM echo %1
for /D %%a in (%1\*) do call %0 %%a
if exist "%1\*.thrift"   copy /b "%1\*.thrift" "%TARGET%\*.*"
GOTO EOF


REM -----------------------------------------------------
:EOF
REM -----------------------------------------------------