-
Notifications
You must be signed in to change notification settings - Fork 917
Add Conan (C/C++) conan.lock file support #1230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
67d8f25
[CPP] add Conan conan.lock file support
hkwi 96aac3a
update function based on linter error
spiffcs 5ad3b0e
update struct to not be inline based on review
spiffcs e72dbe3
update conanLock with explicit json tags
spiffcs d44c78e
enhance Metadata with lockfile information
spiffcs 010e58f
update ConanMetadata to better represent Ref
spiffcs fea2745
update conanlock to use pkg.ConanMetadata
spiffcs d3ed041
add new ConanLockMetadata
spiffcs c25aa38
generate new schema
spiffcs 6401db3
update with correct metadata inclusion
spiffcs be74c52
remove duplicate type
spiffcs 20560be
add PURL test back for ConanLockMetadata
spiffcs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package cpp | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/anchore/syft/syft/artifact" | ||
| "github.com/anchore/syft/syft/pkg" | ||
| "github.com/anchore/syft/syft/pkg/cataloger/common" | ||
| ) | ||
|
|
||
| // integrity check | ||
| var _ common.ParserFn = parseConanlock | ||
|
|
||
| // parseConanlock is a parser function for conan.lock contents, returning all packages discovered. | ||
| func parseConanlock(_ string, reader io.Reader) ([]*pkg.Package, []artifact.Relationship, error) { | ||
| pkgs := []*pkg.Package{} | ||
| var graphLock struct { | ||
| GraphLock struct { | ||
| Nodes map[string]struct { | ||
| Ref string | ||
| } | ||
| } `json:"graph_lock"` | ||
| } | ||
| if err := json.NewDecoder(reader).Decode(&graphLock); err != nil { | ||
| return nil, nil, err | ||
| } else { | ||
| for _, node := range graphLock.GraphLock.Nodes { | ||
| if len(node.Ref) > 0 { | ||
| // ref: pkga/0.1@user/testing | ||
| splits := strings.Split(strings.Split(node.Ref, "@")[0], "/") | ||
| if len(splits) < 2 { | ||
| continue | ||
| } | ||
| pkgName, pkgVersion := splits[0], splits[1] | ||
| pkgs = append(pkgs, &pkg.Package{ | ||
| Name: pkgName, | ||
| Version: pkgVersion, | ||
| Language: pkg.CPP, | ||
| Type: pkg.ConanPkg, | ||
| MetadataType: pkg.ConanaMetadataType, | ||
| Metadata: pkg.ConanMetadata{ | ||
| Name: pkgName, | ||
| Version: pkgVersion, | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
| return pkgs, nil, nil | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package cpp | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/go-test/deep" | ||
|
|
||
| "github.com/anchore/syft/syft/pkg" | ||
| ) | ||
|
|
||
| func TestParseConanlock(t *testing.T) { | ||
| expected := []*pkg.Package{ | ||
| { | ||
| Name: "zlib", | ||
| Version: "1.2.12", | ||
| Language: pkg.CPP, | ||
| Type: pkg.ConanPkg, | ||
| MetadataType: pkg.ConanaMetadataType, | ||
| Metadata: pkg.ConanMetadata{ | ||
| Name: "zlib", | ||
| Version: "1.2.12", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| fixture, err := os.Open("test-fixtures/conan.lock") | ||
| if err != nil { | ||
| t.Fatalf("failed to open fixture: %+v", err) | ||
| } | ||
|
|
||
| // TODO: no relationships are under test yet | ||
| actual, _, err := parseConanlock(fixture.Name(), fixture) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
|
|
||
| differences := deep.Equal(expected, actual) | ||
| if differences != nil { | ||
| t.Errorf("returned package list differed from expectation: %+v", differences) | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "graph_lock": { | ||
| "nodes": { | ||
| "0": { | ||
| "ref": "zlib/1.2.12", | ||
| "options": "fPIC=True\nshared=False", | ||
| "path": "all/conanfile.py", | ||
| "context": "host" | ||
| } | ||
| }, | ||
| "revisions_enabled": false | ||
| }, | ||
| "version": "0.4", | ||
| "profile_host": "[settings]\narch=x86_64\narch_build=x86_64\nbuild_type=Release\ncompiler=gcc\ncompiler.libcxx=libstdc++\ncompiler.version=9\nos=Linux\nos_build=Linux\n[options]\n[build_requires]\n[env]\n" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.