]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | [cmdletbinding()] |
2 | param([string]$targetBinary, [string]$installedDir, [string]$tlogFile, [string]$copiedFilesLog) | |
3 | ||
4 | $g_searched = @{} | |
5 | # Note: installedDir is actually the bin\ directory. | |
6 | $g_install_root = Split-Path $installedDir -parent | |
7 | $g_is_debug = $g_install_root -match '(.*\\)?debug(\\)?$' | |
8 | ||
9 | # Ensure we create the copied files log, even if we don't end up copying any files | |
10 | if ($copiedFilesLog) | |
11 | { | |
12 | Set-Content -Path $copiedFilesLog -Value "" -Encoding UTF8 | |
13 | } | |
14 | ||
15 | function computeHash([System.Security.Cryptography.HashAlgorithm]$alg, [string]$str) { | |
16 | $bytes = [System.Text.Encoding]::UTF8.GetBytes($str) | |
17 | $hash = $alg.ComputeHash($bytes) | |
18 | return [Convert]::ToBase64String($hash) | |
19 | } | |
20 | ||
21 | function getMutex([string]$targetDir) { | |
22 | $sha512Hash = [System.Security.Cryptography.SHA512]::Create() | |
23 | if ($sha512Hash) { | |
24 | $hash = computeHash $sha512Hash $targetDir | |
25 | $mtxName = "VcpkgAppLocalDeployBinary-" + $hash | |
26 | return New-Object System.Threading.Mutex($false, $mtxName) | |
27 | } | |
28 | ||
29 | return New-Object System.Threading.Mutex($false, "VcpkgAppLocalDeployBinary") | |
30 | } | |
31 | ||
32 | # Note: this function signature is depended upon by the qtdeploy.ps1 script introduced in 5.7.1-7 | |
33 | function deployBinary([string]$targetBinaryDir, [string]$SourceDir, [string]$targetBinaryName) { | |
34 | try { | |
35 | $mtx = getMutex($targetBinaryDir) | |
36 | if ($mtx) { | |
37 | $mtx.WaitOne() | Out-Null | |
38 | } | |
39 | ||
40 | if (Test-Path "$targetBinaryDir\$targetBinaryName") { | |
41 | $sourceModTime = (Get-Item $SourceDir\$targetBinaryName).LastWriteTime | |
42 | $destModTime = (Get-Item $targetBinaryDir\$targetBinaryName).LastWriteTime | |
43 | if ($destModTime -lt $sourceModTime) { | |
44 | Write-Verbose " ${targetBinaryName}: Updating $SourceDir\$targetBinaryName" | |
45 | Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir | |
46 | } else { | |
47 | Write-Verbose " ${targetBinaryName}: already present" | |
48 | } | |
49 | } | |
50 | else { | |
51 | Write-Verbose " ${targetBinaryName}: Copying $SourceDir\$targetBinaryName" | |
52 | Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir | |
53 | } | |
54 | if ($copiedFilesLog) { Add-Content $copiedFilesLog "$targetBinaryDir\$targetBinaryName" -Encoding UTF8 } | |
55 | if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$targetBinaryName" -Encoding Unicode } | |
56 | } finally { | |
57 | if ($mtx) { | |
58 | $mtx.ReleaseMutex() | Out-Null | |
59 | $mtx.Dispose() | Out-Null | |
60 | } | |
61 | } | |
62 | } | |
63 | ||
64 | ||
65 | Write-Verbose "Resolving base path $targetBinary..." | |
66 | try | |
67 | { | |
68 | $baseBinaryPath = Resolve-Path $targetBinary -erroraction stop | |
69 | $baseTargetBinaryDir = Split-Path $baseBinaryPath -parent | |
70 | } | |
71 | catch [System.Management.Automation.ItemNotFoundException] | |
72 | { | |
73 | return | |
74 | } | |
75 | ||
76 | # Note: this function signature is depended upon by the qtdeploy.ps1 script | |
77 | function resolve([string]$targetBinary) { | |
78 | Write-Verbose "Resolving $targetBinary..." | |
79 | try | |
80 | { | |
81 | $targetBinaryPath = Resolve-Path $targetBinary -erroraction stop | |
82 | } | |
83 | catch [System.Management.Automation.ItemNotFoundException] | |
84 | { | |
85 | return | |
86 | } | |
87 | $targetBinaryDir = Split-Path $targetBinaryPath -parent | |
88 | ||
89 | if (Get-Command "dumpbin" -ErrorAction SilentlyContinue) { | |
90 | $a = $(dumpbin /DEPENDENTS $targetBinary | ? { $_ -match "^ [^ ].*\.dll" } | % { $_ -replace "^ ","" }) | |
91 | } elseif (Get-Command "llvm-objdump" -ErrorAction SilentlyContinue) { | |
92 | $a = $(llvm-objdump -p $targetBinary| ? { $_ -match "^ {4}DLL Name: .*\.dll" } | % { $_ -replace "^ {4}DLL Name: ","" }) | |
93 | } else { | |
94 | Write-Error "Neither dumpbin nor llvm-objdump could be found. Can not take care of dll dependencies." | |
95 | } | |
96 | $a | % { | |
97 | if ([string]::IsNullOrEmpty($_)) { | |
98 | return | |
99 | } | |
100 | if ($g_searched.ContainsKey($_)) { | |
101 | Write-Verbose " ${_}: previously searched - Skip" | |
102 | return | |
103 | } | |
104 | $g_searched.Set_Item($_, $true) | |
105 | if (Test-Path "$installedDir\$_") { | |
106 | deployBinary $baseTargetBinaryDir $installedDir "$_" | |
107 | if (Test-Path function:\deployPluginsIfQt) { deployPluginsIfQt $baseTargetBinaryDir "$g_install_root\plugins" "$_" } | |
108 | if (Test-Path function:\deployOpenNI2) { deployOpenNI2 $targetBinaryDir "$g_install_root" "$_" } | |
109 | if (Test-Path function:\deployPluginsIfMagnum) { | |
110 | if ($g_is_debug) { | |
111 | deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum-d" "$_" | |
112 | } else { | |
113 | deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum" "$_" | |
114 | } | |
115 | } | |
116 | if (Test-Path function:\deployAzureKinectSensorSDK) { deployAzureKinectSensorSDK $targetBinaryDir "$g_install_root" "$_" } | |
117 | resolve "$baseTargetBinaryDir\$_" | |
118 | } elseif (Test-Path "$targetBinaryDir\$_") { | |
119 | Write-Verbose " ${_}: $_ not found in vcpkg; locally deployed" | |
120 | resolve "$targetBinaryDir\$_" | |
121 | } else { | |
122 | Write-Verbose " ${_}: $installedDir\$_ not found" | |
123 | } | |
124 | } | |
125 | Write-Verbose "Done Resolving $targetBinary." | |
126 | } | |
127 | ||
128 | # Note: This is a hack to make Qt5 work. | |
129 | # Introduced with Qt package version 5.7.1-7 | |
130 | if (Test-Path "$g_install_root\plugins\qtdeploy.ps1") { | |
131 | . "$g_install_root\plugins\qtdeploy.ps1" | |
132 | } | |
133 | ||
134 | # Note: This is a hack to make OpenNI2 work. | |
135 | if (Test-Path "$g_install_root\bin\OpenNI2\openni2deploy.ps1") { | |
136 | . "$g_install_root\bin\OpenNI2\openni2deploy.ps1" | |
137 | } | |
138 | ||
139 | # Note: This is a hack to make Magnum work. | |
140 | if (Test-Path "$g_install_root\bin\magnum\magnumdeploy.ps1") { | |
141 | . "$g_install_root\bin\magnum\magnumdeploy.ps1" | |
142 | } elseif (Test-Path "$g_install_root\bin\magnum-d\magnumdeploy.ps1") { | |
143 | . "$g_install_root\bin\magnum-d\magnumdeploy.ps1" | |
144 | } | |
145 | ||
146 | # Note: This is a hack to make Azure Kinect Sensor SDK work. | |
147 | if (Test-Path "$g_install_root\tools\azure-kinect-sensor-sdk\k4adeploy.ps1") { | |
148 | . "$g_install_root\tools\azure-kinect-sensor-sdk\k4adeploy.ps1" | |
149 | } | |
150 | ||
151 | resolve($targetBinary) | |
152 | Write-Verbose $($g_searched | out-string) |