Files
LinkPort/scripts/go-toolchain.ps1
T

27 lines
1.6 KiB
PowerShell

function Get-LinkPortGoExecutable {
param([Parameter(Mandatory = $true)][string]$ProjectRoot)
$ProjectRoot = [IO.Path]::GetFullPath($ProjectRoot)
if (![string]::IsNullOrWhiteSpace($env:LINKPORT_GO)) {
$explicit = [Environment]::ExpandEnvironmentVariables($env:LINKPORT_GO.Trim().Trim('"'))
if (![IO.Path]::IsPathRooted($explicit)) { $explicit = Join-Path $ProjectRoot $explicit }
$explicit = [IO.Path]::GetFullPath($explicit)
if (!(Test-Path -LiteralPath $explicit -PathType Leaf)) {
throw "LINKPORT_GO does not point to a file: $explicit. Use a project-relative go.exe path, or clear it to enable automatic discovery."
}
return $explicit
}
$portable = Join-Path $ProjectRoot 'tools/go/bin/go.exe'
if (Test-Path -LiteralPath $portable -PathType Leaf) { return $portable }
$command = Get-Command go.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if ($command -and (Test-Path -LiteralPath $command.Source -PathType Leaf)) { return $command.Source }
throw (@(
'Go was not found. Running start-dev.cmd from a source checkout requires Go, Node.js and npm.'
'Install Go 1.27.1 on PATH and reopen the terminal, or set LINKPORT_GO to a project-relative go.exe path.'
'A portable Go installation may be placed at tools\go\bin\go.exe relative to the project.'
'To run without development tools, use the prebuilt linkport.exe release instead of start-dev.cmd.'
('Checked tools/go/bin/go.exe under project: ' + $ProjectRoot + ', then go.exe on PATH.')
) -join [Environment]::NewLine)
}