Audio and MIDI library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
7.3 KiB

  1. ##########################################################################
  2. # This is the Cake bootstrapper script for PowerShell.
  3. # This file was downloaded from https://github.com/cake-build/resources
  4. # Feel free to change this file to fit your needs.
  5. ##########################################################################
  6. <#
  7. .SYNOPSIS
  8. This is a Powershell script to bootstrap a Cake build.
  9. .DESCRIPTION
  10. This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
  11. and execute your Cake build script with the parameters you provide.
  12. .PARAMETER Script
  13. The build script to execute.
  14. .PARAMETER Target
  15. The build script target to run.
  16. .PARAMETER Configuration
  17. The build configuration to use.
  18. .PARAMETER Verbosity
  19. Specifies the amount of information to be displayed.
  20. .PARAMETER ShowDescription
  21. Shows description about tasks.
  22. .PARAMETER DryRun
  23. Performs a dry run.
  24. .PARAMETER Experimental
  25. Uses the nightly builds of the Roslyn script engine.
  26. .PARAMETER Mono
  27. Uses the Mono Compiler rather than the Roslyn script engine.
  28. .PARAMETER SkipToolPackageRestore
  29. Skips restoring of packages.
  30. .PARAMETER ScriptArgs
  31. Remaining arguments are added here.
  32. .LINK
  33. https://cakebuild.net
  34. #>
  35. [CmdletBinding()]
  36. Param(
  37. [string]$Script = "build.cake",
  38. [string]$Target,
  39. [string]$Configuration,
  40. [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
  41. [string]$Verbosity,
  42. [switch]$ShowDescription,
  43. [Alias("WhatIf", "Noop")]
  44. [switch]$DryRun,
  45. [switch]$Experimental,
  46. [switch]$Mono,
  47. [switch]$SkipToolPackageRestore,
  48. [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
  49. [string[]]$ScriptArgs
  50. )
  51. [Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
  52. function MD5HashFile([string] $filePath)
  53. {
  54. if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
  55. {
  56. return $null
  57. }
  58. [System.IO.Stream] $file = $null;
  59. [System.Security.Cryptography.MD5] $md5 = $null;
  60. try
  61. {
  62. $md5 = [System.Security.Cryptography.MD5]::Create()
  63. $file = [System.IO.File]::OpenRead($filePath)
  64. return [System.BitConverter]::ToString($md5.ComputeHash($file))
  65. }
  66. finally
  67. {
  68. if ($file -ne $null)
  69. {
  70. $file.Dispose()
  71. }
  72. }
  73. }
  74. function GetProxyEnabledWebClient
  75. {
  76. $wc = New-Object System.Net.WebClient
  77. $proxy = [System.Net.WebRequest]::GetSystemWebProxy()
  78. $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
  79. $wc.Proxy = $proxy
  80. return $wc
  81. }
  82. Write-Host "Preparing to run build script..."
  83. if(!$PSScriptRoot){
  84. $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
  85. }
  86. $TOOLS_DIR = Join-Path $PSScriptRoot "tools"
  87. $ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
  88. $MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
  89. $NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
  90. $CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
  91. $NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
  92. $PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
  93. $PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
  94. $ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
  95. $MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
  96. # Make sure tools folder exists
  97. if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
  98. Write-Verbose -Message "Creating tools directory..."
  99. New-Item -Path $TOOLS_DIR -Type directory | out-null
  100. }
  101. # Make sure that packages.config exist.
  102. if (!(Test-Path $PACKAGES_CONFIG)) {
  103. Write-Verbose -Message "Downloading packages.config..."
  104. try {
  105. $wc = GetProxyEnabledWebClient
  106. $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
  107. Throw "Could not download packages.config."
  108. }
  109. }
  110. # Try find NuGet.exe in path if not exists
  111. if (!(Test-Path $NUGET_EXE)) {
  112. Write-Verbose -Message "Trying to find nuget.exe in PATH..."
  113. $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
  114. $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
  115. if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
  116. Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
  117. $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
  118. }
  119. }
  120. # Try download NuGet.exe if not exists
  121. if (!(Test-Path $NUGET_EXE)) {
  122. Write-Verbose -Message "Downloading NuGet.exe..."
  123. try {
  124. $wc = GetProxyEnabledWebClient
  125. $wc.DownloadFile($NUGET_URL, $NUGET_EXE)
  126. } catch {
  127. Throw "Could not download NuGet.exe."
  128. }
  129. }
  130. # Save nuget.exe path to environment to be available to child processed
  131. $ENV:NUGET_EXE = $NUGET_EXE
  132. # Restore tools from NuGet?
  133. if(-Not $SkipToolPackageRestore.IsPresent) {
  134. Push-Location
  135. Set-Location $TOOLS_DIR
  136. # Check for changes in packages.config and remove installed tools if true.
  137. [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
  138. if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
  139. ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
  140. Write-Verbose -Message "Missing or changed package.config hash..."
  141. Remove-Item * -Recurse -Exclude packages.config,nuget.exe
  142. }
  143. Write-Verbose -Message "Restoring tools from NuGet..."
  144. $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
  145. if ($LASTEXITCODE -ne 0) {
  146. Throw "An error occurred while restoring NuGet tools."
  147. }
  148. else
  149. {
  150. $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
  151. }
  152. Write-Verbose -Message ($NuGetOutput | out-string)
  153. Pop-Location
  154. }
  155. # Restore addins from NuGet
  156. if (Test-Path $ADDINS_PACKAGES_CONFIG) {
  157. Push-Location
  158. Set-Location $ADDINS_DIR
  159. Write-Verbose -Message "Restoring addins from NuGet..."
  160. $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
  161. if ($LASTEXITCODE -ne 0) {
  162. Throw "An error occurred while restoring NuGet addins."
  163. }
  164. Write-Verbose -Message ($NuGetOutput | out-string)
  165. Pop-Location
  166. }
  167. # Restore modules from NuGet
  168. if (Test-Path $MODULES_PACKAGES_CONFIG) {
  169. Push-Location
  170. Set-Location $MODULES_DIR
  171. Write-Verbose -Message "Restoring modules from NuGet..."
  172. $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
  173. if ($LASTEXITCODE -ne 0) {
  174. Throw "An error occurred while restoring NuGet modules."
  175. }
  176. Write-Verbose -Message ($NuGetOutput | out-string)
  177. Pop-Location
  178. }
  179. # Make sure that Cake has been installed.
  180. if (!(Test-Path $CAKE_EXE)) {
  181. Throw "Could not find Cake.exe at $CAKE_EXE"
  182. }
  183. # Build Cake arguments
  184. $cakeArguments = @("$Script");
  185. if ($Target) { $cakeArguments += "-target=$Target" }
  186. if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
  187. if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
  188. if ($ShowDescription) { $cakeArguments += "-showdescription" }
  189. if ($DryRun) { $cakeArguments += "-dryrun" }
  190. if ($Experimental) { $cakeArguments += "-experimental" }
  191. if ($Mono) { $cakeArguments += "-mono" }
  192. $cakeArguments += $ScriptArgs
  193. # Start Cake
  194. Write-Host "Running build script..."
  195. &$CAKE_EXE $cakeArguments
  196. exit $LASTEXITCODE