From f2824eb48b6418a522848a3a428c0c6d2fc42b8d Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 16:02:06 +0100 Subject: [PATCH 1/8] Stop overwriting logs when copying tool dependencies --- scripts/cmake/vcpkg_copy_tool_dependencies.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake index 856a2d7fe25e94..5dd9df91a67bf4 100644 --- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake +++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake @@ -20,6 +20,11 @@ This command should always be called by portfiles after they have finished rearr #]===] function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) + if(DEFINED Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT) + set(count ${Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT}) + else() + set(count 0) + endif() file(GLOB tools "${tool_dir}/*.exe" "${tool_dir}/*.dll" "${tool_dir}/*.pyd") foreach(tool IN LISTS tools) vcpkg_execute_required_process( @@ -28,9 +33,11 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) -targetBinary "${tool}" -installedDir "${path_to_search}" WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" - LOGNAME copy-tool-dependencies + LOGNAME copy-tool-dependencies-${count} ) + math(EXPR count "${count} + 1") endforeach() + set(Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT ${count} CACHE INTERNAL "") endfunction() function(vcpkg_copy_tool_dependencies tool_dir) From 0f6b64ff2aad4a5025c49d1f88f5e6a632f3acbd Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 16:03:30 +0100 Subject: [PATCH 2/8] Deploy debug dependencies for debug tools --- scripts/cmake/vcpkg_copy_tool_dependencies.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake index 5dd9df91a67bf4..8d5532f93b8d55 100644 --- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake +++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake @@ -50,7 +50,16 @@ function(vcpkg_copy_tool_dependencies tool_dir) if (NOT Z_VCPKG_POWERSHELL_CORE) message(FATAL_ERROR "Could not find PowerShell Core; please open an issue to report this.") endif() - z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_PACKAGES_DIR}/bin") - z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_INSTALLED_DIR}/bin") + cmake_path(RELATIVE_PATH tool_dir + BASE_DIRECTORY "${CURRENT_PACKAGES_DIR}" + OUTPUT_VARIABLE relative_tool_dir + ) + if(relative_tool_dir MATCHES "/debug/") + z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_PACKAGES_DIR}/debug/bin") + z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_INSTALLED_DIR}/debug/bin") + else() + z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_PACKAGES_DIR}/bin") + z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_INSTALLED_DIR}/bin") + endif() endif() endfunction() From 00f739339326f8ea5b47767f591411ab69434aa8 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 16:07:05 +0100 Subject: [PATCH 3/8] Deploy dependencies verbosely in debug mode --- scripts/cmake/vcpkg_copy_tool_dependencies.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake index 8d5532f93b8d55..748bb204558c88 100644 --- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake +++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake @@ -25,6 +25,11 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) else() set(count 0) endif() + if(PORT_DEBUG) + set(verbose "-verbose") + else() + set(verbose "") + endif() file(GLOB tools "${tool_dir}/*.exe" "${tool_dir}/*.dll" "${tool_dir}/*.pyd") foreach(tool IN LISTS tools) vcpkg_execute_required_process( @@ -32,6 +37,7 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) -file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1" -targetBinary "${tool}" -installedDir "${path_to_search}" + ${verbose} WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" LOGNAME copy-tool-dependencies-${count} ) From 52212bd0b1ef6547aee02ea81a3ef4d1513a25b9 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 16:09:33 +0100 Subject: [PATCH 4/8] Don't silently fail deployment on mutex creation error --- scripts/buildsystems/msbuild/applocal.ps1 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/buildsystems/msbuild/applocal.ps1 b/scripts/buildsystems/msbuild/applocal.ps1 index abd102ab06a2ed..b8643a9663accd 100644 --- a/scripts/buildsystems/msbuild/applocal.ps1 +++ b/scripts/buildsystems/msbuild/applocal.ps1 @@ -19,14 +19,19 @@ function computeHash([System.Security.Cryptography.HashAlgorithm]$alg, [string]$ } function getMutex([string]$targetDir) { - $sha512Hash = [System.Security.Cryptography.SHA512]::Create() - if ($sha512Hash) { - $hash = computeHash $sha512Hash $targetDir - $mtxName = "VcpkgAppLocalDeployBinary-" + $hash - return New-Object System.Threading.Mutex($false, $mtxName) - } + try { + $sha512Hash = [System.Security.Cryptography.SHA512]::Create() + if ($sha512Hash) { + $hash = computeHash $sha512Hash $targetDir + $mtxName = "VcpkgAppLocalDeployBinary-" + $hash + return New-Object System.Threading.Mutex($false, $mtxName) + } - return New-Object System.Threading.Mutex($false, "VcpkgAppLocalDeployBinary") + return New-Object System.Threading.Mutex($false, "VcpkgAppLocalDeployBinary") + } + catch { + return 0 + } } # Note: this function signature is depended upon by the qtdeploy.ps1 script introduced in 5.7.1-7 From 0b4c2b4e1654b1cd944d8e976f1b1c1920c11e4a Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 16:12:50 +0100 Subject: [PATCH 5/8] Construct paths portably --- scripts/buildsystems/msbuild/applocal.ps1 | 42 +++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/scripts/buildsystems/msbuild/applocal.ps1 b/scripts/buildsystems/msbuild/applocal.ps1 index b8643a9663accd..5f54707fc70cd2 100644 --- a/scripts/buildsystems/msbuild/applocal.ps1 +++ b/scripts/buildsystems/msbuild/applocal.ps1 @@ -4,7 +4,7 @@ param([string]$targetBinary, [string]$installedDir, [string]$tlogFile, [string]$ $g_searched = @{} # Note: installedDir is actually the bin\ directory. $g_install_root = Split-Path $installedDir -parent -$g_is_debug = $g_install_root -match '(.*\\)?debug(\\)?$' +$g_is_debug = (Split-Path $g_install_root -leaf) -eq 'debug' # Ensure we create the copied files log, even if we don't end up copying any files if ($copiedFilesLog) @@ -42,22 +42,24 @@ function deployBinary([string]$targetBinaryDir, [string]$SourceDir, [string]$tar $mtx.WaitOne() | Out-Null } - if (Test-Path "$targetBinaryDir\$targetBinaryName") { - $sourceModTime = (Get-Item $SourceDir\$targetBinaryName).LastWriteTime - $destModTime = (Get-Item $targetBinaryDir\$targetBinaryName).LastWriteTime + $sourceBinaryFilePath = Join-Path $SourceDir $targetBinaryName + $targetBinaryFilePath = Join-Path $targetBinaryDir $targetBinaryName + if (Test-Path $targetBinaryFilePath) { + $sourceModTime = (Get-Item $sourceBinaryFilePath).LastWriteTime + $destModTime = (Get-Item $targetBinaryFilePath).LastWriteTime if ($destModTime -lt $sourceModTime) { - Write-Verbose " ${targetBinaryName}: Updating $SourceDir\$targetBinaryName" - Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir + Write-Verbose " ${targetBinaryName}: Updating from $sourceBinaryFilePath" + Copy-Item $sourceBinaryFilePath $targetBinaryDir } else { Write-Verbose " ${targetBinaryName}: already present" } } else { - Write-Verbose " ${targetBinaryName}: Copying $SourceDir\$targetBinaryName" - Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir + Write-Verbose " ${targetBinaryName}: Copying $sourceBinaryFilePath" + Copy-Item $sourceBinaryFilePath $targetBinaryDir } - if ($copiedFilesLog) { Add-Content $copiedFilesLog "$targetBinaryDir\$targetBinaryName" -Encoding UTF8 } - if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$targetBinaryName" -Encoding Unicode } + if ($copiedFilesLog) { Add-Content $copiedFilesLog targetBinaryFilePath -Encoding UTF8 } + if ($tlogFile) { Add-Content $tlogFile $targetBinaryFilePath -Encoding Unicode } } finally { if ($mtx) { $mtx.ReleaseMutex() | Out-Null @@ -109,24 +111,26 @@ function resolve([string]$targetBinary) { return } $g_searched.Set_Item($_, $true) - if (Test-Path "$installedDir\$_") { + $installedItemFilePath = Join-Path $installedDir $_ + $targetItemFilePath = Join-Path $targetBinaryDir $_ + if (Test-Path $installedItemFilePath) { deployBinary $baseTargetBinaryDir $installedDir "$_" - if (Test-Path function:\deployPluginsIfQt) { deployPluginsIfQt $baseTargetBinaryDir "$g_install_root\plugins" "$_" } + if (Test-Path function:\deployPluginsIfQt) { deployPluginsIfQt $baseTargetBinaryDir (Join-Path $g_install_root 'plugins') "$_" } if (Test-Path function:\deployOpenNI2) { deployOpenNI2 $targetBinaryDir "$g_install_root" "$_" } if (Test-Path function:\deployPluginsIfMagnum) { if ($g_is_debug) { - deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum-d" "$_" + deployPluginsIfMagnum $targetBinaryDir (Join-Path "$g_install_root" 'bin' 'magnum-d') "$_" } else { - deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum" "$_" + deployPluginsIfMagnum $targetBinaryDir (Join-Path "$g_install_root" 'bin' 'magnum') "$_" } } if (Test-Path function:\deployAzureKinectSensorSDK) { deployAzureKinectSensorSDK $targetBinaryDir "$g_install_root" "$_" } - resolve "$baseTargetBinaryDir\$_" - } elseif (Test-Path "$targetBinaryDir\$_") { - Write-Verbose " ${_}: $_ not found in vcpkg; locally deployed" - resolve "$targetBinaryDir\$_" + resolve (Join-Path $baseTargetBinaryDir "$_") + } elseif (Test-Path $targetItemFilePath) { + Write-Verbose " ${_}: $_ not found in $g_install_root; locally deployed" + resolve "$targetItemFilePath" } else { - Write-Verbose " ${_}: $installedDir\$_ not found" + Write-Verbose " ${_}: $installedItemFilePath not found" } } Write-Verbose "Done Resolving $targetBinary." From eadfb26f0b5fb04951ee505a1d2be1cc602768d0 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 18:44:32 +0100 Subject: [PATCH 6/8] Fix mutex creation on Linux --- scripts/buildsystems/msbuild/applocal.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/buildsystems/msbuild/applocal.ps1 b/scripts/buildsystems/msbuild/applocal.ps1 index 5f54707fc70cd2..08a18fac48d9e5 100644 --- a/scripts/buildsystems/msbuild/applocal.ps1 +++ b/scripts/buildsystems/msbuild/applocal.ps1 @@ -22,7 +22,7 @@ function getMutex([string]$targetDir) { try { $sha512Hash = [System.Security.Cryptography.SHA512]::Create() if ($sha512Hash) { - $hash = computeHash $sha512Hash $targetDir + $hash = (computeHash $sha512Hash $targetDir) -replace ('/' ,'-') $mtxName = "VcpkgAppLocalDeployBinary-" + $hash return New-Object System.Threading.Mutex($false, $mtxName) } From 03fe1056e4da960d6f59dd1c98613f2650fa5d34 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 18:45:14 +0100 Subject: [PATCH 7/8] Abort on mutex creation errors --- scripts/buildsystems/msbuild/applocal.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/buildsystems/msbuild/applocal.ps1 b/scripts/buildsystems/msbuild/applocal.ps1 index 08a18fac48d9e5..412e8e56cb31df 100644 --- a/scripts/buildsystems/msbuild/applocal.ps1 +++ b/scripts/buildsystems/msbuild/applocal.ps1 @@ -30,7 +30,7 @@ function getMutex([string]$targetDir) { return New-Object System.Threading.Mutex($false, "VcpkgAppLocalDeployBinary") } catch { - return 0 + Write-Error -Message $_ -ErrorAction Stop } } From a572b49a20bd6b54a1c3c98f3c9f6b05d92b18de Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 31 Oct 2021 18:48:18 +0100 Subject: [PATCH 8/8] Always copy tool dependencies in verbose mode --- scripts/cmake/vcpkg_copy_tool_dependencies.cmake | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake index 748bb204558c88..b2c36a8e5b9df7 100644 --- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake +++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake @@ -25,11 +25,6 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) else() set(count 0) endif() - if(PORT_DEBUG) - set(verbose "-verbose") - else() - set(verbose "") - endif() file(GLOB tools "${tool_dir}/*.exe" "${tool_dir}/*.dll" "${tool_dir}/*.pyd") foreach(tool IN LISTS tools) vcpkg_execute_required_process( @@ -37,7 +32,7 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) -file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1" -targetBinary "${tool}" -installedDir "${path_to_search}" - ${verbose} + -verbose WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" LOGNAME copy-tool-dependencies-${count} )