Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions syft/pkg/cataloger/golang/parse_go_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (

func makeGoMainPackage(mod *debug.BuildInfo, arch string, location source.Location) pkg.Package {
gbs := getBuildSettings(mod.Settings)
main := newGoBinaryPackage(&mod.Main, mod.GoVersion, arch, location, gbs)
main := newGoBinaryPackage(&mod.Main, mod.Main.Path, mod.GoVersion, arch, location, gbs)

if v, ok := gbs["vcs.revision"]; ok {
main.Version = v
Expand All @@ -37,7 +37,7 @@ func makeGoMainPackage(mod *debug.BuildInfo, arch string, location source.Locati
return main
}

func newGoBinaryPackage(dep *debug.Module, goVersion, architecture string, location source.Location, buildSettings map[string]string) pkg.Package {
func newGoBinaryPackage(dep *debug.Module, mainModule, goVersion, architecture string, location source.Location, buildSettings map[string]string) pkg.Package {
if dep.Replace != nil {
dep = dep.Replace
}
Expand All @@ -55,6 +55,7 @@ func newGoBinaryPackage(dep *debug.Module, goVersion, architecture string, locat
H1Digest: dep.Sum,
Architecture: architecture,
BuildSettings: buildSettings,
MainModule: mainModule,
},
}

Expand Down Expand Up @@ -172,7 +173,7 @@ func buildGoPkgInfo(location source.Location, mod *debug.BuildInfo, arch string)
if dep == nil {
continue
}
p := newGoBinaryPackage(dep, mod.GoVersion, arch, location, nil)
p := newGoBinaryPackage(dep, mod.Main.Path, mod.GoVersion, arch, location, nil)
if pkg.IsValid(&p) {
pkgs = append(pkgs, p)
}
Expand Down
11 changes: 9 additions & 2 deletions syft/pkg/cataloger/golang/parse_go_bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func TestBuildGoPkgInfo(t *testing.T) {
GoCompiledVersion: goCompiledVersion,
Architecture: archDetails,
BuildSettings: buildSettings,
MainModule: "github.com/anchore/syft",
},
}

Expand Down Expand Up @@ -298,6 +299,7 @@ func TestBuildGoPkgInfo(t *testing.T) {
GoCompiledVersion: goCompiledVersion,
Architecture: archDetails,
H1Digest: "h1:VSVdnH7cQ7V+B33qSJHTCRlNgra1607Q8PzEmnvb2Ic=",
MainModule: "github.com/anchore/syft",
},
},
{
Expand All @@ -319,6 +321,7 @@ func TestBuildGoPkgInfo(t *testing.T) {
GoCompiledVersion: goCompiledVersion,
Architecture: archDetails,
H1Digest: "h1:DYssiUV1pBmKqzKsm4mqXx8artqC0Q8HgZsVI3lMsAg=",
MainModule: "github.com/anchore/syft",
},
},
expectedMain,
Expand Down Expand Up @@ -372,7 +375,9 @@ func TestBuildGoPkgInfo(t *testing.T) {
Metadata: pkg.GolangBinMetadata{
GoCompiledVersion: goCompiledVersion,
Architecture: archDetails,
H1Digest: "h1:PjhxBct4MZii8FFR8+oeS7QOvxKOTZXgk63EU2XpfJE="}},
H1Digest: "h1:PjhxBct4MZii8FFR8+oeS7QOvxKOTZXgk63EU2XpfJE=",
MainModule: "github.com/anchore/syft",
}},
{
Name: "golang.org/x/term",
FoundBy: catalogerName,
Expand All @@ -391,7 +396,9 @@ func TestBuildGoPkgInfo(t *testing.T) {
Metadata: pkg.GolangBinMetadata{
GoCompiledVersion: goCompiledVersion,
Architecture: archDetails,
H1Digest: "h1:Ihq/mm/suC88gF8WFcVwk+OV6Tq+wyA1O0E5UEvDglI="},
H1Digest: "h1:Ihq/mm/suC88gF8WFcVwk+OV6Tq+wyA1O0E5UEvDglI=",
MainModule: "github.com/anchore/syft",
},
},
expectedMain,
},
Expand Down
1 change: 1 addition & 0 deletions syft/pkg/golang_bin_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type GolangBinMetadata struct {
GoCompiledVersion string `json:"goCompiledVersion" cyclonedx:"goCompiledVersion"`
Architecture string `json:"architecture" cyclonedx:"architecture"`
H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"`
MainModule string `json:"mainModule,omitempty" cyclonedx:"mainModule"`
}