mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-15 05:37:58 +08:00
[vcpkg] Revise appdeploy and copy_tool_dependencies (#21092)
* Stop overwriting logs when copying tool dependencies * Deploy debug dependencies for debug tools * Deploy dependencies verbosely in debug mode * Don't silently fail deployment on mutex creation error * Construct paths portably * Fix mutex creation on Linux * Abort on mutex creation errors * Always copy tool dependencies in verbose mode
This commit is contained in:
parent
12bdfc7dd2
commit
7dff5e821e
@ -4,7 +4,7 @@ param([string]$targetBinary, [string]$installedDir, [string]$tlogFile, [string]$
|
|||||||
$g_searched = @{}
|
$g_searched = @{}
|
||||||
# Note: installedDir is actually the bin\ directory.
|
# Note: installedDir is actually the bin\ directory.
|
||||||
$g_install_root = Split-Path $installedDir -parent
|
$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
|
# Ensure we create the copied files log, even if we don't end up copying any files
|
||||||
if ($copiedFilesLog)
|
if ($copiedFilesLog)
|
||||||
@ -19,14 +19,19 @@ function computeHash([System.Security.Cryptography.HashAlgorithm]$alg, [string]$
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getMutex([string]$targetDir) {
|
function getMutex([string]$targetDir) {
|
||||||
$sha512Hash = [System.Security.Cryptography.SHA512]::Create()
|
try {
|
||||||
if ($sha512Hash) {
|
$sha512Hash = [System.Security.Cryptography.SHA512]::Create()
|
||||||
$hash = computeHash $sha512Hash $targetDir
|
if ($sha512Hash) {
|
||||||
$mtxName = "VcpkgAppLocalDeployBinary-" + $hash
|
$hash = (computeHash $sha512Hash $targetDir) -replace ('/' ,'-')
|
||||||
return New-Object System.Threading.Mutex($false, $mtxName)
|
$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
|
# Note: this function signature is depended upon by the qtdeploy.ps1 script introduced in 5.7.1-7
|
||||||
@ -37,22 +42,24 @@ function deployBinary([string]$targetBinaryDir, [string]$SourceDir, [string]$tar
|
|||||||
$mtx.WaitOne() | Out-Null
|
$mtx.WaitOne() | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Test-Path "$targetBinaryDir\$targetBinaryName") {
|
$sourceBinaryFilePath = Join-Path $SourceDir $targetBinaryName
|
||||||
$sourceModTime = (Get-Item $SourceDir\$targetBinaryName).LastWriteTime
|
$targetBinaryFilePath = Join-Path $targetBinaryDir $targetBinaryName
|
||||||
$destModTime = (Get-Item $targetBinaryDir\$targetBinaryName).LastWriteTime
|
if (Test-Path $targetBinaryFilePath) {
|
||||||
|
$sourceModTime = (Get-Item $sourceBinaryFilePath).LastWriteTime
|
||||||
|
$destModTime = (Get-Item $targetBinaryFilePath).LastWriteTime
|
||||||
if ($destModTime -lt $sourceModTime) {
|
if ($destModTime -lt $sourceModTime) {
|
||||||
Write-Verbose " ${targetBinaryName}: Updating $SourceDir\$targetBinaryName"
|
Write-Verbose " ${targetBinaryName}: Updating from $sourceBinaryFilePath"
|
||||||
Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir
|
Copy-Item $sourceBinaryFilePath $targetBinaryDir
|
||||||
} else {
|
} else {
|
||||||
Write-Verbose " ${targetBinaryName}: already present"
|
Write-Verbose " ${targetBinaryName}: already present"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Verbose " ${targetBinaryName}: Copying $SourceDir\$targetBinaryName"
|
Write-Verbose " ${targetBinaryName}: Copying $sourceBinaryFilePath"
|
||||||
Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir
|
Copy-Item $sourceBinaryFilePath $targetBinaryDir
|
||||||
}
|
}
|
||||||
if ($copiedFilesLog) { Add-Content $copiedFilesLog "$targetBinaryDir\$targetBinaryName" -Encoding UTF8 }
|
if ($copiedFilesLog) { Add-Content $copiedFilesLog targetBinaryFilePath -Encoding UTF8 }
|
||||||
if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$targetBinaryName" -Encoding Unicode }
|
if ($tlogFile) { Add-Content $tlogFile $targetBinaryFilePath -Encoding Unicode }
|
||||||
} finally {
|
} finally {
|
||||||
if ($mtx) {
|
if ($mtx) {
|
||||||
$mtx.ReleaseMutex() | Out-Null
|
$mtx.ReleaseMutex() | Out-Null
|
||||||
@ -104,24 +111,26 @@ function resolve([string]$targetBinary) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
$g_searched.Set_Item($_, $true)
|
$g_searched.Set_Item($_, $true)
|
||||||
if (Test-Path "$installedDir\$_") {
|
$installedItemFilePath = Join-Path $installedDir $_
|
||||||
|
$targetItemFilePath = Join-Path $targetBinaryDir $_
|
||||||
|
if (Test-Path $installedItemFilePath) {
|
||||||
deployBinary $baseTargetBinaryDir $installedDir "$_"
|
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:\deployOpenNI2) { deployOpenNI2 $targetBinaryDir "$g_install_root" "$_" }
|
||||||
if (Test-Path function:\deployPluginsIfMagnum) {
|
if (Test-Path function:\deployPluginsIfMagnum) {
|
||||||
if ($g_is_debug) {
|
if ($g_is_debug) {
|
||||||
deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum-d" "$_"
|
deployPluginsIfMagnum $targetBinaryDir (Join-Path "$g_install_root" 'bin' 'magnum-d') "$_"
|
||||||
} else {
|
} 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" "$_" }
|
if (Test-Path function:\deployAzureKinectSensorSDK) { deployAzureKinectSensorSDK $targetBinaryDir "$g_install_root" "$_" }
|
||||||
resolve "$baseTargetBinaryDir\$_"
|
resolve (Join-Path $baseTargetBinaryDir "$_")
|
||||||
} elseif (Test-Path "$targetBinaryDir\$_") {
|
} elseif (Test-Path $targetItemFilePath) {
|
||||||
Write-Verbose " ${_}: $_ not found in vcpkg; locally deployed"
|
Write-Verbose " ${_}: $_ not found in $g_install_root; locally deployed"
|
||||||
resolve "$targetBinaryDir\$_"
|
resolve "$targetItemFilePath"
|
||||||
} else {
|
} else {
|
||||||
Write-Verbose " ${_}: $installedDir\$_ not found"
|
Write-Verbose " ${_}: $installedItemFilePath not found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Write-Verbose "Done Resolving $targetBinary."
|
Write-Verbose "Done Resolving $targetBinary."
|
||||||
|
@ -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)
|
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")
|
file(GLOB tools "${tool_dir}/*.exe" "${tool_dir}/*.dll" "${tool_dir}/*.pyd")
|
||||||
foreach(tool IN LISTS tools)
|
foreach(tool IN LISTS tools)
|
||||||
vcpkg_execute_required_process(
|
vcpkg_execute_required_process(
|
||||||
@ -27,10 +32,13 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search)
|
|||||||
-file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1"
|
-file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1"
|
||||||
-targetBinary "${tool}"
|
-targetBinary "${tool}"
|
||||||
-installedDir "${path_to_search}"
|
-installedDir "${path_to_search}"
|
||||||
|
-verbose
|
||||||
WORKING_DIRECTORY "${VCPKG_ROOT_DIR}"
|
WORKING_DIRECTORY "${VCPKG_ROOT_DIR}"
|
||||||
LOGNAME copy-tool-dependencies
|
LOGNAME copy-tool-dependencies-${count}
|
||||||
)
|
)
|
||||||
|
math(EXPR count "${count} + 1")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
set(Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT ${count} CACHE INTERNAL "")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(vcpkg_copy_tool_dependencies tool_dir)
|
function(vcpkg_copy_tool_dependencies tool_dir)
|
||||||
@ -43,7 +51,16 @@ function(vcpkg_copy_tool_dependencies tool_dir)
|
|||||||
if (NOT Z_VCPKG_POWERSHELL_CORE)
|
if (NOT Z_VCPKG_POWERSHELL_CORE)
|
||||||
message(FATAL_ERROR "Could not find PowerShell Core; please open an issue to report this.")
|
message(FATAL_ERROR "Could not find PowerShell Core; please open an issue to report this.")
|
||||||
endif()
|
endif()
|
||||||
z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_PACKAGES_DIR}/bin")
|
cmake_path(RELATIVE_PATH tool_dir
|
||||||
z_vcpkg_copy_tool_dependencies_search("${tool_dir}" "${CURRENT_INSTALLED_DIR}/bin")
|
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()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user