From 633c3bc7eb24c29c1f22a778c6deea7673e24b32 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 24 Dec 2025 17:12:17 +0500 Subject: [PATCH] build-deps - move some code to powershell --- win/build-deps.cmd | 86 ++++++++----------------------------- win/utils/tools.ps1 | 100 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 70 deletions(-) diff --git a/win/build-deps.cmd b/win/build-deps.cmd index ac523774b5..c81541104f 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -793,76 +793,31 @@ exit %IFCOS_SCRIPT_RET% :: DownloadFile - Downloads a file using PowerShell :: Params: %1 url, %2 destinationDir, %3 filename +:: Required vars: +:: - DEPENDENCY_NAME :DownloadFile -mkdir "%2" -pushd "%2" -if not exist "%~3". ( - call cecho.cmd 0 13 "Downloading %DEPENDENCY_NAME% into %~2." - powershell -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; $webClient = new-object System.Net.WebClient; $webClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials; $webClient.DownloadFile('%1', '%3')" - REM Old wget version in case someone has problem with PowerShell: wget --no-check-certificate %1 -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already downloaded. Skipping." -) -set RET=%ERRORLEVEL% -set LAST_ACTION=DownloadFile '%DEPENDENCY_NAME%'. -popd -exit /b %RET% +%PWSH_TOOLS% download_file "%DEPENDENCY_NAME%" "%1" "%2" "%3" +IF NOT %ERRORLEVEL%==0 GOTO :Error +exit /b 0 :: ExtractArchive - Extracts an archive file using 7-zip :: Params: %1 filename, %2 destinationDir, %3 dirAfterExtraction +:: Required vars: +:: - DEPENDENCY_NAME :ExtractArchive -if not exist "%~3". ( - call cecho.cmd 0 13 "Extracting %DEPENDENCY_NAME% into %~2 from %1" - 7za x %1 -y -o%2 > nul -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already extracted into %~3. Skipping." -) -set RET=%ERRORLEVEL% -set LAST_ACTION=ExtractArchive '%DEPENDENCY_NAME%'. -exit /b %RET% - -:: GitCloneOrPullRepository - Clones or pulls (if repository already cloned) a Git repository -:: Params: %1 gitUrl, %2 destDir -:: F.ex. call :GitCloneRepository https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPS_DIR%\OpenCOLLADA\" -:GitCloneOrPullRepository -if not exist "%~2". ( - call cecho.cmd 0 13 "Cloning %DEPENDENCY_NAME% into %~2." - pushd "%DEPS_DIR%" - call git clone %1 %2 - set RET=!ERRORLEVEL! -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned. Pulling latest changes." - git reset --hard - pushd %2 - call git pull - set RET=0 -) -popd -exit /b %RET% +%PWSH_TOOLS% extract_file "%DEPENDENCY_NAME%" "%1" "%2" "%3" +IF NOT %ERRORLEVEL%==0 GOTO :Error +exit /b 0 :: GitCloneAndCheckoutRevision - Clones a Git repository and checks out a specific revision or tag :: Params: %1 gitUrl, %2 destDir, %3 revision :: F.ex. call :GitCloneAndCheckoutRevision https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPENDENCY_DIR%" 064a60b65c2c31b94f013820856bc84fb1937cc6 +:: Required vars: +:: - DEPENDENCY_NAME :GitCloneAndCheckoutRevision -if not exist "%~2". ( - call cecho.cmd 0 13 "Cloning %DEPENDENCY_NAME% into %~2." - pushd "%DEPS_DIR%" - call git clone %1 %2 - set RET=!ERRORLEVEL! - if not "!RET!"=="0" exit /b !RET! - popd -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned." - set RET=0 -) -pushd "%2" -call git fetch -call cecho.cmd 0 13 "Checking out %DEPENDENCY_NAME% revision %3." -call git reset --hard -call git checkout %3 -set RET=%ERRORLEVEL% -popd -exit /b %RET% +%PWSH_TOOLS% git_clone_and_checkout_revision "%DEPENDENCY_NAME%" "%1" "%2" "%3" +IF NOT %ERRORLEVEL%==0 GOTO :Error +exit /b 0 :: RunCMake - Runs CMake for a CMake-based project :: Params: %* cmakeOptions @@ -931,14 +886,9 @@ exit /b %ERRORLEVEL% :: Required vars: :: - DEPENDENCY_NAME :InstallCMakeProject -pushd %1 -call cecho.cmd 0 13 "Installing %2 %DEPENDENCY_NAME%. Please be patient, this will take a while." -set COMMAND=cmake --install . --config %2 -echo %COMMAND% -%COMMAND% -set RET=%ERRORLEVEL% -popd -exit /b %RET% +%PWSH_TOOLS% install_cmake_project "%DEPENDENCY_NAME%" "%1" "%2" +IF NOT %ERRORLEVEL%==0 GOTO :Error +exit /b 0 :: Checks whether a dependency is already installed for the specified config :: Doesn't work for dependencies, only for those that need separate Debug/Release installs. diff --git a/win/utils/tools.ps1 b/win/utils/tools.ps1 index ee52d8ba97..c143581789 100644 --- a/win/utils/tools.ps1 +++ b/win/utils/tools.ps1 @@ -18,7 +18,7 @@ function mark { if (Test-Path -Path $marker_filepath) { return } - echo "Marking installation in '$installation_dir' with '$ENV:MARKER_FILE'." + cecho.cmd 0 13 "Marking installation in '$installation_dir' with '$ENV:MARKER_FILE'." New-Item -Path $marker_filepath -ItemType File | Out-Null } @@ -76,7 +76,7 @@ function mark_based_on_artifacts { if (Test-Path -Path $marker_filepath) { return } - echo "Found artifact '$artifact' for dependency '$dependency_name' $env:BUILD_CFG." + cecho.cmd 0 13 "Found artifact '$artifact' for dependency '$dependency_name' $env:BUILD_CFG." & mark $installation_dir } @@ -125,6 +125,102 @@ function setup_build_cfg { } } + +function extract_file { + param( + [Parameter(Mandatory = $true)] + [string]$dependency_name, + [Parameter(Mandatory = $true)] + [string]$filename, + [Parameter(Mandatory = $true)] + [string]$destination_dir, + [Parameter(Mandatory = $true)] + [string]$dir_after_extraction + ) + if (Test-Path -Path "$dir_after_extraction") { + cecho.cmd 0 13 "$dependency_name already extracted into '$dir_after_extraction'. Skipping." + exit 0 + } + cecho.cmd 0 13 "Extracting $dependency_name into '$destination_dir' from '$filename'." + 7za x "$filename" -o"$destination_dir" + exit 0 +} + + +function download_file { + param( + [Parameter(Mandatory = $true)] + [string]$dependency_name, + [Parameter(Mandatory = $true)] + [string]$url, + [Parameter(Mandatory = $true)] + [string]$destination_dir, + [Parameter(Mandatory = $true)] + [string]$filename + ) + mkdir "$destination_dir" -Force | Out-Null + pushd "$destination_dir" + if (Test-Path -Path "$filename") { + cecho.cmd 0 13 "$dependency_name already downloaded. Skipping." + exit 0 + } + + cecho.cmd 0 13 "Downloading $dependency_name into '$destination_dir'" + Invoke-WebRequest $url -OutFile $filename + exit 0 +} + + +# Required env variables: +# - DEPS_DIR +function git_clone_and_checkout_revision { + param( + [Parameter(Mandatory = $true)] + [string]$dependency_name, + [Parameter(Mandatory = $true)] + [string]$git_url, + [Parameter(Mandatory = $true)] + [string]$dest_dir, + [Parameter(Mandatory = $false)] + [string]$revision + ) + if (Test-Path -Path "$dest_dir") { + cecho.cmd 0 13 "Cloning $dependency_name is already cloned." + exit 0 + } + cecho.cmd 0 13 "Cloning $dependency_name into '$dest_dir'." + pushd "$env:DEPS_DIR" + git clone $git_url $dest_dir + popd + + pushd "$dest_dir" + git fetch + cecho.cmd 0 13 "Checking out $dependency_name revision $revision." + git reset --hard + git checkout $revision + popd + exit 0 +} + +function install_cmake_project { + param( + [Parameter(Mandatory = $true)] + [string]$dependency_name, + [Parameter(Mandatory = $true)] + [string]$build_dir, + [Parameter(Mandatory = $true)] + [string]$configuration + ) + pushd "$build_dir" + cecho.cmd 0 13 "Installing $dependency_name ($configuration). Please be patient, this may take a while." + $command = "cmake --install . --config $configuration" + cecho.cmd 0 13 "$command" + Invoke-Expression $command + popd + exit 0 +} + + function main { & setup_build_cfg # Dispatch command.