Skip to content

Commit 6655093

Browse files
committed
Updated to Cake 0.16.1
1 parent c7746f7 commit 6655093

File tree

3 files changed

+171
-37
lines changed

3 files changed

+171
-37
lines changed

build.ps1

+136-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
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()]
142
Param(
243
[string]$Script = "build.cake",
344
[string]$Target = "Default",
@@ -6,22 +47,63 @@ Param(
647
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
748
[string]$Verbosity = "Verbose",
849
[switch]$Experimental,
50+
[Alias("DryRun","Noop")]
951
[switch]$WhatIf,
1052
[switch]$Mono,
1153
[switch]$SkipToolPackageRestore,
1254
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
1355
[string[]]$ScriptArgs
1456
)
1557

16-
$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition;
58+
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
59+
function MD5HashFile([string] $filePath)
60+
{
61+
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
62+
{
63+
return $null
64+
}
65+
66+
[System.IO.Stream] $file = $null;
67+
[System.Security.Cryptography.MD5] $md5 = $null;
68+
try
69+
{
70+
$md5 = [System.Security.Cryptography.MD5]::Create()
71+
$file = [System.IO.File]::OpenRead($filePath)
72+
return [System.BitConverter]::ToString($md5.ComputeHash($file))
73+
}
74+
finally
75+
{
76+
if ($file -ne $null)
77+
{
78+
$file.Dispose()
79+
}
80+
}
81+
}
82+
83+
Write-Host "Preparing to run build script..."
84+
85+
if(!$PSScriptRoot){
86+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
87+
}
88+
1789
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
1890
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
1991
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
2092
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
93+
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
94+
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
2195

22-
# Should we use experimental build of Roslyn?
96+
# Should we use mono?
97+
$UseMono = "";
98+
if($Mono.IsPresent) {
99+
Write-Verbose -Message "Using the Mono based scripting engine."
100+
$UseMono = "-mono"
101+
}
102+
103+
# Should we use the new Roslyn?
23104
$UseExperimental = "";
24-
if($Experimental.IsPresent) {
105+
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
106+
Write-Verbose -Message "Using experimental version of Roslyn."
25107
$UseExperimental = "-experimental"
26108
}
27109

@@ -31,44 +113,77 @@ if($WhatIf.IsPresent) {
31113
$UseDryRun = "-dryrun"
32114
}
33115

34-
# Should we use mono?
35-
$UseMono = "";
36-
if($Mono.IsPresent) {
37-
$UseMono = "-mono"
116+
# Make sure tools folder exists
117+
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
118+
Write-Verbose -Message "Creating tools directory..."
119+
New-Item -Path $TOOLS_DIR -Type directory | out-null
38120
}
39121

40-
# Create tools dir
41-
if (!(Test-Path $TOOLS_DIR)) {
42-
mkdir $TOOLS_DIR
122+
# Make sure that packages.config exist.
123+
if (!(Test-Path $PACKAGES_CONFIG)) {
124+
Write-Verbose -Message "Downloading packages.config..."
125+
try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
126+
Throw "Could not download packages.config."
127+
}
43128
}
44129

45-
# Try download NuGet.exe if do not exist.
130+
# Try find NuGet.exe in path if not exists
46131
if (!(Test-Path $NUGET_EXE)) {
47-
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
132+
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
133+
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
134+
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
135+
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
136+
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
137+
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
138+
}
48139
}
49140

50-
# Make sure NuGet exists where we expect it.
141+
# Try download NuGet.exe if not exists
51142
if (!(Test-Path $NUGET_EXE)) {
52-
Throw "Could not find NuGet.exe"
143+
Write-Verbose -Message "Downloading NuGet.exe..."
144+
try {
145+
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
146+
} catch {
147+
Throw "Could not download NuGet.exe."
148+
}
53149
}
54150

151+
# Save nuget.exe path to environment to be available to child processed
152+
$ENV:NUGET_EXE = $NUGET_EXE
153+
55154
# Restore tools from NuGet?
56-
if(-Not $SkipToolPackageRestore.IsPresent)
57-
{
155+
if(-Not $SkipToolPackageRestore.IsPresent) {
58156
Push-Location
59157
Set-Location $TOOLS_DIR
60-
Invoke-Expression "$NUGET_EXE install -ExcludeVersion"
61-
Pop-Location
158+
159+
# Check for changes in packages.config and remove installed tools if true.
160+
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
161+
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
162+
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
163+
Write-Verbose -Message "Missing or changed package.config hash..."
164+
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
165+
}
166+
167+
Write-Verbose -Message "Restoring tools from NuGet..."
168+
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
169+
62170
if ($LASTEXITCODE -ne 0) {
63-
exit $LASTEXITCODE
171+
Throw "An error occured while restoring NuGet tools."
64172
}
173+
else
174+
{
175+
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
176+
}
177+
Write-Verbose -Message ($NuGetOutput | out-string)
178+
Pop-Location
65179
}
66180

67181
# Make sure that Cake has been installed.
68182
if (!(Test-Path $CAKE_EXE)) {
69-
Throw "Could not find Cake.exe"
183+
Throw "Could not find Cake.exe at $CAKE_EXE"
70184
}
71185

72186
# Start Cake
73-
Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
187+
Write-Host "Running build script..."
188+
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
74189
exit $LASTEXITCODE

build.sh

+34-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
#!/usr/bin/env bash
2-
###############################################################
3-
# This is the Cake bootstrapper script that is responsible for
4-
# downloading Cake and all specified tools from NuGet.
5-
###############################################################
2+
3+
##########################################################################
4+
# This is the Cake bootstrapper script for Linux and OS X.
5+
# This file was downloaded from https://github.com/cake-build/resources
6+
# Feel free to change this file to fit your needs.
7+
##########################################################################
68

79
# Define directories.
810
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
911
TOOLS_DIR=$SCRIPT_DIR/tools
1012
NUGET_EXE=$TOOLS_DIR/nuget.exe
1113
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
14+
PACKAGES_CONFIG=$TOOLS_DIR/packages.config
15+
PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
16+
17+
# Define md5sum or md5 depending on Linux/OSX
18+
MD5_EXE=
19+
if [[ "$(uname -s)" == "Darwin" ]]; then
20+
MD5_EXE="md5 -r"
21+
else
22+
MD5_EXE="md5sum"
23+
fi
1224

1325
# Define default arguments.
1426
SCRIPT="build.cake"
@@ -35,48 +47,55 @@ for i in "$@"; do
3547
done
3648

3749
# Make sure the tools folder exist.
38-
if [ ! -d $TOOLS_DIR ]; then
39-
mkdir $TOOLS_DIR
50+
if [ ! -d "$TOOLS_DIR" ]; then
51+
mkdir "$TOOLS_DIR"
4052
fi
4153

4254
# Make sure that packages.config exist.
43-
if [ ! -f $TOOLS_DIR/packages.config ]; then
55+
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
4456
echo "Downloading packages.config..."
45-
curl -Lsfo $TOOLS_DIR/packages.config http://cakebuild.net/bootstrapper/packages
57+
curl -Lsfo "$TOOLS_DIR/packages.config" http://cakebuild.net/download/bootstrapper/packages
4658
if [ $? -ne 0 ]; then
4759
echo "An error occured while downloading packages.config."
4860
exit 1
4961
fi
5062
fi
5163

5264
# Download NuGet if it does not exist.
53-
if [ ! -f $NUGET_EXE ]; then
65+
if [ ! -f "$NUGET_EXE" ]; then
5466
echo "Downloading NuGet..."
55-
curl -Lsfo $NUGET_EXE https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
67+
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
5668
if [ $? -ne 0 ]; then
5769
echo "An error occured while downloading nuget.exe."
5870
exit 1
5971
fi
6072
fi
6173

6274
# Restore tools from NuGet.
63-
pushd $TOOLS_DIR >/dev/null
64-
mono $NUGET_EXE install -ExcludeVersion
75+
pushd "$TOOLS_DIR" >/dev/null
76+
if [ ! -f $PACKAGES_CONFIG_MD5 ] || [ "$( cat $PACKAGES_CONFIG_MD5 | sed 's/\r$//' )" != "$( $MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' )" ]; then
77+
find . -type d ! -name . | xargs rm -rf
78+
fi
79+
80+
mono "$NUGET_EXE" install -ExcludeVersion
6581
if [ $? -ne 0 ]; then
6682
echo "Could not restore NuGet packages."
6783
exit 1
6884
fi
85+
86+
$MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' >| $PACKAGES_CONFIG_MD5
87+
6988
popd >/dev/null
7089

7190
# Make sure that Cake has been installed.
72-
if [ ! -f $CAKE_EXE ]; then
91+
if [ ! -f "$CAKE_EXE" ]; then
7392
echo "Could not find Cake.exe at '$CAKE_EXE'."
7493
exit 1
7594
fi
7695

7796
# Start Cake
7897
if $SHOW_VERSION; then
79-
exec mono $CAKE_EXE -version
98+
exec mono "$CAKE_EXE" -version
8099
else
81-
exec mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
100+
exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
82101
fi

tools/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Cake" version="0.11.0" />
3+
<package id="Cake" version="0.16.1" />
44
</packages>

0 commit comments

Comments
 (0)