-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CPP] add Conan conan.lock file support
Signed-off-by: Hiroaki KAWAI <[email protected]>
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 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 |
---|---|---|
@@ -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 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 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" | ||
} |