applocal.ps1 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. [cmdletbinding()]
  2. param([string]$targetBinary, [string]$installedDir, [string]$tlogFile, [string]$copiedFilesLog, [string]$outputDir)
  3. $g_searched = @{}
  4. # Note: installedDir is actually the bin\ directory.
  5. $g_install_root = Split-Path $installedDir -parent
  6. $g_is_debug = $g_install_root -match '(.*\\)?debug(\\)?$'
  7. # Ensure we create the copied files log, even if we don't end up copying any files
  8. if ($copiedFilesLog)
  9. {
  10. Set-Content -Path $copiedFilesLog -Value "" -Encoding UTF8
  11. }
  12. # Note: this function signature is depended upon by the qtdeploy.ps1 script introduced in 5.7.1-7
  13. function deployBinary([string]$targetBinaryDir, [string]$SourceDir, [string]$targetBinaryName) {
  14. if (Test-Path "$targetBinaryDir\$targetBinaryName") {
  15. $sourceModTime = (Get-Item $SourceDir\$targetBinaryName).LastWriteTime
  16. $destModTime = (Get-Item $targetBinaryDir\$targetBinaryName).LastWriteTime
  17. if ($destModTime -lt $sourceModTime) {
  18. Write-Verbose " ${targetBinaryName}: Updating $SourceDir\$targetBinaryName"
  19. Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir
  20. } else {
  21. Write-Verbose " ${targetBinaryName}: already present"
  22. }
  23. }
  24. else {
  25. Write-Verbose " ${targetBinaryName}: Copying $SourceDir\$targetBinaryName"
  26. Copy-Item "$SourceDir\$targetBinaryName" $targetBinaryDir
  27. }
  28. if ($copiedFilesLog) { Add-Content $copiedFilesLog "$targetBinaryDir\$targetBinaryName" -Encoding UTF8 }
  29. if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$targetBinaryName" -Encoding Unicode }
  30. }
  31. Write-Verbose "Resolving base path $targetBinary..."
  32. try
  33. {
  34. $baseBinaryPath = Resolve-Path $targetBinary -erroraction stop
  35. $baseTargetBinaryDir = Split-Path $baseBinaryPath -parent
  36. if (![string]::IsNullOrEmpty($outputDir)) {
  37. if (Test-Path "$outputDir\$_"){
  38. $baseTargetBinaryDir = $outputDir
  39. } else {
  40. Write-Error " ${outputDir} not found"
  41. return
  42. }
  43. }
  44. }
  45. catch [System.Management.Automation.ItemNotFoundException]
  46. {
  47. return
  48. }
  49. # Note: this function signature is depended upon by the qtdeploy.ps1 script
  50. function resolve([string]$targetBinary) {
  51. Write-Verbose "Resolving $targetBinary..."
  52. try
  53. {
  54. $targetBinaryPath = Resolve-Path $targetBinary -erroraction stop
  55. }
  56. catch [System.Management.Automation.ItemNotFoundException]
  57. {
  58. return
  59. }
  60. $targetBinaryDir = Split-Path $targetBinaryPath -parent
  61. $a = $(dumpbin /DEPENDENTS $targetBinary | ? { $_ -match "^ [^ ].*\.dll" } | % { $_ -replace "^ ","" })
  62. $a | % {
  63. if ([string]::IsNullOrEmpty($_)) {
  64. return
  65. }
  66. if ($g_searched.ContainsKey($_)) {
  67. Write-Verbose " ${_}: previously searched - Skip"
  68. return
  69. }
  70. $g_searched.Set_Item($_, $true)
  71. if (Test-Path "$installedDir\$_") {
  72. deployBinary $baseTargetBinaryDir $installedDir "$_"
  73. if (Test-Path function:\deployPluginsIfQt) { deployPluginsIfQt $baseTargetBinaryDir "$g_install_root\plugins" "$_" }
  74. if (Test-Path function:\deployOpenNI2) { deployOpenNI2 $targetBinaryDir "$g_install_root" "$_" }
  75. if (Test-Path function:\deployPluginsIfMagnum) {
  76. if ($g_is_debug) {
  77. deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum-d" "$_"
  78. } else {
  79. deployPluginsIfMagnum $targetBinaryDir "$g_install_root\bin\magnum" "$_"
  80. }
  81. }
  82. if (Test-Path function:\deployAzureKinectSensorSDK) { deployAzureKinectSensorSDK $targetBinaryDir "$g_install_root" "$_" }
  83. resolve "$baseTargetBinaryDir\$_"
  84. } elseif (Test-Path "$targetBinaryDir\$_") {
  85. Write-Verbose " ${_}: $_ not found in vcpkg; locally deployed"
  86. resolve "$targetBinaryDir\$_"
  87. } else {
  88. Write-Verbose " ${_}: $installedDir\$_ not found"
  89. }
  90. }
  91. Write-Verbose "Done Resolving $targetBinary."
  92. }
  93. # Note: This is a hack to make Qt5 work.
  94. # Introduced with Qt package version 5.7.1-7
  95. if (Test-Path "$g_install_root\plugins\qtdeploy.ps1") {
  96. . "$g_install_root\plugins\qtdeploy.ps1"
  97. }
  98. # Note: This is a hack to make OpenNI2 work.
  99. if (Test-Path "$g_install_root\bin\OpenNI2\openni2deploy.ps1") {
  100. . "$g_install_root\bin\OpenNI2\openni2deploy.ps1"
  101. }
  102. # Note: This is a hack to make Magnum work.
  103. if (Test-Path "$g_install_root\bin\magnum\magnumdeploy.ps1") {
  104. . "$g_install_root\bin\magnum\magnumdeploy.ps1"
  105. } elseif (Test-Path "$g_install_root\bin\magnum-d\magnumdeploy.ps1") {
  106. . "$g_install_root\bin\magnum-d\magnumdeploy.ps1"
  107. }
  108. # Note: This is a hack to make Azure Kinect Sensor SDK work.
  109. if (Test-Path "$g_install_root\tools\azure-kinect-sensor-sdk\k4adeploy.ps1") {
  110. . "$g_install_root\tools\azure-kinect-sensor-sdk\k4adeploy.ps1"
  111. }
  112. resolve($targetBinary)
  113. Write-Verbose $($g_searched | out-string)