01_install_dependencies.ps1 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Param(
  2. [Switch]$Help = $(if (Test-Path variable:Help) { $Help }),
  3. [Switch]$Quiet = $(if (Test-Path variable:Quiet) { $Quiet }),
  4. [Switch]$Verbose = $(if (Test-Path variable:Verbose) { $Verbose }),
  5. [Switch]$NoChoco = $(if (Test-Path variable:NoChoco) { $true } else { $false }),
  6. [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" } else { (Get-CimInstance CIM_OperatingSystem).OSArchitecture }),
  7. [String]$ProductName = $(if (Test-Path variable:ProductName) { "${ProductName}" } else { "obs-plugin" })
  8. )
  9. ##############################################################################
  10. # Windows dependency management function
  11. ##############################################################################
  12. #
  13. # This script file can be included in build scripts for Windows or run
  14. # directly
  15. #
  16. ##############################################################################
  17. $ErrorActionPreference = "Stop"
  18. Function Install-obs-deps {
  19. Param(
  20. [Parameter(Mandatory=$true)]
  21. [String]$Version
  22. )
  23. Write-Status "Setup for pre-built Windows OBS dependencies v${Version}"
  24. Ensure-Directory $DepsBuildDir
  25. if (!(Test-Path $DepsBuildDir/dependencies${Version})) {
  26. Write-Status "Setting up pre-built Windows OBS dependencies v${Version}"
  27. Write-Step "Download..."
  28. $ProgressPreference = $(if ($Quiet.isPresent) { "SilentlyContinue" } else { "Continue" })
  29. Invoke-WebRequest -Uri "https://cdn-fastly.obsproject.com/downloads/dependencies${Version}.zip" -UseBasicParsing -OutFile "dependencies${Version}.zip"
  30. $ProgressPreference = 'Continue'
  31. Write-Step "Unpack..."
  32. Expand-Archive -Path "dependencies${Version}.zip"
  33. } else {
  34. Write-Step "Found existing pre-built dependencies..."
  35. }
  36. }
  37. function Install-qt-deps {
  38. Param(
  39. [Parameter(Mandatory=$true)]
  40. [String]$Version
  41. )
  42. Write-Status "Setup for pre-built dependency Qt v${Version}"
  43. Ensure-Directory $DepsBuildDir
  44. if (!(Test-Path $DepsBuildDir/Qt_${Version})) {
  45. Write-Status "Setting up OBS dependency Qt v${Version}"
  46. Write-Step "Download..."
  47. $ProgressPreference = $(if ($Quiet.isPresent) { 'SilentlyContinue' } else { 'Continue' })
  48. Invoke-WebRequest -Uri "https://cdn-fastly.obsproject.com/downloads/Qt_${Version}.7z" -UseBasicParsing -OutFile "Qt_${Version}.7z"
  49. $ProgressPreference = 'Continue'
  50. Write-Step "Unpack..."
  51. # TODO: Replace with zip and properly package Qt to share directory with other deps
  52. & 7z x Qt_${Version}.7z
  53. & mv ${Version} "Qt_${Version}"
  54. } else {
  55. Write-Step "Found existing pre-built Qt..."
  56. }
  57. }
  58. function Install-obs-studio {
  59. Param(
  60. [parameter(Mandatory=$true)]
  61. [string]$Version
  62. )
  63. $CheckoutRef = "$(if (!(Test-Path variable:OBSBranch)) { ${OBSBranch} } else { "tags/${OBSVersion}" })"
  64. Write-Status "Setup for OBS Studio v${CheckoutRef}"
  65. Ensure-Directory ${ObsBuildDir}
  66. if (!(Test-Path "${ObsBuildDir}/.git")) {
  67. & git clone --recursive https://github.com/obsproject/obs-studio "${pwd}"
  68. & git fetch origin --tags
  69. & git checkout ${CheckoutRef} -b obs-plugin-build
  70. } else {
  71. $BranchExists = &git show-ref --verify --quiet refs/heads/obs-plugin-build
  72. if ($BranchExists -Eq $false) {
  73. & git checkout ${CheckoutRef} -b obs-plugin-build
  74. } else {
  75. & git checkout obs-plugin-build
  76. }
  77. }
  78. }
  79. function Install-Dependencies {
  80. if(!($NoChoco.isPresent)) {
  81. Install-Windows-Dependencies
  82. }
  83. $BuildDependencies = @(
  84. @('obs-deps', $WindowsDepsVersion),
  85. @('qt-deps', $WindowsQtVersion),
  86. @('obs-studio', $OBSVersion)
  87. )
  88. Foreach($Dependency in ${BuildDependencies}) {
  89. $DependencyName = $Dependency[0]
  90. $DependencyVersion = $Dependency[1]
  91. $FunctionName = "Install-${DependencyName}"
  92. & $FunctionName -Version $DependencyVersion
  93. }
  94. Ensure-Directory ${CheckoutDir}
  95. }
  96. function Install-Dependencies-Standalone {
  97. $CheckoutDir = git rev-parse --show-toplevel
  98. if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
  99. . ${CheckoutDir}/CI/include/build_environment.ps1
  100. }
  101. $DepsBuildDir = "${CheckoutDir}/../obs-build-dependencies"
  102. $ObsBuildDir = "${CheckoutDir}/../obs-studio"
  103. . ${CheckoutDir}/CI/include/build_support_windows.ps1
  104. Write-Status "Setting up plugin build dependencies"
  105. Install-Dependencies
  106. }
  107. function Print-Usage {
  108. $Lines = @(
  109. "Usage: ${MyInvocation.MyCommand.Name}",
  110. "-Help : Print this help",
  111. "-Quiet : Suppress most build process output",
  112. "-Verbose : Enable more verbose build process output",
  113. "-NoChoco : Skip automatic dependency installation via Chocolatey - Default: on"
  114. "-BuildArch : Build architecture to use (32bit or 64bit) - Default: local architecture"
  115. )
  116. $Lines | Write-Host
  117. }
  118. if(!(Test-Path variable:_RunObsBuildScript)) {
  119. if ($Help.isPresent) {
  120. Print-Usage
  121. exit 0
  122. }
  123. Install-Dependencies-Standalone
  124. }