mirror of
https://github.com/anchore/syft.git
synced 2025-11-22 02:43:19 +01:00
* unexport as many types and functions from cataloger packages as possible Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * capture type and signature information in convention test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * check that we return pkg.Cataloger from constructors Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package cpp
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/syft/artifact"
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
|
)
|
|
|
|
var _ generic.Parser = parseConanfile
|
|
|
|
// parseConanfile is a parser function for conanfile.txt contents, returning all packages discovered.
|
|
func parseConanfile(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
|
r := bufio.NewReader(reader)
|
|
inRequirements := false
|
|
var pkgs []pkg.Package
|
|
for {
|
|
line, err := r.ReadString('\n')
|
|
switch {
|
|
case errors.Is(io.EOF, err):
|
|
return pkgs, nil, nil
|
|
case err != nil:
|
|
return nil, nil, fmt.Errorf("failed to parse conanfile.txt file: %w", err)
|
|
}
|
|
|
|
switch {
|
|
case strings.Contains(line, "[requires]"):
|
|
inRequirements = true
|
|
case strings.ContainsAny(line, "[]") || strings.HasPrefix(strings.TrimSpace(line), "#"):
|
|
inRequirements = false
|
|
}
|
|
|
|
m := pkg.ConanfileEntry{
|
|
Ref: strings.Trim(line, "\n"),
|
|
}
|
|
|
|
if !inRequirements {
|
|
continue
|
|
}
|
|
|
|
p := newConanfilePackage(
|
|
m,
|
|
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
|
)
|
|
if p == nil {
|
|
continue
|
|
}
|
|
|
|
pkgs = append(pkgs, *p)
|
|
}
|
|
}
|