Compile packages for selected targets

This commit is contained in:
2026-10-07 22:27:31 +00:00
parent 1c41f7a0d1
commit cabc56b134
20 changed files with 406 additions and 40 deletions

View File

@@ -3,15 +3,25 @@ package validation
import (
"context"
"fmt"
"io"
"os"
"strings"
"gitea.maximumdirect.net/eric/ReleaseKit/internal/gotool"
)
// Settings selects shared validation behavior.
type Settings struct {
Race bool
FullVet bool
Race bool
FullVet bool
CompileTargets []Target
}
// Target selects one package-compilation target.
type Target struct {
OS string
Arch string
}
// Request identifies the captured source and output used by shared validation.
@@ -30,6 +40,17 @@ func (request Request) ReadCandidateTree(ctx context.Context) (*CandidateTree, e
// Run executes shared validation for the captured candidate.
func Run(ctx context.Context, request Request) error {
for _, target := range request.Settings.CompileTargets {
if strings.TrimSpace(target.OS) == "" || strings.TrimSpace(target.Arch) == "" || strings.Contains(target.OS, "/") || strings.Contains(target.Arch, "/") {
return &Failure{
Check: PackageCompile,
Findings: []Finding{{
Target: target.OS + "/" + target.Arch,
Message: "target must be one complete GOOS/GOARCH pair",
}},
}
}
}
tool, err := gotool.New(ctx, request.RepositoryDir)
if err != nil {
return &Failure{Check: GoTest, Cause: err}
@@ -52,5 +73,20 @@ func Run(ctx context.Context, request Request) error {
return &Failure{Check: GoVet, Cause: err}
}
}
for _, target := range request.Settings.CompileTargets {
selected := gotool.Target{OS: target.OS, Arch: target.Arch}
_, err = tool.Run(ctx, request.RepositoryDir, gotool.Static, selected, request.Output,
"build", "-mod=readonly", "-o", os.DevNull, "./...")
if err != nil {
return &Failure{
Check: PackageCompile,
Findings: []Finding{{
Target: fmt.Sprintf("%s/%s", target.OS, target.Arch),
Message: "package compilation failed",
}},
Cause: err,
}
}
}
return nil
}