Build from the selected module
This commit is contained in:
@@ -13,11 +13,28 @@ type Target struct {
|
||||
Arch string
|
||||
}
|
||||
|
||||
// Settings contains normalized inputs shared by build execution and evidence.
|
||||
type Settings struct {
|
||||
MainPackage string
|
||||
BinaryName string
|
||||
Targets []Target
|
||||
}
|
||||
|
||||
type Declaration struct {
|
||||
Target Target
|
||||
Filename string
|
||||
}
|
||||
|
||||
// NormalizeSettings copies build inputs and removes duplicate targets while
|
||||
// preserving their first occurrence.
|
||||
func NormalizeSettings(mainPackage, binaryName string, targets []Target) Settings {
|
||||
return Settings{
|
||||
MainPackage: mainPackage,
|
||||
BinaryName: binaryName,
|
||||
Targets: NormalizeTargets(targets),
|
||||
}
|
||||
}
|
||||
|
||||
// NormalizeTargets removes duplicate targets while preserving their first
|
||||
// occurrence.
|
||||
func NormalizeTargets(targets []Target) []Target {
|
||||
|
||||
@@ -17,6 +17,22 @@ func TestNormalizeTargetsPreservesOrderAndFirstOccurrence(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSettingsKeepsBuildInputsAndNormalizesTargets(t *testing.T) {
|
||||
settings := NormalizeSettings("./cmd/app", "app", []Target{
|
||||
{OS: "linux", Arch: "amd64"},
|
||||
{OS: "windows", Arch: "arm64"},
|
||||
{OS: "linux", Arch: "amd64"},
|
||||
})
|
||||
want := Settings{
|
||||
MainPackage: "./cmd/app",
|
||||
BinaryName: "app",
|
||||
Targets: []Target{{OS: "linux", Arch: "amd64"}, {OS: "windows", Arch: "arm64"}},
|
||||
}
|
||||
if !reflect.DeepEqual(settings, want) {
|
||||
t.Fatalf("NormalizeSettings() = %#v, want %#v", settings, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpectedBuildUsesSharedNamesInTargetOrder(t *testing.T) {
|
||||
targets := []Target{{OS: "windows", Arch: "arm64"}, {OS: "linux", Arch: "amd64"}}
|
||||
want := []Declaration{
|
||||
|
||||
Reference in New Issue
Block a user