pawelzwronek - 2024-11-24

Excuse me for a rush pull request. Original script sucks. This is more robust and more configurable version. The patch also changes slightly others files.

@echo off
:: 1. Build scintilla.dll and copy to the root bin folder
:: 2. Build C++ unit tests and run them
:: 3. Run python tests: simpleTests.py, win32Tests.py

set "MAKE_DIR=win32"
set "OUTPUT_DLL=scintilla.dll"
set "INSTALL_DIR=bin"

set "VS_DEV_CMD=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
set "CONFIGURATION=Release"
set "PLATFORM=x64"

set "VS_CONFIG_CMD=_VS_config.cmd"

:: Create configuration script if it does not exist
if not exist %VS_CONFIG_CMD% (
    (
        echo set "VS_DEV_CMD=%VS_DEV_CMD%"
        echo set "CONFIGURATION=%CONFIGURATION%"
        echo set "PLATFORM=%PLATFORM%"
        echo @rem set "VS_DEV_CMD=%VS_DEV_CMD:Program Files\Microsoft Visual Studio\2022=Program Files (x86)\Microsoft Visual Studio\2019%"
        echo @rem set "CONFIGURATION=Debug"
        echo @rem set "PLATFORM=x86"
    ) > %VS_CONFIG_CMD%
    call :echo_yellow "Configuration script created at: %VS_CONFIG_CMD%"
    call :echo_yellow "Edit it to change the configuration and run this script again"
    exit /b 1
)

:: Run configuration script
call %VS_CONFIG_CMD%
set "OUTPUT_PATH=%MAKE_DIR%\%PLATFORM%\%CONFIGURATION%\%OUTPUT_DLL%"

if not exist "%VS_DEV_CMD%" (
    call :echo_red "Visual Studio not found at: %VS_DEV_CMD%"
    call :echo_red "Edit %VS_CONFIG_CMD% to point to the correct location"
    exit /b 1
)

:: Set up Visual Studio environment if not already set
if not defined VSCMD_VER (
    call "%VS_DEV_CMD%"
    call :check_error "Failed to set up Visual Studio environment"
)

:: Build Scintilla
del %INSTALL_DIR%\%OUTPUT_DLL% 2>nul
del %OUTPUT_PATH% 2>nul

pushd %MAKE_DIR%
    msbuild /m /p:Configuration=%CONFIGURATION% /p:Platform=%PLATFORM% /p:OutDir=%PLATFORM%\%CONFIGURATION%\
    :: /m - multi-threaded build
    call :check_error "Failed to build Scintilla"
popd

:: Copy output to installation folder
copy /Y %OUTPUT_PATH% %INSTALL_DIR%
call :check_error "Failed to copy %OUTPUT_PATH% to %INSTALL_DIR%\"

:: Build C++ unit tests
pushd "test\unit"
    nmake -f test.mak test
    call :check_error "Failed to build or running C++ unit tests"
popd

:: Run Python unit tests
pushd "test"
    python simpleTests.py
    call :check_error "Failed to run simpleTests.py"

    python win32Tests.py
    call :check_error "Failed to run win32Tests.py"
popd

exit /b 0


:: Function to check error level and exit if an error occurred
:check_error
    if %errorlevel% neq 0 (
        call :echo_red "%~1 (%errorlevel%)"
        popd
        (goto) 2>nul & goto :exit
    )
    exit /b 0

:echo_green
    echo %~1
    exit /b 0

:echo_yellow
    echo %~1
    exit /b 0

:echo_red
    echo %~1
    exit /b 0


:exit
    exit /b %errorlevel%
 

Last edit: pawelzwronek 2024-11-25