-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
accept main.version ldflags even without vcs (#1855)
Signed-off-by: Avi Deitcher <[email protected]>
- Loading branch information
Showing
2 changed files
with
154 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,7 +347,7 @@ func TestBuildGoPkgInfo(t *testing.T) { | |
}, | ||
}, | ||
{ | ||
name: "parse main mod and replace devel version with one from ldflags", | ||
name: "parse main mod and replace devel version with one from ldflags with vcs. build settings", | ||
arch: archDetails, | ||
mod: &debug.BuildInfo{ | ||
GoVersion: goCompiledVersion, | ||
|
@@ -393,6 +393,135 @@ func TestBuildGoPkgInfo(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
name: "parse main mod and replace devel version with one from ldflags without any vcs. build settings", | ||
arch: archDetails, | ||
mod: &debug.BuildInfo{ | ||
GoVersion: goCompiledVersion, | ||
Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"}, | ||
Settings: []debug.BuildSetting{ | ||
{Key: "GOARCH", Value: archDetails}, | ||
{Key: "GOOS", Value: "darwin"}, | ||
{Key: "GOAMD64", Value: "v1"}, | ||
{Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`}, | ||
}, | ||
}, | ||
expected: []pkg.Package{ | ||
{ | ||
Name: "github.com/anchore/syft", | ||
Language: pkg.Go, | ||
Type: pkg.GoModulePkg, | ||
Version: "v0.79.0", | ||
PURL: "pkg:golang/github.com/anchore/[email protected]", | ||
Locations: file.NewLocationSet( | ||
file.NewLocationFromCoordinates( | ||
file.Coordinates{ | ||
RealPath: "/a-path", | ||
FileSystemID: "layer-id", | ||
}, | ||
).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), | ||
), | ||
MetadataType: pkg.GolangBinMetadataType, | ||
Metadata: pkg.GolangBinMetadata{ | ||
GoCompiledVersion: goCompiledVersion, | ||
Architecture: archDetails, | ||
BuildSettings: map[string]string{ | ||
"GOARCH": archDetails, | ||
"GOOS": "darwin", | ||
"GOAMD64": "v1", | ||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`, | ||
}, | ||
MainModule: "github.com/anchore/syft", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "parse main mod and replace devel version with one from ldflags main.version without any vcs. build settings", | ||
arch: archDetails, | ||
mod: &debug.BuildInfo{ | ||
GoVersion: goCompiledVersion, | ||
Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"}, | ||
Settings: []debug.BuildSetting{ | ||
{Key: "GOARCH", Value: archDetails}, | ||
{Key: "GOOS", Value: "darwin"}, | ||
{Key: "GOAMD64", Value: "v1"}, | ||
{Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X main.version=0.79.0`}, | ||
}, | ||
}, | ||
expected: []pkg.Package{ | ||
{ | ||
Name: "github.com/anchore/syft", | ||
Language: pkg.Go, | ||
Type: pkg.GoModulePkg, | ||
Version: "v0.79.0", | ||
PURL: "pkg:golang/github.com/anchore/[email protected]", | ||
Locations: file.NewLocationSet( | ||
file.NewLocationFromCoordinates( | ||
file.Coordinates{ | ||
RealPath: "/a-path", | ||
FileSystemID: "layer-id", | ||
}, | ||
).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), | ||
), | ||
MetadataType: pkg.GolangBinMetadataType, | ||
Metadata: pkg.GolangBinMetadata{ | ||
GoCompiledVersion: goCompiledVersion, | ||
Architecture: archDetails, | ||
BuildSettings: map[string]string{ | ||
"GOARCH": archDetails, | ||
"GOOS": "darwin", | ||
"GOAMD64": "v1", | ||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X main.version=0.79.0`, | ||
}, | ||
MainModule: "github.com/anchore/syft", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "parse main mod and replace devel version with one from ldflags main.Version without any vcs. build settings", | ||
arch: archDetails, | ||
mod: &debug.BuildInfo{ | ||
GoVersion: goCompiledVersion, | ||
Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"}, | ||
Settings: []debug.BuildSetting{ | ||
{Key: "GOARCH", Value: archDetails}, | ||
{Key: "GOOS", Value: "darwin"}, | ||
{Key: "GOAMD64", Value: "v1"}, | ||
{Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X main.Version=0.79.0`}, | ||
}, | ||
}, | ||
expected: []pkg.Package{ | ||
{ | ||
Name: "github.com/anchore/syft", | ||
Language: pkg.Go, | ||
Type: pkg.GoModulePkg, | ||
Version: "v0.79.0", | ||
PURL: "pkg:golang/github.com/anchore/[email protected]", | ||
Locations: file.NewLocationSet( | ||
file.NewLocationFromCoordinates( | ||
file.Coordinates{ | ||
RealPath: "/a-path", | ||
FileSystemID: "layer-id", | ||
}, | ||
).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), | ||
), | ||
MetadataType: pkg.GolangBinMetadataType, | ||
Metadata: pkg.GolangBinMetadata{ | ||
GoCompiledVersion: goCompiledVersion, | ||
Architecture: archDetails, | ||
BuildSettings: map[string]string{ | ||
"GOARCH": archDetails, | ||
"GOOS": "darwin", | ||
"GOAMD64": "v1", | ||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X main.Version=0.79.0`, | ||
}, | ||
MainModule: "github.com/anchore/syft", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "parse main mod and replace devel version with a pseudo version", | ||
arch: archDetails, | ||
|