Skip to content

Commit

Permalink
Merge pull request #3 from bpintea/feature/tableau_connect
Browse files Browse the repository at this point in the history
connect Tableau to Elasticsearch
  • Loading branch information
bpintea authored Apr 20, 2018
2 parents d38dd0f + 61358eb commit 3de5728
Show file tree
Hide file tree
Showing 14 changed files with 1,143 additions and 253 deletions.
274 changes: 204 additions & 70 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ setlocal EnableExtensions EnableDelayedExpansion
REM cls

SET ARG="%*"
SET SRC_PATH=%~dp0


REM 32/64 bit argument needs to stay on top, before setting LIBCURL path.
REM presence of '32' or '64': set the Bits/Target ARCHhitecture
if not _%ARG:32=% == _%ARG% (
set TARCH=x86
set BARCH=32
) else (
set TARCH=x64
set BARCH=64
)



REM
REM List of variables that can be customized
REM

if "%SRC_PATH%" == "" (
SET SRC_PATH=%~dp0
)
if "%BUILD_DIR%" == "" (
SET BUILD_DIR=%SRC_PATH%\builds
)
Expand All @@ -33,7 +44,7 @@ if "%INSTALL_DIR%" == "" (
)

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

if "%CMAKE_BIN_PATH%" == "" (
Expand All @@ -43,49 +54,173 @@ if "%CMAKE_BIN_PATH%" == "" (


REM
REM Perform the building steps
REM Perform the building steps
REM

REM presence of 'help'/'?': invoke USAGE "function" and exit
if /i not _%ARG:help=% == _%ARG% (
call:USAGE %0
goto end
) else if not _%ARG:?=% == _%ARG% (
call:USAGE %0
goto end
)

REM presence of 'proper' or 'clean': invoke respective "functions"
if /i not _%ARG:proper=% == _%ARG% (
call:PROPER
goto end
) else if /i not _%ARG:clean=% == _%ARG% (
call:CLEAN
)

REM presence of 'setup': invoke SETUP "function"
if /i not _%ARG:setup=% == _%ARG% (
call:SETUP
) else (
REM Invoked without 'setup': setting up build vars skipped.

where cl.exe >nul 2>&1
if ERRORLEVEL 1 (
echo.
echo Note: building environment not set. Run with /? to see options.
echo.
)
)

REM presence of 'fetch': invoke FETCH "function"
if /i not _%ARG:fetch=% == _%ARG% (
call:FETCH
)


cd %BUILD_DIR%

REM absence of nobuild: invoke BUILD "function"
if /i _%ARG:nobuild=% == _%ARG% (
call:BUILD
) else (
echo Invoked with 'nobuild', building skipped.
)

REM presence of 'copy': invoke COPY "function"
if /i not _%ARG:copy=% == _%ARG% (
call:COPY
) else (
REM Invoked without 'copy': DLLs test installation skipped.
)

REM presence of 'trunclogs': invoke TRUNCLOGS "function"
if /i not _%ARG:trunclogs=% == _%ARG% (
call:TRUNCLOGS
) else (
REM Invoked without 'trunclogs', logs not truncated.
)

REM presence of 'regadd': call REGADD "function"
if /i not _%ARG:regadd=% == _%ARG% (
call:REGADD
) else (
REM Invoked without 'regadd': registry adding skipped.
)

REM presence of 'regdel': invoke REGDEL "function"
if /i not _%ARG:regdel=% == _%ARG% (
call:REGDEL
) else (
REM Invoked without 'regadd': registry adding skipped.
)

:end
exit /b 0



REM
REM "Functions"
REM

REM presence of 'help': output a usage message
if not _%ARG:help=% == _%ARG% (
echo Usage: %0 [argument(s^)]
REM USAGE function: output a usage message
:USAGE
echo Usage: %1 [argument(s^)]
echo.
echo The following arguments are supported:
echo help : output this message and exit.
echo help^|*?* : output this message and exit.
echo 32^|64 : setup the architecture to 32- or 64-bit (default^);
echo useful with 'setup' and 'reg*' arguments only;
echo x86 and x64 platforms supported only.
echo setup : invoke MSVC's build environment setup script before
echo building (requires 2017 version or later^).
echo clean : clean the build dir files.
echo proper : clean both the build and libs dir and exit.
echo fetch : fetch, patch and build the dependency libs.
echo nobuild : don't build the project (the default is to build^).
echo copy : copy the DLL into the test dir.
echo regadd : register the driver into the registry (run as Administrator^).
echo regdel : deregister the driver from the registry (run as Administrator^).
echo trunclogs : truncate the logs.
echo nobuild : skip project building (the default is to build^).
echo copy : copy the DLL into the test dir (%INSTALL_DIR%^).
echo regadd : register the driver into the registry;
echo (needs Administrator privileges^).
echo regdel : deregister the driver from the registry;
echo (needs Administrator privileges^).
echo trunclogs : truncate the logs (in %LOGGING_DIR%^).
echo.
echo Multiple arguments can be used concurrently.
echo Invoked with no arguments, the script will only initiate a build.
echo Example:^> %1 setup 32 fetch
echo.

goto end
)
echo List of settable environment variables:
echo BUILD_DIR : path to folder to hold the build files;
echo now set to: `%BUILD_DIR%`.
echo LOGGING_DIR : path to folder holding the logging files;
echo now set to: `%LOGGING_DIR%`.
echo INSTALL_DIR : path to folder to hold the built driver;
echo now set to: `%INSTALL_DIR%`.
echo LIBCURL_PATH_BUILD : path to libcurl library;
echo now set to: `%LIBCURL_PATH_BUILD%`.
echo CMAKE_BIN_PATH : path to cmake executable;
echo now set to: `%CMAKE_BIN_PATH%`.
echo.

goto:eof

REM presence of 'proper': clean up the build and libs dir before building
if not _%ARG:proper=% == _%ARG% (

REM PROPER function: clean up the build and libs dir before building
:PROPER
echo Cleaning all build and libs files.
del /s /q %BUILD_DIR%\* >nul 2>&1
for /d %%i in (%BUILD_DIR%\*) do rmdir /s /q %%i >nul 2>&1
del /s /q libs\* >nul 2>&1
for /d %%i in (libs\*) do rmdir /s /q %%i >nul 2>&1

goto end
) else if not _%ARG:clean=% == _%ARG% (
REM presence of 'clean': clean up the build dir before building
goto:eof


REM CLEAN function: clean up the build dir before building
:CLEAN
echo Cleaning all build files.
del /s /q %BUILD_DIR%\* >nul 2>&1
for /d %%i in (%BUILD_DIR%\*) do rmdir /s /q %%i >nul 2>&1
)

REM presence of 'fetch': fetch, patch, build the external libs
if not _%ARG:fetch=% == _%ARG% (
goto:eof


REM SETUP function: set-up the build environment
:SETUP
set RELEASE=2017
set EDITION=Professional
for %%e in (Enterprise, Professional, Community) do (
if exist "C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE%\%%e\Common7\Tools\VsDevCmd.bat" (
if /i "%%e" == "Community" (
echo WARNING: Community edition is not licensed to build commerical projects.
)
call "C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE%\%%e\Common7\Tools\VsDevCmd.bat" -arch=!TARCH!
break
)
)

goto:eof


REM FETCH function: fetch, patch, build the external libs
:FETCH
echo Fetching external dependencies, patching and building them.

rem pushd .
Expand Down Expand Up @@ -119,18 +254,17 @@ if not _%ARG:fetch=% == _%ARG% (
REM build libcurl
cd curl
git checkout curl-7_58_0

call buildconf.bat
REM buildconf.bat will cd
cd winbuild
call nmake /f Makefile.vc mode=dll MACHINE=x64
)
call nmake /f Makefile.vc mode=dll MACHINE=!TARCH!

goto:eof

cd %BUILD_DIR%

REM absence of nobuild: run the build
if _%ARG:nobuild=% == _%ARG% (
REM BUILD function: compile, build the driver
:BUILD
echo Building the driver:
if not exist ALL_BUILD.vcxproj (
echo Generating the project files.
Expand All @@ -139,68 +273,68 @@ if _%ARG:nobuild=% == _%ARG% (
echo Building the project.
REM MSBuild ALL_BUILD.vcxproj /t:rebuild
MSBuild ALL_BUILD.vcxproj
) else (
echo Invoked with 'nobuild', building skipped.
)

REM presence of copy: copy DLLs (libcurl, odbc) to the test "install" dir
if not _%ARG:copy=% == _%ARG% (
goto:eof


REM COPY function: copy DLLs (libcurl, odbc) to the test "install" dir
:COPY
echo Copying into test install folder %INSTALL_DIR%.
rem dumpbin /exports Debug\elasticodbc*.dll

copy Debug\elasticodbc*.dll %INSTALL_DIR%\
copy %LIBCURL_PATH_BUILD%\bin\libcurl.dll %INSTALL_DIR%\
) else (
REM Invoked without 'copy': DLLs test installation skipped.
)

REM presence of regadd: add driver into the registry
if not _%ARG:regadd=% == _%ARG% (
goto:eof


REM TRUNCLOGS function: empty logs files
:TRUNCLOGS
echo Truncating logs in %LOGGING_DIR%.
echo.>%LOGGING_DIR%\mylog.txt
echo.>%LOGGING_DIR%\SQL32.LOG
echo.>%LOGGING_DIR%\SQL.LOG

goto:eof


REM REGADD function: add driver into the registry
:REGADD
echo Adding driver into the registry.

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

echo Registering driver in registry under: %INSTALL_DIR%\!DRVNAME!
echo Adding ESODBC driver %INSTALL_DIR%\!DRVNAME! to the registry.

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

reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f /reg:64
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f ^
/reg:!BARCH!
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v Driver ^
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:64
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:!BARCH!
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v Setup ^
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:64
/t REG_SZ /d %INSTALL_DIR%\!DRVNAME! /f /reg:!BARCH!
reg add "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v UsageCount^
/t REG_DWORD /d 1 /f /reg:64
) else (
REM Invoked without 'regadd': registry adding skipped.
)
/t REG_DWORD /d 1 /f /reg:!BARCH!

goto:eof

REM presence of regdel: remove driver from the registry
if not _%ARG:regdel=% == _%ARG% (
echo Removing driver from the registry.

REM REGDEL function: remove driver from the registry
:REGDEL
echo Removing ESODBC driver from the registry.

reg delete "HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" ^
/v "Elasticsearch ODBC" /f /reg:64
reg delete "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f /reg:64
) else (
REM Invoked without 'regadd': registry adding skipped.
)
/v "Elasticsearch ODBC" /f /reg:!BARCH!
reg delete "HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f ^
/reg:!BARCH!

REM presence of keeplogs: empty logs files
if not _%ARG:trunclogs=% == _%ARG% (
echo Truncating logs in %LOGGING_DIR%.
echo.>%LOGGING_DIR%\mylog.txt
echo.>%LOGGING_DIR%\SQL32.LOG
echo.>%LOGGING_DIR%\SQL.LOG
) else (
REM Invoked without 'trunclogs', logs not truncated.
)
goto:eof

:end
endlocal
Loading

0 comments on commit 3de5728

Please sign in to comment.