Skip to content

Commit 0b2774b

Browse files
committed
Switch to new bootstrappers
1 parent b7d6dee commit 0b2774b

4 files changed

Lines changed: 42 additions & 127 deletions

File tree

.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": "2.1.0",
7+
"commands": [
8+
"dotnet-cake"
9+
]
10+
}
11+
}
12+
}

build.config

Lines changed: 0 additions & 3 deletions
This file was deleted.

build.ps1

Lines changed: 22 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
#!/usr/bin/env pwsh
22
$DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1';
33
$DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh'
4-
$DotNetChannel = 'LTS'
54
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
65

7-
[string] $CakeVersion = ''
8-
[string] $DotNetVersion= ''
9-
foreach($line in Get-Content (Join-Path $PSScriptRoot 'build.config'))
10-
{
11-
if ($line -like 'CAKE_VERSION=*') {
12-
$CakeVersion = $line.SubString(13)
13-
}
14-
elseif ($line -like 'DOTNET_VERSION=*') {
15-
$DotNetVersion =$line.SubString(15)
16-
}
17-
}
18-
19-
20-
if ([string]::IsNullOrEmpty($CakeVersion) -or [string]::IsNullOrEmpty($DotNetVersion)) {
21-
'Failed to parse Cake / .NET Core SDK Version'
22-
exit 1
23-
}
24-
256
# Make sure tools folder exists
267
$ToolPath = Join-Path $PSScriptRoot "tools"
278
if (!(Test-Path $ToolPath)) {
@@ -52,7 +33,7 @@ if ($PSVersionTable.PSEdition -ne 'Core') {
5233

5334
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
5435
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
55-
$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=1
36+
$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
5637

5738

5839
Function Remove-PathVariable([string]$VariableToRemove)
@@ -77,78 +58,39 @@ Function Remove-PathVariable([string]$VariableToRemove)
7758
}
7859
}
7960

80-
# Get .NET Core CLI path if installed.
81-
$FoundDotNetCliVersion = $null;
82-
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
83-
$FoundDotNetCliVersion = dotnet --version;
61+
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
62+
$GlobalJsonPath = Join-Path $PSScriptRoot "global.json"
63+
if (!(Test-Path $InstallPath)) {
64+
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null;
8465
}
8566

86-
if($FoundDotNetCliVersion -ne $DotNetVersion) {
87-
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
88-
if (!(Test-Path $InstallPath)) {
89-
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null;
90-
}
67+
if ($IsMacOS -or $IsLinux) {
68+
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
69+
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
70+
& bash $ScriptPath --jsonfile "$GlobalJsonPath" --install-dir "$InstallPath" --no-path
9171

92-
if ($IsMacOS -or $IsLinux) {
93-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
94-
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
95-
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
96-
97-
Remove-PathVariable "$InstallPath"
98-
$env:PATH = "$($InstallPath):$env:PATH"
99-
}
100-
else {
101-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
102-
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
103-
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
72+
Remove-PathVariable "$InstallPath"
73+
$env:PATH = "$($InstallPath):$env:PATH"
74+
}
75+
else {
76+
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
77+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
78+
& $ScriptPath -JSonFile $GlobalJsonPath -InstallDir $InstallPath;
10479

105-
Remove-PathVariable "$InstallPath"
106-
$env:PATH = "$InstallPath;$env:PATH"
107-
}
108-
$env:DOTNET_ROOT=$InstallPath
80+
Remove-PathVariable "$InstallPath"
81+
$env:PATH = "$InstallPath;$env:PATH"
10982
}
83+
$env:DOTNET_ROOT=$InstallPath
11084

11185
###########################################################################
11286
# INSTALL CAKE
11387
###########################################################################
11488

115-
# Make sure Cake has been installed.
116-
[string] $CakeExePath = ''
117-
[string] $CakeInstalledVersion = Get-Command dotnet-cake -ErrorAction SilentlyContinue | % {&$_.Source --version}
118-
119-
if ($CakeInstalledVersion -eq $CakeVersion) {
120-
# Cake found locally
121-
$CakeExePath = (Get-Command dotnet-cake).Source
122-
}
123-
else {
124-
$CakePath = [System.IO.Path]::Combine($ToolPath,'.store', 'cake.tool', $CakeVersion) # Old PowerShell versions Join-Path only supports one child path
125-
126-
$CakeExePath = (Get-ChildItem -Path $ToolPath -Filter "dotnet-cake*" -File| ForEach-Object FullName | Select-Object -First 1)
127-
128-
129-
if ((!(Test-Path -Path $CakePath -PathType Container)) -or (!(Test-Path $CakeExePath -PathType Leaf))) {
130-
131-
if ((![string]::IsNullOrEmpty($CakeExePath)) -and (Test-Path $CakeExePath -PathType Leaf))
132-
{
133-
& dotnet tool uninstall --tool-path $ToolPath Cake.Tool
134-
}
135-
136-
& dotnet tool install --tool-path $ToolPath --version $CakeVersion Cake.Tool
137-
if ($LASTEXITCODE -ne 0)
138-
{
139-
'Failed to install cake'
140-
exit 1
141-
}
142-
$CakeExePath = (Get-ChildItem -Path $ToolPath -Filter "dotnet-cake*" -File| ForEach-Object FullName | Select-Object -First 1)
143-
}
144-
}
89+
& dotnet tool restore
14590

14691
###########################################################################
14792
# RUN BUILD SCRIPT
14893
###########################################################################
149-
& "$CakeExePath" ./build.cake --bootstrap
150-
if ($LASTEXITCODE -eq 0)
151-
{
152-
& "$CakeExePath" ./build.cake $args
153-
}
94+
& dotnet cake ./build.cake $args
95+
15496
exit $LASTEXITCODE

build.sh

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#!/usr/bin/env bash
22
# Define varibles
33
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
4-
source $SCRIPT_DIR/build.config
54
TOOLS_DIR=$SCRIPT_DIR/tools
6-
CAKE_EXE=$TOOLS_DIR/dotnet-cake
7-
CAKE_PATH=$TOOLS_DIR/.store/cake.tool/$CAKE_VERSION
85

9-
if [ "$CAKE_VERSION" = "" ] || [ "$DOTNET_VERSION" = "" ]; then
10-
echo "An error occured while parsing Cake / .NET Core SDK version."
11-
exit 1
12-
fi
136

147
# Make sure the tools folder exist.
158
if [ ! -d "$TOOLS_DIR" ]; then
@@ -25,51 +18,22 @@ export DOTNET_CLI_TELEMETRY_OPTOUT=1
2518
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
2619
export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
2720

28-
DOTNET_INSTALLED_VERSION=$(dotnet --version 2>&1)
29-
30-
if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
31-
echo "Installing .NET CLI..."
32-
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
33-
mkdir "$SCRIPT_DIR/.dotnet"
34-
fi
35-
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh
36-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path
37-
export PATH="$SCRIPT_DIR/.dotnet":$PATH
38-
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
21+
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
22+
mkdir "$SCRIPT_DIR/.dotnet"
3923
fi
24+
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh
25+
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --jsonfile ./global.json --install-dir .dotnet --no-path
26+
export PATH="$SCRIPT_DIR/.dotnet":$PATH
27+
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
4028

4129
###########################################################################
4230
# INSTALL CAKE
4331
###########################################################################
4432

45-
CAKE_INSTALLED_VERSION=$(dotnet-cake --version 2>&1)
46-
47-
if [ "$CAKE_VERSION" != "$CAKE_INSTALLED_VERSION" ]; then
48-
if [ ! -f "$CAKE_EXE" ] || [ ! -d "$CAKE_PATH" ]; then
49-
if [ -f "$CAKE_EXE" ]; then
50-
dotnet tool uninstall --tool-path $TOOLS_DIR Cake.Tool
51-
fi
52-
53-
echo "Installing Cake $CAKE_VERSION..."
54-
dotnet tool install --tool-path $TOOLS_DIR --version $CAKE_VERSION Cake.Tool
55-
if [ $? -ne 0 ]; then
56-
echo "An error occured while installing Cake."
57-
exit 1
58-
fi
59-
fi
60-
61-
# Make sure that Cake has been installed.
62-
if [ ! -f "$CAKE_EXE" ]; then
63-
echo "Could not find Cake.exe at '$CAKE_EXE'."
64-
exit 1
65-
fi
66-
else
67-
CAKE_EXE="dotnet-cake"
68-
fi
33+
dotnet tool restore
6934

7035
###########################################################################
7136
# RUN BUILD SCRIPT
7237
###########################################################################
7338

74-
# Start Cake
75-
(exec "$CAKE_EXE" build.cake --bootstrap) && (exec "$CAKE_EXE" build.cake "$@")
39+
dotnet cake "$@"

0 commit comments

Comments
 (0)