|
| 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 | +<# |
| 8 | +
|
| 9 | +.SYNOPSIS |
| 10 | +This is a Powershell script to bootstrap a Cake build. |
| 11 | +
|
| 12 | +.DESCRIPTION |
| 13 | +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) |
| 14 | +and execute your Cake build script with the parameters you provide. |
| 15 | +
|
| 16 | +.PARAMETER Script |
| 17 | +The build script to execute. |
| 18 | +.PARAMETER Target |
| 19 | +The build script target to run. |
| 20 | +.PARAMETER Configuration |
| 21 | +The build configuration to use. |
| 22 | +.PARAMETER Verbosity |
| 23 | +Specifies the amount of information to be displayed. |
| 24 | +.PARAMETER Experimental |
| 25 | +Tells Cake to use the latest Roslyn release. |
| 26 | +.PARAMETER WhatIf |
| 27 | +Performs a dry run of the build script. |
| 28 | +No tasks will be executed. |
| 29 | +.PARAMETER Mono |
| 30 | +Tells Cake to use the Mono scripting engine. |
| 31 | +.PARAMETER SkipToolPackageRestore |
| 32 | +Skips restoring of packages. |
| 33 | +.PARAMETER ScriptArgs |
| 34 | +Remaining arguments are added here. |
| 35 | +
|
| 36 | +.LINK |
| 37 | +http://cakebuild.net |
| 38 | +
|
| 39 | +#> |
| 40 | + |
| 41 | +[CmdletBinding()] |
| 42 | +Param( |
| 43 | + [string]$Script = "deploy.cake", |
| 44 | + [string]$Target = "Default", |
| 45 | + [string]$Configuration = "Release", |
| 46 | + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] |
| 47 | + [string]$Verbosity = "Verbose", |
| 48 | + [switch]$Experimental, |
| 49 | + [Alias("DryRun","Noop")] |
| 50 | + [switch]$WhatIf, |
| 51 | + [switch]$Mono, |
| 52 | + [switch]$SkipToolPackageRestore, |
| 53 | + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] |
| 54 | + [string[]]$ScriptArgs |
| 55 | +) |
| 56 | + |
| 57 | +Write-Host "Preparing to run build script..." |
| 58 | + |
| 59 | +$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition; |
| 60 | +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" |
| 61 | +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" |
| 62 | +$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe" |
| 63 | +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" |
| 64 | +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" |
| 65 | + |
| 66 | +# Should we use mono? |
| 67 | +$UseMono = ""; |
| 68 | +if($Mono.IsPresent) { |
| 69 | + Write-Verbose -Message "Using the Mono based scripting engine." |
| 70 | + $UseMono = "-mono" |
| 71 | +} |
| 72 | + |
| 73 | +# Should we use the new Roslyn? |
| 74 | +$UseExperimental = ""; |
| 75 | +if($Experimental.IsPresent -and !($Mono.IsPresent)) { |
| 76 | + Write-Verbose -Message "Using experimental version of Roslyn." |
| 77 | + $UseExperimental = "-experimental" |
| 78 | +} |
| 79 | + |
| 80 | +# Is this a dry run? |
| 81 | +$UseDryRun = ""; |
| 82 | +if($WhatIf.IsPresent) { |
| 83 | + $UseDryRun = "-dryrun" |
| 84 | +} |
| 85 | + |
| 86 | +# Make sure tools folder exists |
| 87 | +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { |
| 88 | + Write-Verbose -Message "Creating tools directory..." |
| 89 | + New-Item -Path $TOOLS_DIR -Type directory | out-null |
| 90 | +} |
| 91 | + |
| 92 | +# Make sure that packages.config exist. |
| 93 | +if (!(Test-Path $PACKAGES_CONFIG)) { |
| 94 | + Write-Verbose -Message "Downloading packages.config..." |
| 95 | + try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch { |
| 96 | + Throw "Could not download packages.config." |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +# Try find NuGet.exe in path if not exists |
| 101 | +if (!(Test-Path $NUGET_EXE)) { |
| 102 | + Write-Verbose -Message "Trying to find nuget.exe in PATH..." |
| 103 | + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) } |
| 104 | + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 |
| 105 | + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { |
| 106 | + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." |
| 107 | + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +# Try download NuGet.exe if not exists |
| 112 | +if (!(Test-Path $NUGET_EXE)) { |
| 113 | + Write-Verbose -Message "Downloading NuGet.exe..." |
| 114 | + try { |
| 115 | + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) |
| 116 | + } catch { |
| 117 | + Throw "Could not download NuGet.exe." |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +# Save nuget.exe path to environment to be available to child processed |
| 122 | +$ENV:NUGET_EXE = $NUGET_EXE |
| 123 | + |
| 124 | +# Restore tools from NuGet? |
| 125 | +if(-Not $SkipToolPackageRestore.IsPresent) { |
| 126 | + Push-Location |
| 127 | + Set-Location $TOOLS_DIR |
| 128 | + Write-Verbose -Message "Restoring tools from NuGet..." |
| 129 | + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" |
| 130 | + if ($LASTEXITCODE -ne 0) { |
| 131 | + Throw "An error occured while restoring NuGet tools." |
| 132 | + } |
| 133 | + Write-Verbose -Message ($NuGetOutput | out-string) |
| 134 | + Pop-Location |
| 135 | +} |
| 136 | + |
| 137 | +# Make sure that Cake has been installed. |
| 138 | +if (!(Test-Path $CAKE_EXE)) { |
| 139 | + Throw "Could not find Cake.exe at $CAKE_EXE" |
| 140 | +} |
| 141 | + |
| 142 | +# Start Cake |
| 143 | +Write-Host "Running build script..." |
| 144 | +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" |
| 145 | +exit $LASTEXITCODE |
0 commit comments