DEVenv/Win/Scripts/dev.bat

113 lines
6.4 KiB
Batchfile

@echo off
:: Setup :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set script_path=%~dpnx0
set script_dir_backslash=%~dp0
set script_dir=%script_dir_backslash:~0,-1%
set root_dir=%devenver_root%
:: Arguments :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set clang_dir=%root_dir%\LLVM
set cmake_dir=%root_dir%\CMake
set msvc_dir=%root_dir%\msvc
set msvc_vc_dir=%msvc_dir%\msvc_host_x64_target_x64
set msvc_sdk_dir=%msvc_dir%\sdk_host_x64_target_x64
set node_dir=%root_dir%\NodeJS
set raddbg_dir=%root_dir%\raddbg\trunk
set raddbg_args=--user:%raddbg_dir%\..\doylet.raddbg_user
set raddbg_exe=raddbg.exe
set radlink_dir=%root_dir%\raddbg\trunk
set radlink_exe=radlink.exe
set rad_update_dir=%radlink_dir%\..
set rad_update_exe=update_trunk.bat
set remedybg_dir=%root_dir%\RemedyBG
set remedybg_exe=remedybg.exe
set virustotal_url=https://www.virustotal.com/gui/file
:: Argument parsing ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Remove the first argument which is the command (e.g. raddbg or radlink)
set option=%1
shift
if "%option%"=="clang" set "exe_dir=%clang_dir%\%1\bin" && set path=%exe_dir%;%path% && set cmd_line=!exe_dir!\%2 && shift && shift
if "%option%"=="cmake" set "exe_dir=%cmake_dir%\%1" && set path=%exe_dir%;%path% && set cmd_line=!exe_dir!\%2 && shift && shift
if "%option%"=="node" set "exe_dir=%node_dir%\%1" && set path=%exe_dir%;%path% && set cmd_line=!exe_dir!\%2 && shift && shift
if "%option%"=="msvc" endlocal && call %msvc_vc_dir%\%1\devcmd.bat && call %msvc_sdk_dir%\%2\devcmd.bat && goto :eof
if "%option%"=="rad_update" set "exe_dir=%rad_update_dir%" && set path=%rad_update_dir%;%path% && set cmd_line=!exe_dir!\update_trunk.bat
if "%option%"=="raddbg" set "exe_dir=%raddbg_dir%" && set path=%exe_dir%;%path% && set cmd_line=start /B !exe_dir!\%raddbg_exe% %raddbg_args%
if "%option%"=="raddbg_env" endlocal && set path=%raddbg_dir%;%path% && goto :eof
if "%option%"=="radlink" set "exe_dir=%radlink_dir%" && set path=%exe_dir%;%path% && set cmd_line=!exe_dir!\%radlink_exe%
if "%option%"=="radlink_env" endlocal && set path=%radlink_dir%;%path% && goto :eof
if "%option%"=="remedybg" set "exe_dir=%remedybg_dir%\%1" && set path=%exe_dir%;%path% && set cmd_line=start /B !exe_dir!\%remedybg_exe% && shift
if "%option%"=="virustotal" for /f "delims=" %%a in ('powershell -Command "(Get-FileHash \"%1\" -Algorithm SHA256).Hash"') do set virustotal_hash=%%a && shift
if "%option%"=="virustotal" set cmd_line=start /B %virustotal_url%/%virustotal_hash%
if "%cmd_line%"=="" set option=help
if "%option%"=="help" (
for /f "delims=" %%a in ('dir /B %clang_dir%') do set "clang_versions=%%a !clang_versions!"
for /f "delims=" %%a in ('dir /B %cmake_dir%') do set "cmake_versions=%%a !cmake_versions!"
for /f "delims=" %%a in ('dir /B %remedybg_dir%') do set "remedybg_versions=%%a !remedybg_versions!"
for /f "delims=" %%a in ('dir /B %node_dir%') do set "node_versions=%%a !node_versions!"
for /f "delims=" %%a in ('dir /B %msvc_vc_dir%') do set "msvc_vc_versions=%%a !msvc_vc_versions!"
for /f "delims=" %%a in ('dir /B %msvc_sdk_dir%') do set "msvc_sdk_versions=%%a !msvc_sdk_versions!"
echo USAGE: dev [option] [args...]
echo.
echo NOTES:
echo Commands suffixed with '_env' augment the system path with the path to the tool for the
echo current shell session.
echo.
echo OPTIONS:
echo cmake [version] [exe] CMake build system: '%cmake_dir%\[version]\[exe] %cmake_args%'
echo Versions: !cmake_versions!
echo.
echo clang [version] [exe] CLANG compiler: '%clang_dir%\[version]\[exe] %clang_args%'
echo Example: 'dev clang 18.1.4 clang++.exe --help'
echo Versions: !clang_versions!
echo.
echo msvc [vc_version] [sdk_version] MSVC build tools: '%msvc_vc_dir%\[vc_version]'
echo '%msvc_sdk_dir%\[sdk_version]'
echo VC Versions: !msvc_vc_versions!
echo SDK Versions: !msvc_sdk_versions!
echo.
echo node [version] [exe] Node JS: '%node_dir%\[version]\[exe]'
echo Versions: !node_versions!
echo.
echo raddbg RAD debugger: '%raddbg_dir%\%raddbg_exe% %raddbg_args%'
echo raddbg_env [cmd...] '%raddbg_dir%;[PATH]'
echo radlink RAD linker: '%radlink_dir%\%radlink_exe%'
echo radlink_env [cmd...] '%radlink_dir%;[PATH]'
echo rad_update Update the RAD linker and debugger: '%rad_update_dir%\%rad_update_exe%'
echo remedybg [version] C/C++ debugger: '%remedybg_dir%\%remedybg_exe%'
echo Versions: !remedybg_versions!
echo.
echo virustotal [file] Lookup file SHA256 hash on VirusTotal: '%virustotal_url%/[file]'
goto :eof
)
:: Extract user arguments ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:extract_args
if "%~1" neq "" (
set user_args=%user_args% %1
shift
goto :extract_args
)
:trim_user_args_trailing_space
if "!user_args:~-1!"==" " (
set user_args=!user_args:~0,-1!
goto trim_user_args_trailing_space
)
:trim_cmd_line_trailing_space
if "!cmd_line:~-1!"==" " (
set cmd_line=!cmd_line:~0,-1!
goto trim_cmd_line_trailing_space
)
:: Eval ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo DEV: Running "%script_path%" with "%cmd_line%%user_args%"
call %cmd_line%%user_args%
goto :eof