blob: 439854537e9614dcd187fa725c7bb3f6c7757524 [file] [log] [blame]
Jens Geyer703200c2014-04-15 21:54:55 +02001REM /*
2REM * Licensed to the Apache Software Foundation (ASF) under one
3REM * or more contributor license agreements. See the NOTICE file
4REM * distributed with this work for additional information
5REM * regarding copyright ownership. The ASF licenses this file
6REM * to you under the Apache License, Version 2.0 (the
7REM * "License"); you may not use this file except in compliance
8REM * with the License. You may obtain a copy of the License at
9REM *
10REM * http://www.apache.org/licenses/LICENSE-2.0
11REM *
12REM * Unless required by applicable law or agreed to in writing,
13REM * software distributed under the License is distributed on an
14REM * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15REM * KIND, either express or implied. See the License for the
16REM * specific language governing permissions and limitations
17REM * under the License.
18REM */
Roger Meier5b9693c2012-02-28 19:32:55 +000019@echo off
20if ""=="%1" goto CONFIG
21goto HANDLEDIR
22
23REM -----------------------------------------------------
24:CONFIG
25REM -----------------------------------------------------
26
27rem * CONFIGURATION BEGIN
28rem * configuration settings, adjust as necessary to meet your system setup
29set SVNWORKDIR=
30set MY_THRIFT_FILES=
31set BIN=C:\MSys10\local\bin
32set MINGW_BIN=C:\MinGW\bin
33set DCC=
34set SUBDIR=gen-delphi
35rem * CONFIGURATION END
36
37
38REM -----------------------------------------------------
39:START
40REM -----------------------------------------------------
41
42rem * configured?
43if "%SVNWORKDIR%"=="" goto CONFIG_ERROR
44
45rem * try to find dcc32.exe
46echo Looking for dcc32.exe ...
47if not exist "%DCC%" set DCC=%ProgramFiles%\Embarcadero\RAD Studio\8.0\bin\dcc32.exe
48if not exist "%DCC%" set DCC=%ProgramFiles(x86)%\Embarcadero\RAD Studio\8.0\bin\dcc32.exe
49if not exist "%DCC%" goto CONFIG_ERROR
50echo Found %DCC%
51echo.
52
53rem * some helpers
54set PATH=%BIN%;%MINGW_BIN%;%PATH%
55set TARGET=%SVNWORKDIR%\..\thrift-testing
56set SOURCE=%SVNWORKDIR%
57set TESTAPP=TestProject
58set UNITSEARCH=%SOURCE%\lib\pas\src;%SOURCE%\lib\delphi\src
59set OUTDCU="%TARGET%\dcu"
60set LOGFILE=%TARGET%\%SUBDIR%\codegen.log
61
62rem * create and/or empty target dirs
63if not exist "%TARGET%" md "%TARGET%"
64if not exist "%TARGET%\%SUBDIR%" md "%TARGET%\%SUBDIR%"
Jens Geyerd5436f52014-10-03 19:50:38 +020065if not exist "%OUTDCU%" md "%OUTDCU%"
Roger Meier5b9693c2012-02-28 19:32:55 +000066if exist "%TARGET%\*.thrift" del "%TARGET%\*.thrift" /Q
67if exist "%TARGET%\%SUBDIR%\*.*" del "%TARGET%\%SUBDIR%\*.*" /Q
68if exist "%OUTDCU%\*.*" del "%OUTDCU%\*.*" /Q
69
70rem * recurse through thrift WC and "my thrift files" folder
71rem * copies all .thrift files into thrift-testing
72call %0 %SOURCE%
73if not "%MY_THRIFT_FILES%"=="" call %0 %MY_THRIFT_FILES%
74
75rem * compile all thrift files, generate PAS and C++ code
76echo.
77echo Generating code, please wait ...
78cd "%TARGET%"
Jens Geyerd95fc9b2014-02-02 18:08:31 +010079for %%a in (*.thrift) do "%BIN%\thrift.exe" -v --gen delphi:ansistr_binary,register_types,constprefix,events,xmldoc "%%a" 2>> "%LOGFILE%"
Roger Meier5b9693c2012-02-28 19:32:55 +000080REM * for %%a in (*.thrift) do "%BIN%\thrift.exe" -v --gen cpp "%%a" >> NUL:
81cmd /c start notepad "%LOGFILE%"
82cd ..
83
84rem * check for special Delphi testcases being processed
85if not exist "%TARGET%\%SUBDIR%\ReservedKeywords.pas" goto TESTCASE_MISSING
86
87
88rem * generate a minimal DPR file that uses all generated pascal units
89cd "%TARGET%\%SUBDIR%\"
90if exist inherited.* ren inherited.* _inherited.*
Jens Geyerd5436f52014-10-03 19:50:38 +020091echo program %TESTAPP%; > %TESTAPP%.dpr
92echo {$APPTYPE CONSOLE} >> %TESTAPP%.dpr
93echo. >> %TESTAPP%.dpr
94echo uses >> %TESTAPP%.dpr
95for %%a in (*.pas) do echo %%~na, >> %TESTAPP%.dpr
96echo Windows, Classes, SysUtils; >> %TESTAPP%.dpr
97echo. >> %TESTAPP%.dpr
98echo begin >> %TESTAPP%.dpr
99echo Writeln('Successfully compiled!'); >> %TESTAPP%.dpr
100echo Writeln('List of units:'); >> %TESTAPP%.dpr
101for %%a in (*.pas) do echo Write('%%~na':30,'':10); >> %TESTAPP%.dpr
102echo Writeln; >> %TESTAPP%.dpr
103echo end. >> %TESTAPP%.dpr
104echo. >> %TESTAPP%.dpr
Roger Meier5b9693c2012-02-28 19:32:55 +0000105cd ..\..
106
107rem * try to compile the DPR
108rem * this should not throw any errors, warnings or hints
Jens Geyerd5436f52014-10-03 19:50:38 +0200109"%DCC%" -B "%TARGET%\%SUBDIR%\%TESTAPP%" -U"%UNITSEARCH%" -I"%UNITSEARCH%" -N"%OUTDCU%" -E"%TARGET%\%SUBDIR%"
Roger Meier5b9693c2012-02-28 19:32:55 +0000110dir "%TARGET%\%SUBDIR%\%TESTAPP%.exe"
111if not exist "%TARGET%\%SUBDIR%\%TESTAPP%.exe" goto CODEGEN_FAILED
112echo.
113echo -----------------------------------------------------------------
114echo The compiled program is now executed. If it hangs or crashes, we
Jens Geyerd5436f52014-10-03 19:50:38 +0200115echo have a serious problem with the generated code. Expected output
Roger Meier5b9693c2012-02-28 19:32:55 +0000116echo is "Successfully compiled:" followed by a list of generated units.
117echo -----------------------------------------------------------------
118"%TARGET%\%SUBDIR%\%TESTAPP%.exe"
119echo -----------------------------------------------------------------
120echo.
121pause
122GOTO EOF
123
124REM -----------------------------------------------------
125:DXE_NOT_FOUND
126REM -----------------------------------------------------
Jens Geyerd5436f52014-10-03 19:50:38 +0200127echo Delphi Compiler (dcc32.exe) not found.
Roger Meier5b9693c2012-02-28 19:32:55 +0000128echo Please check the "DCC" setting in this batch.
129echo.
Jens Geyerc02618c2014-04-10 01:16:48 +0200130cmd /c start notepad README.MD
Roger Meier5b9693c2012-02-28 19:32:55 +0000131cmd /c start notepad %0
132pause
133GOTO EOF
134
135
136REM -----------------------------------------------------
137:CONFIG_ERROR
138REM -----------------------------------------------------
139echo Missing, incomplete or wrong configuration settings!
Jens Geyerc02618c2014-04-10 01:16:48 +0200140cmd /c start notepad README.MD
Roger Meier5b9693c2012-02-28 19:32:55 +0000141cmd /c start notepad %0
142pause
143GOTO EOF
144
145
146REM -----------------------------------------------------
147:TESTCASE_MISSING
148REM -----------------------------------------------------
149echo Missing an expected Delphi testcase!
150pause
151GOTO EOF
152
153
154REM -----------------------------------------------------
155:CODEGEN_FAILED
156REM -----------------------------------------------------
157echo Code generation FAILED!
158pause
159GOTO EOF
160
161
162REM -----------------------------------------------------
163:HANDLEDIR
164REM -----------------------------------------------------
165REM echo %1
166for /D %%a in (%1\*) do call %0 %%a
167if exist "%1\*.thrift" copy /b "%1\*.thrift" "%TARGET%\*.*"
168GOTO EOF
169
170
171REM -----------------------------------------------------
172:EOF
173REM -----------------------------------------------------