Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions scripts/buildsystems/msbuild/applocal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) -replace ('/' ,'-')
$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 {
Write-Error -Message $_ -ErrorAction Stop
}
}

# Note: this function signature is depended upon by the qtdeploy.ps1 script introduced in 5.7.1-7
Expand All @@ -37,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 link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor output change here.

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
Expand Down Expand Up @@ -104,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."
Expand Down
23 changes: 20 additions & 3 deletions scripts/cmake/vcpkg_copy_tool_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ 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(
COMMAND "${Z_VCPKG_POWERSHELL_CORE}" -noprofile -executionpolicy Bypass -nologo
-file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1"
-targetBinary "${tool}"
-installedDir "${path_to_search}"
-verbose
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 "")
Comment thread
ras0219-msft marked this conversation as resolved.
endfunction()

function(vcpkg_copy_tool_dependencies tool_dir)
Expand All @@ -43,7 +51,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()