Skip to content

Commit

Permalink
Do not return a buildinfo if empty
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Sep 5, 2024
1 parent 85cd450 commit 16bd0e0
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/go_inspector/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,30 @@ def collect_go_package(location, **kwargs):
return _collect_go_package_from_data(go_data, location=location)


def get_build_info(go_data):
if not go_data or not "BuildInfo" in go_data:
return

build_info = go_data["BuildInfo"]
if (
not build_info.get("GoVersion")
and not build_info.get("Path")
and not build_info.get("Settings")
):
return
main = build_info.get("Main") or {}
if not main.get("Path") and not main.get("Version") and not main.get("Sum"):
return
return build_info


def _collect_go_package_from_data(go_data, location, **kwargs):
"""
Yield a Go PackageData found in the Go binary file ``go_data`` mapping extracted from
``location`` string. Raise exceptions on errors.
"""
if not go_data:
return

if not (build_info := go_data.get("BuildInfo")):
build_info = get_build_info(go_data)
if not build_info:
return

package_data = get_main_package(build_info=build_info, location=location)
Expand Down Expand Up @@ -172,7 +187,7 @@ def get_main_package(build_info, location):
extra_data=extra_data,
)
purl = PackageURL(type="generic", name=pathloc, qualifiers=dict(path=location))
pkg.set_purl(package_url=purl())
pkg.set_purl(package_url=purl)

elif main_module:
pkg = main_module.as_package_data()
Expand Down

0 comments on commit 16bd0e0

Please sign in to comment.