Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit b79a764

Browse files
authored
Switch build scripts to use dotnet cake (#13691)
* Switch build scripts to use dotnet cake * - pin to version 0.38.5 * - cake version * - dotnet first * quotes * - windows fix * - fix bash to ignore empty parameters * - roll back android * - kudos * - fix * - shift * - empty space
1 parent e5604ee commit b79a764

File tree

8 files changed

+44
-314
lines changed

8 files changed

+44
-314
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"cake.tool": {
6+
"version": "1.0.0",
7+
"commands": [
8+
"dotnet-cake"
9+
]
10+
}
11+
}
12+
}

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ variables:
1616
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
1717
value: true
1818
- name: DOTNET_VERSION
19-
value: 3.1.301
19+
value: 5.0.102
2020

2121
resources:
2222
repositories:

build.cake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
99
Windows CMD:
1010
build.cmd -Target NugetPack
11-
build.cmd -Target NugetPack -ScriptArgs '-packageVersion="9.9.9-custom"','-configuration="Release"'
11+
build.cmd -Target NugetPack -ScriptArgs '--packageVersion="9.9.9-custom"','--configuration="Release"'
1212
1313
PowerShell:
1414
./build.ps1 -Target NugetPack
15-
./build.ps1 -Target NugetPack -ScriptArgs '-packageVersion="9.9.9-custom"'
15+
./build.ps1 -Target NugetPack -ScriptArgs '--packageVersion="9.9.9-custom"'
1616
1717
*/
1818
//////////////////////////////////////////////////////////////////////
@@ -169,6 +169,7 @@ Information ("isCIBuild: {0}", isCIBuild);
169169
Information ("artifactStagingDirectory: {0}", artifactStagingDirectory);
170170
Information("workingDirectory: {0}", workingDirectory);
171171
Information("NUNIT_TEST_WHERE: {0}", NUNIT_TEST_WHERE);
172+
Information("TARGET: {0}", target);
172173

173174
var releaseChannel = ReleaseChannel.Stable;
174175
if(releaseChannelArg == "Preview")

build.ps1

Lines changed: 6 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -1,234 +1,20 @@
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 ShowDescription
25-
Shows description about tasks.
26-
.PARAMETER DryRun
27-
Performs a dry run.
28-
.PARAMETER Experimental
29-
Uses the nightly builds of the Roslyn script engine.
30-
.PARAMETER Mono
31-
Uses the Mono Compiler rather than the Roslyn script engine.
32-
.PARAMETER SkipToolPackageRestore
33-
Skips restoring of packages.
34-
.PARAMETER ScriptArgs
35-
Remaining arguments are added here.
36-
37-
.LINK
38-
https://cakebuild.net
39-
40-
#>
1+
# script inspired by https://andrewlock.net/simplifying-the-cake-global-tool-bootstrapper-scripts-in-netcore3-with-local-tools/
412

423
[CmdletBinding()]
434
Param(
445
[string]$Script = "build.cake",
456
[string]$Target,
46-
[string]$Configuration,
47-
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
48-
[string]$Verbosity,
49-
[switch]$ShowDescription,
50-
[Alias("WhatIf", "Noop")]
51-
[switch]$DryRun,
52-
[switch]$Experimental,
53-
[switch]$Mono,
54-
[switch]$SkipToolPackageRestore,
557
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
568
[string[]]$ScriptArgs
579
)
5810

59-
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
60-
function MD5HashFile([string] $filePath)
61-
{
62-
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
63-
{
64-
return $null
65-
}
66-
67-
[System.IO.Stream] $file = $null;
68-
[System.Security.Cryptography.MD5] $md5 = $null;
69-
try
70-
{
71-
$md5 = [System.Security.Cryptography.MD5]::Create()
72-
$file = [System.IO.File]::OpenRead($filePath)
73-
return [System.BitConverter]::ToString($md5.ComputeHash($file))
74-
}
75-
finally
76-
{
77-
if ($file -ne $null)
78-
{
79-
$file.Dispose()
80-
}
81-
}
82-
}
83-
84-
function GetProxyEnabledWebClient
85-
{
86-
$wc = New-Object System.Net.WebClient
87-
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
88-
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
89-
$wc.Proxy = $proxy
90-
return $wc
91-
}
92-
93-
Write-Host "Preparing to run build script..."
94-
95-
if(!$PSScriptRoot){
96-
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
97-
}
98-
99-
$TOOLS_DIR = Join-Path $PSScriptRoot "caketools"
100-
$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
101-
$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
102-
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
103-
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
104-
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
105-
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
106-
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
107-
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
108-
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
109-
110-
# Make sure tools folder exists
111-
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
112-
Write-Verbose -Message "Creating tools directory..."
113-
New-Item -Path $TOOLS_DIR -Type directory | out-null
114-
}
115-
116-
# Make sure that packages.config exist.
117-
if (!(Test-Path $PACKAGES_CONFIG)) {
118-
Write-Verbose -Message "Downloading packages.config..."
119-
try {
120-
$wc = GetProxyEnabledWebClient
121-
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
122-
Throw "Could not download packages.config."
123-
}
124-
}
125-
126-
# Try find NuGet.exe in path if not exists
127-
if (!(Test-Path $NUGET_EXE)) {
128-
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
129-
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
130-
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
131-
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
132-
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
133-
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
134-
}
135-
}
136-
137-
# Try download NuGet.exe if not exists
138-
if (!(Test-Path $NUGET_EXE)) {
139-
Write-Verbose -Message "Downloading NuGet.exe..."
140-
try {
141-
$wc = GetProxyEnabledWebClient
142-
$wc.DownloadFile($NUGET_URL, $NUGET_EXE)
143-
} catch {
144-
Throw "Could not download NuGet.exe."
145-
}
146-
}
147-
148-
# Save nuget.exe path to environment to be available to child processed
149-
$ENV:NUGET_EXE = $NUGET_EXE
150-
151-
# Restore tools from NuGet?
152-
if(-Not $SkipToolPackageRestore.IsPresent) {
153-
Push-Location
154-
Set-Location $TOOLS_DIR
155-
156-
# Check for changes in packages.config and remove installed tools if true.
157-
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
158-
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
159-
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
160-
Write-Verbose -Message "Missing or changed package.config hash..."
161-
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
162-
}
163-
164-
Write-Verbose -Message "Restoring tools from NuGet..."
165-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
166-
167-
if ($LASTEXITCODE -ne 0) {
168-
Throw "An error occurred while restoring NuGet tools."
169-
}
170-
else
171-
{
172-
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
173-
}
174-
Write-Verbose -Message ($NuGetOutput | out-string)
175-
176-
Pop-Location
177-
}
178-
179-
# Restore addins from NuGet
180-
if (Test-Path $ADDINS_PACKAGES_CONFIG) {
181-
Push-Location
182-
Set-Location $ADDINS_DIR
183-
184-
Write-Verbose -Message "Restoring addins from NuGet..."
185-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
186-
187-
if ($LASTEXITCODE -ne 0) {
188-
Throw "An error occurred while restoring NuGet addins."
189-
}
190-
191-
Write-Verbose -Message ($NuGetOutput | out-string)
192-
193-
Pop-Location
194-
}
195-
196-
# Restore modules from NuGet
197-
if (Test-Path $MODULES_PACKAGES_CONFIG) {
198-
Push-Location
199-
Set-Location $MODULES_DIR
200-
201-
Write-Verbose -Message "Restoring modules from NuGet..."
202-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
203-
204-
if ($LASTEXITCODE -ne 0) {
205-
Throw "An error occurred while restoring NuGet modules."
206-
}
207-
208-
Write-Verbose -Message ($NuGetOutput | out-string)
209-
210-
Pop-Location
211-
}
212-
213-
# Make sure that Cake has been installed.
214-
if (!(Test-Path $CAKE_EXE)) {
215-
Throw "Could not find Cake.exe at $CAKE_EXE"
216-
}
217-
218-
11+
# Restore Cake tool
12+
& dotnet tool restore
21913

22014
# Build Cake arguments
22115
$cakeArguments = @("$Script");
222-
if ($Target) { $cakeArguments += "-target=$Target" }
223-
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
224-
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
225-
if ($ShowDescription) { $cakeArguments += "-showdescription" }
226-
if ($DryRun) { $cakeArguments += "-dryrun" }
227-
if ($Experimental) { $cakeArguments += "-experimental" }
228-
if ($Mono) { $cakeArguments += "-mono" }
16+
if ($Target) { $cakeArguments += "--target=$Target" }
22917
$cakeArguments += $ScriptArgs
23018

231-
# Start Cake
232-
Write-Host "Running build script..."
233-
&$CAKE_EXE $cakeArguments
234-
exit $LASTEXITCODE
19+
& dotnet tool run dotnet-cake -- $cakeArguments
20+
exit $LASTEXITCODE

build.sh

Lines changed: 9 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,30 @@
11
#!/usr/bin/env bash
22

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-
##########################################################################
8-
9-
# Define directories.
10-
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
11-
TOOLS_DIR=$SCRIPT_DIR/caketools
12-
NUGET_EXE=$TOOLS_DIR/nuget.exe
13-
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
3+
# script inspired by https://andrewlock.net/simplifying-the-cake-global-tool-bootstrapper-scripts-in-netcore3-with-local-tools/
244

255
# Define default arguments.
266
SCRIPT="build.cake"
27-
VERBOSITY="verbose"
28-
DRYRUN=
29-
SHOW_VERSION=false
30-
SCRIPT_ARGUMENTS=()
7+
CAKE_ARGUMENTS=()
318

329
# Parse arguments.
3310
for i in "$@"; do
3411
case $1 in
3512
-s|--script) SCRIPT="$2"; shift ;;
36-
-t|--target) TARGET="$2"; shift ;;
37-
-c|--configuration) CONFIGURATION="$2"; shift ;;
38-
-v|--verbosity) VERBOSITY="$2"; shift ;;
39-
-d|--dryrun) DRYRUN="-dryrun" ;;
40-
--version) SHOW_VERSION=true ;;
41-
--) shift; SCRIPT_ARGUMENTS+=("$@"); break ;;
42-
*) SCRIPT_ARGUMENTS+=("$1") ;;
13+
--) shift; CAKE_ARGUMENTS+=("$@"); break ;;
14+
*) CAKE_ARGUMENTS+=("$1") ;;
4315
esac
4416
shift
4517
done
4618

47-
# Make sure the tools folder exist.
48-
if [ ! -d "$TOOLS_DIR" ]; then
49-
mkdir "$TOOLS_DIR"
50-
fi
51-
52-
# Make sure that packages.config exist.
53-
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
54-
echo "Downloading packages.config..."
55-
curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
56-
if [ $? -ne 0 ]; then
57-
echo "An error occurred while downloading packages.config."
58-
exit 1
59-
fi
60-
fi
61-
62-
# Download NuGet if it does not exist.
63-
if [ ! -f "$NUGET_EXE" ]; then
64-
echo "Downloading NuGet..."
65-
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
66-
if [ $? -ne 0 ]; then
67-
echo "An error occurred while downloading nuget.exe."
68-
exit 1
69-
fi
70-
fi
19+
# Restore Cake tool
20+
dotnet tool restore
7121

72-
# Restore tools from NuGet.
73-
pushd "$TOOLS_DIR" >/dev/null
74-
if [ ! -f $PACKAGES_CONFIG_MD5 ] || [ "$( cat $PACKAGES_CONFIG_MD5 | sed 's/\r$//' )" != "$( $MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' )" ]; then
75-
find . -type d ! -name . | xargs rm -rf
76-
fi
77-
78-
mono "$NUGET_EXE" install -ExcludeVersion
7922
if [ $? -ne 0 ]; then
80-
echo "Could not restore NuGet packages."
23+
echo "An error occured while installing Cake."
8124
exit 1
8225
fi
8326

84-
$MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' >| $PACKAGES_CONFIG_MD5
85-
86-
popd >/dev/null
87-
88-
# Make sure that Cake has been installed.
89-
if [ ! -f "$CAKE_EXE" ]; then
90-
echo "Could not find Cake.exe at '$CAKE_EXE'."
91-
exit 1
92-
fi
27+
echo "${CAKE_ARGUMENTS[@]}"
9328

9429
# Start Cake
95-
if $SHOW_VERSION; then
96-
exec mono "$CAKE_EXE" -version
97-
else
98-
exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
99-
fi
30+
dotnet tool run dotnet-cake "$SCRIPT" "${CAKE_ARGUMENTS[@]}"

0 commit comments

Comments
 (0)