Skip to content

Commit 3de5728

Browse files
authored
Merge pull request #3 from bpintea/feature/tableau_connect
connect Tableau to Elasticsearch
2 parents d38dd0f + 61358eb commit 3de5728

14 files changed

+1143
-253
lines changed

build.bat

Lines changed: 204 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ setlocal EnableExtensions EnableDelayedExpansion
55
REM cls
66

77
SET ARG="%*"
8+
SET SRC_PATH=%~dp0
9+
10+
11+
REM 32/64 bit argument needs to stay on top, before setting LIBCURL path.
12+
REM presence of '32' or '64': set the Bits/Target ARCHhitecture
13+
if not _%ARG:32=% == _%ARG% (
14+
set TARCH=x86
15+
set BARCH=32
16+
) else (
17+
set TARCH=x64
18+
set BARCH=64
19+
)
20+
21+
822

923
REM
1024
REM List of variables that can be customized
1125
REM
1226

13-
if "%SRC_PATH%" == "" (
14-
SET SRC_PATH=%~dp0
15-
)
1627
if "%BUILD_DIR%" == "" (
1728
SET BUILD_DIR=%SRC_PATH%\builds
1829
)
@@ -33,7 +44,7 @@ if "%INSTALL_DIR%" == "" (
3344
)
3445

3546
if "%LIBCURL_PATH_BUILD%" == "" (
36-
SET LIBCURL_PATH_BUILD=%SRC_PATH%\libs\curl\builds\libcurl-vc-x64-release-dll-ipv6-sspi-winssl
47+
SET LIBCURL_PATH_BUILD=%SRC_PATH%\libs\curl\builds\libcurl-vc-!TARCH!-release-dll-ipv6-sspi-winssl
3748
)
3849

3950
if "%CMAKE_BIN_PATH%" == "" (
@@ -43,49 +54,173 @@ if "%CMAKE_BIN_PATH%" == "" (
4354

4455

4556
REM
46-
REM Perform the building steps
57+
REM Perform the building steps
58+
REM
59+
60+
REM presence of 'help'/'?': invoke USAGE "function" and exit
61+
if /i not _%ARG:help=% == _%ARG% (
62+
call:USAGE %0
63+
goto end
64+
) else if not _%ARG:?=% == _%ARG% (
65+
call:USAGE %0
66+
goto end
67+
)
68+
69+
REM presence of 'proper' or 'clean': invoke respective "functions"
70+
if /i not _%ARG:proper=% == _%ARG% (
71+
call:PROPER
72+
goto end
73+
) else if /i not _%ARG:clean=% == _%ARG% (
74+
call:CLEAN
75+
)
76+
77+
REM presence of 'setup': invoke SETUP "function"
78+
if /i not _%ARG:setup=% == _%ARG% (
79+
call:SETUP
80+
) else (
81+
REM Invoked without 'setup': setting up build vars skipped.
82+
83+
where cl.exe >nul 2>&1
84+
if ERRORLEVEL 1 (
85+
echo.
86+
echo Note: building environment not set. Run with /? to see options.
87+
echo.
88+
)
89+
)
90+
91+
REM presence of 'fetch': invoke FETCH "function"
92+
if /i not _%ARG:fetch=% == _%ARG% (
93+
call:FETCH
94+
)
95+
96+
97+
cd %BUILD_DIR%
98+
99+
REM absence of nobuild: invoke BUILD "function"
100+
if /i _%ARG:nobuild=% == _%ARG% (
101+
call:BUILD
102+
) else (
103+
echo Invoked with 'nobuild', building skipped.
104+
)
105+
106+
REM presence of 'copy': invoke COPY "function"
107+
if /i not _%ARG:copy=% == _%ARG% (
108+
call:COPY
109+
) else (
110+
REM Invoked without 'copy': DLLs test installation skipped.
111+
)
112+
113+
REM presence of 'trunclogs': invoke TRUNCLOGS "function"
114+
if /i not _%ARG:trunclogs=% == _%ARG% (
115+
call:TRUNCLOGS
116+
) else (
117+
REM Invoked without 'trunclogs', logs not truncated.
118+
)
119+
120+
REM presence of 'regadd': call REGADD "function"
121+
if /i not _%ARG:regadd=% == _%ARG% (
122+
call:REGADD
123+
) else (
124+
REM Invoked without 'regadd': registry adding skipped.
125+
)
126+
127+
REM presence of 'regdel': invoke REGDEL "function"
128+
if /i not _%ARG:regdel=% == _%ARG% (
129+
call:REGDEL
130+
) else (
131+
REM Invoked without 'regadd': registry adding skipped.
132+
)
133+
134+
:end
135+
exit /b 0
136+
137+
138+
139+
REM
140+
REM "Functions"
47141
REM
48142

49-
REM presence of 'help': output a usage message
50-
if not _%ARG:help=% == _%ARG% (
51-
echo Usage: %0 [argument(s^)]
143+
REM USAGE function: output a usage message
144+
:USAGE
145+
echo Usage: %1 [argument(s^)]
52146
echo.
53147
echo The following arguments are supported:
54-
echo help : output this message and exit.
148+
echo help^|*?* : output this message and exit.
149+
echo 32^|64 : setup the architecture to 32- or 64-bit (default^);
150+
echo useful with 'setup' and 'reg*' arguments only;
151+
echo x86 and x64 platforms supported only.
152+
echo setup : invoke MSVC's build environment setup script before
153+
echo building (requires 2017 version or later^).
55154
echo clean : clean the build dir files.
56155
echo proper : clean both the build and libs dir and exit.
57156
echo fetch : fetch, patch and build the dependency libs.
58-
echo nobuild : don't build the project (the default is to build^).
59-
echo copy : copy the DLL into the test dir.
60-
echo regadd : register the driver into the registry (run as Administrator^).
61-
echo regdel : deregister the driver from the registry (run as Administrator^).
62-
echo trunclogs : truncate the logs.
157+
echo nobuild : skip project building (the default is to build^).
158+
echo copy : copy the DLL into the test dir (%INSTALL_DIR%^).
159+
echo regadd : register the driver into the registry;
160+
echo (needs Administrator privileges^).
161+
echo regdel : deregister the driver from the registry;
162+
echo (needs Administrator privileges^).
163+
echo trunclogs : truncate the logs (in %LOGGING_DIR%^).
63164
echo.
64165
echo Multiple arguments can be used concurrently.
65166
echo Invoked with no arguments, the script will only initiate a build.
167+
echo Example:^> %1 setup 32 fetch
66168
echo.
67-
68-
goto end
69-
)
169+
echo List of settable environment variables:
170+
echo BUILD_DIR : path to folder to hold the build files;
171+
echo now set to: `%BUILD_DIR%`.
172+
echo LOGGING_DIR : path to folder holding the logging files;
173+
echo now set to: `%LOGGING_DIR%`.
174+
echo INSTALL_DIR : path to folder to hold the built driver;
175+
echo now set to: `%INSTALL_DIR%`.
176+
echo LIBCURL_PATH_BUILD : path to libcurl library;
177+
echo now set to: `%LIBCURL_PATH_BUILD%`.
178+
echo CMAKE_BIN_PATH : path to cmake executable;
179+
echo now set to: `%CMAKE_BIN_PATH%`.
180+
echo.
181+
182+
goto:eof
70183

71-
REM presence of 'proper': clean up the build and libs dir before building
72-
if not _%ARG:proper=% == _%ARG% (
184+
185+
REM PROPER function: clean up the build and libs dir before building
186+
:PROPER
73187
echo Cleaning all build and libs files.
74188
del /s /q %BUILD_DIR%\* >nul 2>&1
75189
for /d %%i in (%BUILD_DIR%\*) do rmdir /s /q %%i >nul 2>&1
76190
del /s /q libs\* >nul 2>&1
77191
for /d %%i in (libs\*) do rmdir /s /q %%i >nul 2>&1
78192

79-
goto end
80-
) else if not _%ARG:clean=% == _%ARG% (
81-
REM presence of 'clean': clean up the build dir before building
193+
goto:eof
194+
195+
196+
REM CLEAN function: clean up the build dir before building
197+
:CLEAN
82198
echo Cleaning all build files.
83199
del /s /q %BUILD_DIR%\* >nul 2>&1
84200
for /d %%i in (%BUILD_DIR%\*) do rmdir /s /q %%i >nul 2>&1
85-
)
86201

87-
REM presence of 'fetch': fetch, patch, build the external libs
88-
if not _%ARG:fetch=% == _%ARG% (
202+
goto:eof
203+
204+
205+
REM SETUP function: set-up the build environment
206+
:SETUP
207+
set RELEASE=2017
208+
set EDITION=Professional
209+
for %%e in (Enterprise, Professional, Community) do (
210+
if exist "C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE%\%%e\Common7\Tools\VsDevCmd.bat" (
211+
if /i "%%e" == "Community" (
212+
echo WARNING: Community edition is not licensed to build commerical projects.
213+
)
214+
call "C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE%\%%e\Common7\Tools\VsDevCmd.bat" -arch=!TARCH!
215+
break
216+
)
217+
)
218+
219+
goto:eof
220+
221+
222+
REM FETCH function: fetch, patch, build the external libs
223+
:FETCH
89224
echo Fetching external dependencies, patching and building them.
90225

91226
rem pushd .
@@ -119,18 +254,17 @@ if not _%ARG:fetch=% == _%ARG% (
119254
REM build libcurl
120255
cd curl
121256
git checkout curl-7_58_0
122-
257+
123258
call buildconf.bat
124259
REM buildconf.bat will cd
125260
cd winbuild
126-
call nmake /f Makefile.vc mode=dll MACHINE=x64
127-
)
261+
call nmake /f Makefile.vc mode=dll MACHINE=!TARCH!
128262

263+
goto:eof
129264

130-
cd %BUILD_DIR%
131265

132-
REM absence of nobuild: run the build
133-
if _%ARG:nobuild=% == _%ARG% (
266+
REM BUILD function: compile, build the driver
267+
:BUILD
134268
echo Building the driver:
135269
if not exist ALL_BUILD.vcxproj (
136270
echo Generating the project files.
@@ -139,68 +273,68 @@ if _%ARG:nobuild=% == _%ARG% (
139273
echo Building the project.
140274
REM MSBuild ALL_BUILD.vcxproj /t:rebuild
141275
MSBuild ALL_BUILD.vcxproj
142-
) else (
143-
echo Invoked with 'nobuild', building skipped.
144-
)
145276

146-
REM presence of copy: copy DLLs (libcurl, odbc) to the test "install" dir
147-
if not _%ARG:copy=% == _%ARG% (
277+
goto:eof
278+
279+
280+
REM COPY function: copy DLLs (libcurl, odbc) to the test "install" dir
281+
:COPY
148282
echo Copying into test install folder %INSTALL_DIR%.
149283
rem dumpbin /exports Debug\elasticodbc*.dll
150284

151285
copy Debug\elasticodbc*.dll %INSTALL_DIR%\
152286
copy %LIBCURL_PATH_BUILD%\bin\libcurl.dll %INSTALL_DIR%\
153-
) else (
154-
REM Invoked without 'copy': DLLs test installation skipped.
155-
)
156287

157-
REM presence of regadd: add driver into the registry
158-
if not _%ARG:regadd=% == _%ARG% (
288+
goto:eof
289+
290+
291+
REM TRUNCLOGS function: empty logs files
292+
:TRUNCLOGS
293+
echo Truncating logs in %LOGGING_DIR%.
294+
echo.>%LOGGING_DIR%\mylog.txt
295+
echo.>%LOGGING_DIR%\SQL32.LOG
296+
echo.>%LOGGING_DIR%\SQL.LOG
297+
298+
goto:eof
299+
300+
301+
REM REGADD function: add driver into the registry
302+
:REGADD
159303
echo Adding driver into the registry.
160304

161305
REM check if driver exists, otherwise the filename is unknown
162-
if not exist Debug\elasticodbc*.dll (
306+
if not exist %BUILD_DIR%\Debug\elasticodbc*.dll (
163307
echo Error: Driver can only be added into the registry once built.
164308
goto end
165309
)
166-
for /f %%i in ("Debug\elasticodbc*.dll") do set DRVNAME=%%~nxi
310+
for /f %%i in ("%BUILD_DIR%\Debug\elasticodbc*.dll") do set DRVNAME=%%~nxi
167311

168-
echo Registering driver in registry under: %INSTALL_DIR%\!DRVNAME!
312+
echo Adding ESODBC driver %INSTALL_DIR%\!DRVNAME! to the registry.
169313

170314
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" ^
171-
/v "Elasticsearch ODBC" /t REG_SZ /d Installed /f /reg:64
315+
/v "Elasticsearch ODBC" /t REG_SZ /d Installed /f /reg:!BARCH!
172316

173-
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f /reg:64
317+
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f ^
318+
/reg:!BARCH!
174319
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v Driver ^
175-
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:64
320+
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:!BARCH!
176321
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v Setup ^
177-
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:64
322+
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:!BARCH!
178323
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v UsageCount^
179-
/t REG_DWORD /d 1 /f /reg:64
180-
) else (
181-
REM Invoked without 'regadd': registry adding skipped.
182-
)
324+
/t REG_DWORD /d 1 /f /reg:!BARCH!
325+
326+
goto:eof
183327

184-
REM presence of regdel: remove driver from the registry
185-
if not _%ARG:regdel=% == _%ARG% (
186-
echo Removing driver from the registry.
328+
329+
REM REGDEL function: remove driver from the registry
330+
:REGDEL
331+
echo Removing ESODBC driver from the registry.
187332

188333
reg delete "HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" ^
189-
/v "Elasticsearch ODBC" /f /reg:64
190-
reg delete "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f /reg:64
191-
) else (
192-
REM Invoked without 'regadd': registry adding skipped.
193-
)
334+
/v "Elasticsearch ODBC" /f /reg:!BARCH!
335+
reg delete "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f ^
336+
/reg:!BARCH!
194337

195-
REM presence of keeplogs: empty logs files
196-
if not _%ARG:trunclogs=% == _%ARG% (
197-
echo Truncating logs in %LOGGING_DIR%.
198-
echo.>%LOGGING_DIR%\mylog.txt
199-
echo.>%LOGGING_DIR%\SQL32.LOG
200-
echo.>%LOGGING_DIR%\SQL.LOG
201-
) else (
202-
REM Invoked without 'trunclogs', logs not truncated.
203-
)
338+
goto:eof
204339

205-
:end
206340
endlocal

0 commit comments

Comments
 (0)