Skip to content

Commit 95ac217

Browse files
authored
Rebuild crank from source (#6648)
1 parent b0fd545 commit 95ac217

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

tools/Crank/setup-crank-agent.ps1

+60-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
[CmdletBinding()]
44
param (
55
[bool]$InstallDotNet = $true,
6-
[bool]$InstallCrankAgent = $true
6+
[bool]$InstallCrankAgent = $true,
7+
[string]$CrankBranch
78
)
89

910
$ErrorActionPreference = 'Stop'
@@ -24,12 +25,66 @@ function InstallDotNet {
2425
}
2526
}
2627

27-
function InstallCrankAgent {
28+
function New-TemporaryDirectory {
29+
$parent = [System.IO.Path]::GetTempPath()
30+
$name = [System.Guid]::NewGuid()
31+
New-Item -ItemType Directory -Path (Join-Path $parent $name)
32+
}
33+
34+
function BuildCrankAgent {
35+
Write-Verbose "Cloning crank repo..."
36+
git clone https://github.com/dotnet/crank.git > $null
37+
Set-Location crank
38+
39+
$logFileName = 'build.log'
40+
Write-Verbose "Building crank (see $(Join-Path -Path $PWD -ChildPath $logFileName))..."
41+
$buildCommand = $IsWindows ? '.\build.cmd' : './build.sh'
42+
& $buildCommand -configuration Release -pack > $logFileName
43+
44+
Join-Path -Path $PWD -ChildPath "artifacts/packages/Release/Shipping"
45+
}
46+
47+
function GetDotNetToolsLocationArgs {
48+
$IsWindows ? ('--tool-path', 'c:\dotnet-tools') : '-g'
49+
}
50+
51+
function InstallCrankAgentTool($LocalPackageSource) {
52+
Write-Verbose 'Uninstalling crank-agent...'
53+
54+
$uninstallArgs = 'tool', 'uninstall', 'Microsoft.Crank.Agent'
55+
$uninstallArgs += GetDotNetToolsLocationArgs
56+
& dotnet $uninstallArgs
57+
2858
Write-Verbose 'Installing crank-agent...'
29-
if ($IsWindows) {
30-
dotnet tool install --tool-path c:\dotnet-tools Microsoft.Crank.Agent --version "0.1.0-*"
59+
60+
$installArgs =
61+
'tool', 'install', 'Microsoft.Crank.Agent',
62+
'--version', '0.1.0-*'
63+
64+
$installArgs += GetDotNetToolsLocationArgs
65+
66+
if ($LocalPackageSource) {
67+
$installArgs += '--add-source', $LocalPackageSource
68+
}
69+
70+
& dotnet $installArgs
71+
}
72+
73+
function InstallCrankAgent {
74+
if ($CrankBranch) {
75+
$tempDir = New-TemporaryDirectory
76+
Write-Verbose "Creating temporary directory: $($tempDir.FullName)"
77+
Push-Location -Path $tempDir.FullName
78+
try {
79+
$packagesDirectory = BuildCrankAgent
80+
InstallCrankAgentTool -LocalPackageSource $packagesDirectory
81+
} finally {
82+
Pop-Location
83+
Write-Verbose "Removing temporary directory: $($tempDir.FullName)"
84+
Remove-Item $tempDir.FullName -Recurse -Force -ErrorAction Ignore
85+
}
3186
} else {
32-
dotnet tool install -g Microsoft.Crank.Agent --version "0.1.0-*"
87+
InstallCrankAgentTool
3388
}
3489
}
3590

0 commit comments

Comments
 (0)