Install-BuildDependencies.ps1 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function Install-BuildDependencies {
  2. <#
  3. .SYNOPSIS
  4. Installs required build dependencies.
  5. .DESCRIPTION
  6. Additional packages might be needed for successful builds. This module contains additional
  7. dependencies available for installation via winget and, if possible, adds their locations
  8. to the environment path for future invocation.
  9. .EXAMPLE
  10. Install-BuildDependencies
  11. #>
  12. param(
  13. [string] $WingetFile = "$PSScriptRoot/.Wingetfile"
  14. )
  15. if ( ! ( Test-Path function:Log-Warning ) ) {
  16. . $PSScriptRoot/Logger.ps1
  17. }
  18. $Host64Bit = [System.Environment]::Is64BitOperatingSystem
  19. $Paths = $Env:Path -split [System.IO.Path]::PathSeparator
  20. $WingetOptions = @('install', '--accept-package-agreements', '--accept-source-agreements')
  21. if ( $script:Quiet ) {
  22. $WingetOptions += '--silent'
  23. }
  24. Get-Content $WingetFile | ForEach-Object {
  25. $_, $Package, $_, $Path, $_, $Binary = ([regex]::Split($_, " (?=(?:[^']|'[^']*')*$)")) -replace ',', '' -replace "'",''
  26. (${Env:ProgramFiles(x86)}, $Env:ProgramFiles) | ForEach-Object {
  27. $Prefix = $_
  28. $FullPath = "${Prefix}\${Path}"
  29. if ( ( Test-Path $FullPath ) -and ! ( $Paths -contains $FullPath ) ) {
  30. $Paths += $FullPath
  31. $Env:Path = $Paths -join [System.IO.Path]::PathSeparator
  32. }
  33. }
  34. Log-Debug "Checking for command ${Binary}"
  35. $Found = Get-Command -ErrorAction SilentlyContinue $Binary
  36. if ( $Found ) {
  37. Log-Status "Found dependency ${Binary} as $($Found.Source)"
  38. } else {
  39. Log-Status "Installing package ${Package}"
  40. try {
  41. $Params = $WingetOptions + $Package
  42. winget @Params
  43. } catch {
  44. throw "Error while installing winget package ${Package}: $_"
  45. }
  46. }
  47. }
  48. }