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