添加和完善编译脚本
This commit is contained in:
@@ -5,6 +5,8 @@ param(
|
|||||||
|
|
||||||
[string]$GoBin = "",
|
[string]$GoBin = "",
|
||||||
[string]$DistDir = "",
|
[string]$DistDir = "",
|
||||||
|
[string]$GoCacheDir = "",
|
||||||
|
[string]$GoModCacheDir = "",
|
||||||
[string]$CgoEnabledValue = "0",
|
[string]$CgoEnabledValue = "0",
|
||||||
[string]$BuildJobs = "",
|
[string]$BuildJobs = "",
|
||||||
[string]$Version = "",
|
[string]$Version = "",
|
||||||
@@ -40,6 +42,8 @@ Usage:
|
|||||||
Optional parameters:
|
Optional parameters:
|
||||||
-GoBin <path> Go binary path
|
-GoBin <path> Go binary path
|
||||||
-DistDir <path> Output directory, default: .\dist
|
-DistDir <path> Output directory, default: .\dist
|
||||||
|
-GoCacheDir <path> Go build cache directory, default: .\.cache\go-build
|
||||||
|
-GoModCacheDir <path> Go module cache directory, default: .\.cache\gomod
|
||||||
-CgoEnabledValue <0|1> CGO_ENABLED value, default: 0
|
-CgoEnabledValue <0|1> CGO_ENABLED value, default: 0
|
||||||
-BuildJobs <int> Go build parallel jobs, default: GO_BUILD_JOBS or CPU core count
|
-BuildJobs <int> Go build parallel jobs, default: GO_BUILD_JOBS or CPU core count
|
||||||
-Version <string> Embedded version, default: git describe --tags --always
|
-Version <string> Embedded version, default: git describe --tags --always
|
||||||
@@ -130,6 +134,19 @@ function Resolve-BuildJobs {
|
|||||||
return [string][Environment]::ProcessorCount
|
return [string][Environment]::ProcessorCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Resolve-CachePath {
|
||||||
|
param(
|
||||||
|
[string]$RequestedPath,
|
||||||
|
[string]$DefaultRelativePath
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($RequestedPath) {
|
||||||
|
return [System.IO.Path]::GetFullPath($RequestedPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return [System.IO.Path]::GetFullPath((Join-Path $RootDir $DefaultRelativePath))
|
||||||
|
}
|
||||||
|
|
||||||
function Get-TargetConfig {
|
function Get-TargetConfig {
|
||||||
param([string]$Target)
|
param([string]$Target)
|
||||||
|
|
||||||
@@ -226,6 +243,8 @@ function Invoke-BuildTarget {
|
|||||||
$env:CGO_ENABLED = $CgoEnabledValue
|
$env:CGO_ENABLED = $CgoEnabledValue
|
||||||
$env:GOOS = $config.GOOS
|
$env:GOOS = $config.GOOS
|
||||||
$env:GOARCH = $config.GOARCH
|
$env:GOARCH = $config.GOARCH
|
||||||
|
$env:GOCACHE = $script:ResolvedGoCacheDir
|
||||||
|
$env:GOMODCACHE = $script:ResolvedGoModCacheDir
|
||||||
|
|
||||||
if ($config.ContainsKey("GOARM")) {
|
if ($config.ContainsKey("GOARM")) {
|
||||||
$env:GOARM = $config.GOARM
|
$env:GOARM = $config.GOARM
|
||||||
@@ -240,7 +259,27 @@ function Invoke-BuildTarget {
|
|||||||
$MainPkg
|
$MainPkg
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
throw "Build failed: $Target"
|
return [pscustomobject]@{
|
||||||
|
Target = $Target
|
||||||
|
Success = $false
|
||||||
|
OutputPath = $outputPath
|
||||||
|
Error = "go build exited with code $LASTEXITCODE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Target = $Target
|
||||||
|
Success = $true
|
||||||
|
OutputPath = $outputPath
|
||||||
|
Error = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return [pscustomobject]@{
|
||||||
|
Target = $Target
|
||||||
|
Success = $false
|
||||||
|
OutputPath = $outputPath
|
||||||
|
Error = $_.Exception.Message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -269,6 +308,8 @@ Require-File -Path $releaseLdflagsPath
|
|||||||
$script:ResolvedGoBin = Resolve-GoBinary -RequestedGoBin $GoBin
|
$script:ResolvedGoBin = Resolve-GoBinary -RequestedGoBin $GoBin
|
||||||
$script:ResolvedDistDir = if ($DistDir) { $DistDir } else { Join-Path $RootDir "dist" }
|
$script:ResolvedDistDir = if ($DistDir) { $DistDir } else { Join-Path $RootDir "dist" }
|
||||||
$script:ResolvedDistDir = [System.IO.Path]::GetFullPath($script:ResolvedDistDir)
|
$script:ResolvedDistDir = [System.IO.Path]::GetFullPath($script:ResolvedDistDir)
|
||||||
|
$script:ResolvedGoCacheDir = Resolve-CachePath -RequestedPath $GoCacheDir -DefaultRelativePath ".cache\go-build"
|
||||||
|
$script:ResolvedGoModCacheDir = Resolve-CachePath -RequestedPath $GoModCacheDir -DefaultRelativePath ".cache\gomod"
|
||||||
$script:ResolvedBuildJobs = Resolve-BuildJobs -RequestedBuildJobs $BuildJobs
|
$script:ResolvedBuildJobs = Resolve-BuildJobs -RequestedBuildJobs $BuildJobs
|
||||||
$script:ResolvedVersion = Resolve-Version -RequestedVersion $Version -RepoRoot $RootDir
|
$script:ResolvedVersion = Resolve-Version -RequestedVersion $Version -RepoRoot $RootDir
|
||||||
$script:ResolvedBuildTagsOthers = if ($BuildTagsOthers) { $BuildTagsOthers } else { Read-TrimmedFile -Path $releaseTagsOthersPath }
|
$script:ResolvedBuildTagsOthers = if ($BuildTagsOthers) { $BuildTagsOthers } else { Read-TrimmedFile -Path $releaseTagsOthersPath }
|
||||||
@@ -276,6 +317,8 @@ $script:ResolvedBuildTagsWindows = if ($BuildTagsWindows) { $BuildTagsWindows }
|
|||||||
$script:ResolvedLdflagsShared = Read-TrimmedFile -Path $releaseLdflagsPath
|
$script:ResolvedLdflagsShared = Read-TrimmedFile -Path $releaseLdflagsPath
|
||||||
|
|
||||||
New-Item -ItemType Directory -Force -Path $script:ResolvedDistDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $script:ResolvedDistDir | Out-Null
|
||||||
|
New-Item -ItemType Directory -Force -Path $script:ResolvedGoCacheDir | Out-Null
|
||||||
|
New-Item -ItemType Directory -Force -Path $script:ResolvedGoModCacheDir | Out-Null
|
||||||
|
|
||||||
$resolvedTargets = @()
|
$resolvedTargets = @()
|
||||||
if ($Targets.Count -eq 0 -or ($Targets.Count -eq 1 -and $Targets[0] -eq "all")) {
|
if ($Targets.Count -eq 0 -or ($Targets.Count -eq 1 -and $Targets[0] -eq "all")) {
|
||||||
@@ -284,10 +327,37 @@ if ($Targets.Count -eq 0 -or ($Targets.Count -eq 1 -and $Targets[0] -eq "all"))
|
|||||||
$resolvedTargets = $Targets
|
$resolvedTargets = $Targets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$results = @()
|
||||||
foreach ($target in $resolvedTargets) {
|
foreach ($target in $resolvedTargets) {
|
||||||
Invoke-BuildTarget -Target $target
|
$results += Invoke-BuildTarget -Target $target
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "Build completed." -ForegroundColor Green
|
Write-Host "Build completed." -ForegroundColor Green
|
||||||
Write-Host "Output directory: $script:ResolvedDistDir"
|
Write-Host "Output directory: $script:ResolvedDistDir"
|
||||||
|
Write-Host "Go build cache: $script:ResolvedGoCacheDir"
|
||||||
|
Write-Host "Go module cache: $script:ResolvedGoModCacheDir"
|
||||||
|
|
||||||
|
$successfulResults = @($results | Where-Object { $_.Success })
|
||||||
|
$failedResults = @($results | Where-Object { -not $_.Success })
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Succeeded targets:" -ForegroundColor Green
|
||||||
|
if ($successfulResults.Count -eq 0) {
|
||||||
|
Write-Host " (none)"
|
||||||
|
} else {
|
||||||
|
foreach ($result in $successfulResults) {
|
||||||
|
Write-Host " $($result.Target) -> $($result.OutputPath)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Failed targets:" -ForegroundColor Yellow
|
||||||
|
if ($failedResults.Count -eq 0) {
|
||||||
|
Write-Host " (none)"
|
||||||
|
} else {
|
||||||
|
foreach ($result in $failedResults) {
|
||||||
|
Write-Host " $($result.Target) -> $($result.Error)"
|
||||||
|
}
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|||||||
@@ -90,3 +90,20 @@ func (t *Transport) Reset() {
|
|||||||
t.dhcpTransport.Reset()
|
t.dhcpTransport.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Transport) Exchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg, error) {
|
||||||
|
question := message.Question[0]
|
||||||
|
if question.Qtype == mDNS.TypeA || question.Qtype == mDNS.TypeAAAA {
|
||||||
|
addresses := t.hosts.Lookup(dns.FqdnToDomain(question.Name))
|
||||||
|
if len(addresses) > 0 {
|
||||||
|
return dns.FixedResponse(message.Id, question, addresses, C.DefaultDNSTTL), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if t.fallback && t.dhcpTransport != nil {
|
||||||
|
dhcpServers := t.dhcpTransport.Fetch()
|
||||||
|
if len(dhcpServers) > 0 {
|
||||||
|
return t.dhcpTransport.Exchange0(ctx, message, dhcpServers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t.exchange(ctx, message, question.Name)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build !darwin
|
//go:build !windows
|
||||||
|
|
||||||
package local
|
package local
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user