-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild64.bat
410 lines (360 loc) · 14.4 KB
/
build64.bat
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
@echo off
setlocal enabledelayedexpansion
rem Check for help argument
if "%1"=="/?" goto :show_help
if "%1"=="-h" goto :show_help
if "%1"=="--help" goto :show_help
set startTime=%time%
echo Create a symlink to overcome CMake error FTK1011
set "LINK_PKG_PATH=C:\ProgramData\BTW\workplace\RSODBCDriver"
:: Ensure parent directory exists
mkdir "C:\ProgramData\BTW\workplace"
:: Check if the path already exists and delete if necessary
IF EXIST "!LINK_PKG_PATH!" (
echo Deleting the directory or junction: !LINK_PKG_PATH!
rmdir /s /q "!LINK_PKG_PATH!"
) else (
echo Directory or junction does not exist: !LINK_PKG_PATH!
)
:: Create the directory junction
echo Creating the directory junction: !LINK_PKG_PATH! and %CD%
mklink /j "!LINK_PKG_PATH!" "%CD%"
dir "!LINK_PKG_PATH!"
echo Create a clean public directory for artifacts
set "RS_ARTIFACTS_DIR=!LINK_PKG_PATH!\public\windows"
mkdir !RS_ARTIFACTS_DIR!
rmdir /s/q !RS_ARTIFACTS_DIR!\*
rem Initialize variables
set WIN_ODBC_BUILD_MSI=""
set "CMAKE_ARGS_ODBC_VERSION="
set RS_BUILD_DIR=
set INSTALL_DIR=
set RS_ROOT_DIR=!LINK_PKG_PATH!
set ENABLE_TESTING=
set RS_OPENSSL_DIR=
set RS_MULTI_DEPS_DIRS=
set RS_DEPS_DIRS=
set RS_ODBC_DIR=
set "RS_VERSION="
set "RS_BUILD_TYPE=Release"
set "BUILD_DEPENDENCIES=yes"
set PYTHON_CMD=
set PERL_CMD=
echo "LINK_PKG_PATH====== dir !LINK_PKG_PATH! ========"
@REM dir !LINK_PKG_PATH!
rem Parse command line arguments
rem https://stackoverflow.com/questions/28103532/how-to-parse-command-line-arguments-with-switch-in-batch-file
:parse_args
if "%~1"=="" goto :end_parse_args
set "temp_option="
for %%a in (%*) do (
if not defined temp_option (
set arg=%%a
if "!arg:~0,1!" equ "-" (
set "temp_option=!arg!"
)
) else (
echo arg=!arg!
echo value=%%a
if "!arg!"=="--version" set "RS_VERSION=%%a"
if "!arg!"=="--build-type" set "RS_BUILD_TYPE=%%a"
if "!arg!"=="--build-dependencies" set "BUILD_DEPENDENCIES=%%a"
if "!arg!"=="--dependencies-src-dir" set "DEPENDENCIES_SRC_DIR=%%a"
if "!arg!"=="--dependencies-build-dir" set "DEPENDENCIES_BUILD_DIR=%%a"
if "!arg!"=="--dependencies-install-dir" set "DEPENDENCIES_INSTALL_DIR=%%a"
set "temp_option!temp_option!=%%a"
set "temp_option="
)
)
:end_parse_args
if not defined DEPENDENCIES_SRC_DIR if "!BUILD_DEPENDENCIES!"=="yes" (
if exist "!LINK_PKG_PATH!\find-dependencies-src-dir.bat" (
:: Hoping to find DEPENDENCIES_SRC_DIR from a helper script
echo "DEPENDENCIES_SRC_DIR does not exist. Finding by Calling !LINK_PKG_PATH!\find-dependencies-src-dir.bat ..."
call !LINK_PKG_PATH!\find-dependencies-src-dir.bat
)
:: Default behavior
if not defined DEPENDENCIES_SRC_DIR (
echo "DEPENDENCIES_SRC_DIR still does not exist. Falling back to default location.
set "DEPENDENCIES_SRC_DIR=!LINK_PKG_PATH!\..\RedshiftODBCDriverDependencies\src\tp"
)
) else (
if defined DEPENDENCIES_SRC_DIR (
echo "skip setting DEPENDENCIES_SRC_DIR because it is already defined."
) else (
echo "skip setting DEPENDENCIES_SRC_DIR because '!BUILD_DEPENDENCIES!' does not equal 'yes'."
)
)
if defined DEPENDENCIES_SRC_DIR (
echo "DEPENDENCIES_SRC_DIR====== dir: !DEPENDENCIES_SRC_DIR! ========"
@REM dir !DEPENDENCIES_SRC_DIR!
echo Try Shortening path using a symbolic link
@REM set "DEPENDENCIES_SRC_DIR_SHORT_PATH=!LINK_PKG_PATH!\depsdir"
set "DEPENDENCIES_SRC_DIR_SHORT_PATH=C:\ProgramData\BTW\workplace\depsdir"
echo "Try Shortening DEPENDENCIES_SRC_DIR(!DEPENDENCIES_SRC_DIR!) to !DEPENDENCIES_SRC_DIR_SHORT_PATH! using a symbolic link
:: Create the symbolic link (if it doesn't exist)
if exist "!DEPENDENCIES_SRC_DIR_SHORT_PATH!" (
echo "Removing existing Symbolic link !DEPENDENCIES_SRC_DIR_SHORT_PATH!"
rmdir !DEPENDENCIES_SRC_DIR_SHORT_PATH!
)
echo "Creating Symbolic link !DEPENDENCIES_SRC_DIR_SHORT_PATH!"
mklink /j "!DEPENDENCIES_SRC_DIR_SHORT_PATH!" "!DEPENDENCIES_SRC_DIR!"
echo "Symbolic link created: !DEPENDENCIES_SRC_DIR_SHORT_PATH! -> !DEPENDENCIES_SRC_DIR!"
:: Reassign DEPENDENCIES_SRC_DIR to the shortened DEPENDENCIES_SRC_DIR_SHORT_PATH
echo "Reassign !DEPENDENCIES_SRC_DIR! to the shortened !DEPENDENCIES_SRC_DIR_SHORT_PATH!"
set "DEPENDENCIES_SRC_DIR=!DEPENDENCIES_SRC_DIR_SHORT_PATH!"
echo "DEPENDENCIES_SRC_DIR is now: !DEPENDENCIES_SRC_DIR!:"
if not exist "!DEPENDENCIES_SRC_DIR!" (
echo "Warning DEPENDENCIES_SRC_DIR (!DEPENDENCIES_SRC_DIR!) does not exist "
) else (
echo "Contents of !DEPENDENCIES_SRC_DIR!:"
dir !DEPENDENCIES_SRC_DIR!
)
)
:: Where to build if the need be
if not defined DEPENDENCIES_BUILD_DIR if !BUILD_DEPENDENCIES!=="yes" (
set "DEPENDENCIES_BUILD_DIR=!LINK_PKG_PATH!\tpbuild"
)
:: Default install directory for installation and/or consumption
if not defined DEPENDENCIES_INSTALL_DIR if defined DEPENDENCIES_SRC_DIR (
set "DEPENDENCIES_INSTALL_DIR=!DEPENDENCIES_SRC_DIR!\install"
)
rem Display parsed arguments
echo Version: !RS_VERSION!
echo Build Type: !RS_BUILD_TYPE!
echo Build Dependencies: !BUILD_DEPENDENCIES!
echo Dependencies Source: !DEPENDENCIES_SRC_DIR!
echo Dependencies Build: !DEPENDENCIES_BUILD_DIR!
echo Dependencies Install: !DEPENDENCIES_INSTALL_DIR!
rem Visual Studio environment settings
set "VS_PATH="
set "cmake_generator=Visual Studio 17 2022"
if "!VS_PATH!"=="" (
echo checking vs candidates
set "vs_path_candidates="
rem List of paths to check
set "vs_path_candidates=!vs_path_candidates!C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools;"
set "vs_path_candidates=!vs_path_candidates!C:\Program Files (x86)\Microsoft Visual Studio\2022\Community;"
set "vs_path_candidates=!vs_path_candidates!C:\Program Files\Microsoft Visual Studio\2022\BuildTools;"
set "vs_path_candidates=!vs_path_candidates!C:\Program Files\Microsoft Visual Studio\2022\Community"
rem Loop through paths and find the first valid one
FOR %%p IN ("!vs_path_candidates:;=";"!") do (
echo checking %%p
if exist "%%p" (
echo setting %%p
set "VS_PATH=%%p"
echo done setting !VS_PATH!
goto :vs_path_found
) else (
echo not found %%p
)
)
) else (
goto :vs_path_found
)
if "!VS_PATH!"=="" (
echo No Visual Studio installation found.
) else (
echo Visual Studio Path using candiates paths: !VS_PATH!
)
:vs_path_found
set "VS_PATH=!VS_PATH:"=!"
echo calling !VS_PATH!\VC\Auxiliary\Build\vcvarsall.bat
call "!VS_PATH!\VC\Auxiliary\Build\vcvarsall.bat" x64
where nmake
rem Absolute paths to the required build tool directories
set "CMAKE_BIN_DIR=!VS_PATH!\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
set "MSBUILD_BIN_DIR=!VS_PATH!\MSBuild\Current\Bin\amd64"
set "VS170COMNTOOLS=!VS_PATH!\Common7\Tools"
rem Find the latest Wix, used for creating MSI
for /d %%D in ("C:\Program Files (x86)\WiX Toolset*") do (
rem Extract the version number
for /f "tokens=1-2 delims=. " %%A in ("%%~nD") do (
if "%%A"=="WiX" (
set CURRENT_VERSION=%%B
rem Compare versions numerically
if !CURRENT_VERSION! GTR !HIGHEST_VERSION! (
set HIGHEST_VERSION=!CURRENT_VERSION!
set HIGHEST_PATH=%%D
)
)
)
)
echo Highest WiX version path: !HIGHEST_PATH!
set "WIX_BIN_DIR=!HIGHEST_PATH!\bin"
rem Ensure that the directories and executables exist
if not exist "!CMAKE_BIN_DIR!\cmake.exe" (
echo Error: cmake.exe not found in "!CMAKE_BIN_DIR!"
exit /b 1
)
if not exist "!MSBUILD_BIN_DIR!\msbuild.exe" (
echo Error: msbuild.exe not found in "!MSBUILD_BIN_DIR!"
exit /b 1
)
if not exist "!WIX_BIN_DIR!\candle.exe" (
echo Error: WiX tools not found in "!WIX_BIN_DIR!"
exit /b 1
)
rem Add build tool directories to the PATH for this script
set "PATH=!CMAKE_BIN_DIR!;!MSBUILD_BIN_DIR!;!WIX_BIN_DIR!;!VS170COMNTOOLS!;!PATH!"
rem Setting few environment variables required for build
SET "SystemDrive=C:"
SET "TMP=C:\Windows\TEMP"
SET "windir=C:\Windows"
rem Process command-line arguments
set argC=0
for %%x in (%*) do Set /A argC+=1
echo "Number of args is %argC%"
echo Building 64 bit Windows Redshift ODBC Driver
rem Process package version
if not "!RS_VERSION!"=="" (
set "CMAKE_ARGS_ODBC_VERSION=-DODBC_VERSION=!RS_VERSION!"
)
REM A separate python based script for building dependencies is provided.
REM You may use it separately or call it within this batch script.
REM Eitherway, we put this clause as a placeholder to invoke the python script
REM from builddeps.bat. You are welcome to replace builddeps.bat with scripts\builddeps.py
if "!BUILD_DEPENDENCIES!"=="yes" (
if exist "builddeps.bat" (
echo "=== Building dependencies ====="
call builddeps.bat
)
)
rem Load environment variables from exports files if they exist
if exist ".\exports_basic.bat" (
call .\exports_basic.bat
echo Loaded exports_basic.bat
)
if exist ".\exports.bat" (
call .\exports.bat
echo Loaded exports.bat
)
echo "batch ENABLE_TESTING=%ENABLE_TESTING%"
rem cmake options
if "%ENABLE_TESTING%" == "" set ENABLE_TESTING=0
rem build and install options
if "%RS_BUILD_DIR%" == "" set "RS_BUILD_DIR=%LINK_PKG_PATH%\cmake-build\%RS_BUILD_TYPE%"
if "%INSTALL_DIR%" == "" set "INSTALL_DIR=%LINK_PKG_PATH%\cmake-build\install"
if not exist "%RS_BUILD_DIR%" mkdir "%RS_BUILD_DIR%" || exit /b %ERRORLEVEL%
@REM Start creating cmake command with various arguments
set "cmake_command=cmake -G "%cmake_generator%" -B "%RS_BUILD_DIR%" -S "%RS_ROOT_DIR%" -DRS_BUILD_TYPE=%RS_BUILD_TYPE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% %CMAKE_ARGS_ODBC_VERSION%"
if "%RS_BUILD_TYPE%"=="Debug" (
set "cmake_command=!cmake_command! -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug"
) else (
set "cmake_command=!cmake_command! -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded"
)
if defined RS_OPENSSL_DIR (
set "cmake_command=!cmake_command! -DRS_OPENSSL_DIR=%RS_OPENSSL_DIR%"
) else (
echo "RS_OPENSSL_DIR not set"
)
set DEPS_DIRS=-DRS_DEPS_DIRS="%RS_ROOT_DIR%\src\pgclient\kfw-3-2-2-final"
if defined RS_DEPS_DIRS (
set RS_DEPS_DIRS=!DEPS_DIRS!;%RS_DEPS_DIRS%
) else (
set RS_DEPS_DIRS=%DEPS_DIRS%
)
set "cmake_command=!cmake_command! %RS_DEPS_DIRS%"
if defined RS_MULTI_DEPS_DIRS (
set "cmake_command=!cmake_command! -DRS_MULTI_DEPS_DIRS=%RS_MULTI_DEPS_DIRS%"
)
if defined RS_ODBC_DIR (
set "cmake_command=!cmake_command! -DRS_ODBC_DIR=%RS_ODBC_DIR%"
)
if defined ENABLE_TESTING (
set "cmake_command=!cmake_command! -DENABLE_TESTING=%ENABLE_TESTING%"
)
echo "RSODBC CMAKE COMMAND: %cmake_command%"
call %cmake_command%
if %ERRORLEVEL% neq 0 (
echo Error occurred during CMake! Error code: %ERRORLEVEL%
exit /b %ERRORLEVEL%
) else (
echo CMake completed successfully.
)
@REM "%CMAKE%" --build %RS_BUILD_DIR% --config %RS_BUILD_TYPE%
msbuild %RS_BUILD_DIR%\ALL_BUILD.vcxproj /p:Configuration=%RS_BUILD_TYPE% /t:build /m:5
if %ERRORLEVEL% neq 0 (
echo Error occurred during Build! Error code: %ERRORLEVEL%
exit /b %ERRORLEVEL%
) else (
echo Build completed successfully.
)
@REM "%CMAKE%" --install %RS_BUILD_DIR% --config %RS_BUILD_TYPE%
msbuild %RS_BUILD_DIR%\INSTALL.vcxproj /p:Configuration=%RS_BUILD_TYPE% /m /verbosity:normal
if %ERRORLEVEL% neq 0 (
echo Error occurred during Install! Error code: %ERRORLEVEL%
exit /b %ERRORLEVEL%
) else (
echo Install completed successfully.
)
:GOT_INSTALLER
call package64.bat
echo "RS_ARTIFACTS_DIR is !RS_ARTIFACTS_DIR!"
echo "RS_BUILD_DIR is !RS_BUILD_DIR!"
REM Copy artifacts
copy version.txt !RS_ARTIFACTS_DIR!
echo "========== running: copy !WIN_ODBC_BUILD_MSI! !RS_ARTIFACTS_DIR!"
copy !WIN_ODBC_BUILD_MSI! !RS_ARTIFACTS_DIR!
REM Compress and Copy the test artifacts to a public folder
echo "========== running dir !RS_BUILD_DIR!(RS_BUILD_DIR)"
if exist "!RS_BUILD_DIR!" (
echo "==========!RS_BUILD_DIR! exists"
dir !RS_BUILD_DIR!
)
set "TEST_ARCHIVER_SCRIPT=!LINK_PKG_PATH!\scripts\tests_archiver.ps1"
echo "========== running set TEST_ARCHIVER_SCRIPT=!LINK_PKG_PATH!\scripts\tests_archiver.ps1"
if exist "%TEST_ARCHIVER_SCRIPT%" (
echo "========== running powershell !TEST_ARCHIVER_SCRIPT! -testFolder !RS_BUILD_DIR! -zipFileName tests.zip (RS_ARTIFACTS_DIR)"
powershell !TEST_ARCHIVER_SCRIPT! -testFolder !RS_BUILD_DIR! -zipFileName tests.zip
copy tests.zip !RS_ARTIFACTS_DIR!
) else (
echo File "%TEST_ARCHIVER_SCRIPT%" not found. Skipping execution safely.
)
echo "========== running dir !RS_ARTIFACTS_DIR!(RS_ARTIFACTS_DIR)"
dir !RS_ARTIFACTS_DIR!
echo "========== running where /r !RS_BUILD_DIR! *.exe (RS_BUILD_DIR)"
cmd /C "where /r !RS_BUILD_DIR! *.exe"
tree /F !RS_ARTIFACTS_DIR!
rem Calculate elapsed time
set endTime=%time%
for /F "tokens=1-4 delims=:.," %%a in ("%startTime%") do (
set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
)
for /F "tokens=1-4 delims=:.," %%a in ("%endTime%") do (
set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
)
set /A elapsed=end-start
rem Calculate hours, minutes, seconds
set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), ss=rest%%(60*100), cc=rest%%100
if %hh% lss 10 set hh=0%hh%
if %mm% lss 10 set mm=0%mm%
if %ss% lss 10 set ss=0%ss%
if %cc% lss 10 set cc=0%cc%
echo Start Time: %startTime%
echo Finish Time: %endTime%
echo Elapsed Time: %hh%:%mm%:%ss%.%cc%
@REM The script end here
exit /b %ERRORLEVEL%
:show_help
echo Usage: %~nx0 [OPTIONS]
echo Build the 64-bit Windows Redshift ODBC Driver
echo.
echo Options:
echo --version=X.X.X.X Set the version number (optional)
echo --build-type=TYPE Set the build type (default: Release)
echo --build-dependencies=BOOL Build dependencies (default: no)
echo --dependencies-src-dir=PATH Set the dependencies source path
echo (default: %%RS_ROOT_DIR%%\tp)
echo --dependencies-build-dir=PATH Dependency build directory
echo (default: %%DEPENDENCIES_BUILD_DIR%%)
echo --dependencies-install-dir=PATH Path to store and/or use dependency libraries
echo.
echo /?, -h, --help Show this help message
echo.
echo Examples:
echo %~nx0 --version=1.1.1.1 --build-type=Debug
echo %~nx0 --build-dependencies=yes --dependencies-src-dir=%%CD%%\tp
echo %~nx0 --build-dependencies=yes --dependencies-src-dir=%%CD%%\tp --dependencies-build-dir=%%CD%%\tpbuild
echo %~nx0 --build-dependencies=no --dependencies-install-dir=%%CD%%\tp\install
exit /b 0