mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
spdx: Update for bitbake changes
Bitbake is dropping the need for fetcher name iteration and multiple revisions per url. Update the code to match (removal of the for loop). (From OE-Core rev: 4859cdf97fd9a260036e148e25f0b78eb393df1e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
@@ -352,34 +352,33 @@ def add_download_packages(d, doc, recipe):
|
|||||||
for download_idx, src_uri in enumerate(d.getVar('SRC_URI').split()):
|
for download_idx, src_uri in enumerate(d.getVar('SRC_URI').split()):
|
||||||
f = bb.fetch2.FetchData(src_uri, d)
|
f = bb.fetch2.FetchData(src_uri, d)
|
||||||
|
|
||||||
for name in f.names:
|
package = oe.spdx.SPDXPackage()
|
||||||
package = oe.spdx.SPDXPackage()
|
package.name = "%s-source-%d" % (d.getVar("PN"), download_idx + 1)
|
||||||
package.name = "%s-source-%d" % (d.getVar("PN"), download_idx + 1)
|
package.SPDXID = oe.sbom.get_download_spdxid(d, download_idx + 1)
|
||||||
package.SPDXID = oe.sbom.get_download_spdxid(d, download_idx + 1)
|
|
||||||
|
|
||||||
if f.type == "file":
|
if f.type == "file":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if f.method.supports_checksum(f):
|
if f.method.supports_checksum(f):
|
||||||
for checksum_id in CHECKSUM_LIST:
|
for checksum_id in CHECKSUM_LIST:
|
||||||
if checksum_id.upper() not in oe.spdx.SPDXPackage.ALLOWED_CHECKSUMS:
|
if checksum_id.upper() not in oe.spdx.SPDXPackage.ALLOWED_CHECKSUMS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
expected_checksum = getattr(f, "%s_expected" % checksum_id)
|
expected_checksum = getattr(f, "%s_expected" % checksum_id)
|
||||||
if expected_checksum is None:
|
if expected_checksum is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
c = oe.spdx.SPDXChecksum()
|
c = oe.spdx.SPDXChecksum()
|
||||||
c.algorithm = checksum_id.upper()
|
c.algorithm = checksum_id.upper()
|
||||||
c.checksumValue = expected_checksum
|
c.checksumValue = expected_checksum
|
||||||
package.checksums.append(c)
|
package.checksums.append(c)
|
||||||
|
|
||||||
package.downloadLocation = oe.spdx_common.fetch_data_to_uri(f, name)
|
package.downloadLocation = oe.spdx_common.fetch_data_to_uri(f, f.name)
|
||||||
doc.packages.append(package)
|
doc.packages.append(package)
|
||||||
doc.add_relationship(doc, "DESCRIBES", package)
|
doc.add_relationship(doc, "DESCRIBES", package)
|
||||||
# In the future, we might be able to do more fancy dependencies,
|
# In the future, we might be able to do more fancy dependencies,
|
||||||
# but this should be sufficient for now
|
# but this should be sufficient for now
|
||||||
doc.add_relationship(package, "BUILD_DEPENDENCY_OF", recipe)
|
doc.add_relationship(package, "BUILD_DEPENDENCY_OF", recipe)
|
||||||
|
|
||||||
def get_license_list_version(license_data, d):
|
def get_license_list_version(license_data, d):
|
||||||
# Newer versions of the SPDX license list are SemVer ("MAJOR.MINOR.MICRO"),
|
# Newer versions of the SPDX license list are SemVer ("MAJOR.MINOR.MICRO"),
|
||||||
|
|||||||
+66
-67
@@ -356,78 +356,77 @@ def add_download_files(d, objset):
|
|||||||
for download_idx, src_uri in enumerate(urls):
|
for download_idx, src_uri in enumerate(urls):
|
||||||
fd = fetch.ud[src_uri]
|
fd = fetch.ud[src_uri]
|
||||||
|
|
||||||
for name in fd.names:
|
file_name = os.path.basename(fetch.localpath(src_uri))
|
||||||
file_name = os.path.basename(fetch.localpath(src_uri))
|
if oe.patch.patch_path(src_uri, fetch, "", expand=False):
|
||||||
if oe.patch.patch_path(src_uri, fetch, "", expand=False):
|
primary_purpose = oe.spdx30.software_SoftwarePurpose.patch
|
||||||
primary_purpose = oe.spdx30.software_SoftwarePurpose.patch
|
else:
|
||||||
else:
|
primary_purpose = oe.spdx30.software_SoftwarePurpose.source
|
||||||
primary_purpose = oe.spdx30.software_SoftwarePurpose.source
|
|
||||||
|
|
||||||
if fd.type == "file":
|
if fd.type == "file":
|
||||||
if os.path.isdir(fd.localpath):
|
if os.path.isdir(fd.localpath):
|
||||||
walk_idx = 1
|
walk_idx = 1
|
||||||
for root, dirs, files in os.walk(fd.localpath, onerror=walk_error):
|
for root, dirs, files in os.walk(fd.localpath, onerror=walk_error):
|
||||||
dirs.sort()
|
dirs.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
for f in files:
|
for f in files:
|
||||||
f_path = os.path.join(root, f)
|
f_path = os.path.join(root, f)
|
||||||
if os.path.islink(f_path):
|
if os.path.islink(f_path):
|
||||||
# TODO: SPDX doesn't support symlinks yet
|
# TODO: SPDX doesn't support symlinks yet
|
||||||
continue
|
|
||||||
|
|
||||||
file = objset.new_file(
|
|
||||||
objset.new_spdxid(
|
|
||||||
"source", str(download_idx + 1), str(walk_idx)
|
|
||||||
),
|
|
||||||
os.path.join(
|
|
||||||
file_name, os.path.relpath(f_path, fd.localpath)
|
|
||||||
),
|
|
||||||
f_path,
|
|
||||||
purposes=[primary_purpose],
|
|
||||||
)
|
|
||||||
|
|
||||||
inputs.add(file)
|
|
||||||
walk_idx += 1
|
|
||||||
|
|
||||||
else:
|
|
||||||
file = objset.new_file(
|
|
||||||
objset.new_spdxid("source", str(download_idx + 1)),
|
|
||||||
file_name,
|
|
||||||
fd.localpath,
|
|
||||||
purposes=[primary_purpose],
|
|
||||||
)
|
|
||||||
inputs.add(file)
|
|
||||||
|
|
||||||
else:
|
|
||||||
dl = objset.add(
|
|
||||||
oe.spdx30.software_Package(
|
|
||||||
_id=objset.new_spdxid("source", str(download_idx + 1)),
|
|
||||||
creationInfo=objset.doc.creationInfo,
|
|
||||||
name=file_name,
|
|
||||||
software_primaryPurpose=primary_purpose,
|
|
||||||
software_downloadLocation=oe.spdx_common.fetch_data_to_uri(
|
|
||||||
fd, name
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if fd.method.supports_checksum(fd):
|
|
||||||
# TODO Need something better than hard coding this
|
|
||||||
for checksum_id in ["sha256", "sha1"]:
|
|
||||||
expected_checksum = getattr(
|
|
||||||
fd, "%s_expected" % checksum_id, None
|
|
||||||
)
|
|
||||||
if expected_checksum is None:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dl.verifiedUsing.append(
|
file = objset.new_file(
|
||||||
oe.spdx30.Hash(
|
objset.new_spdxid(
|
||||||
algorithm=getattr(oe.spdx30.HashAlgorithm, checksum_id),
|
"source", str(download_idx + 1), str(walk_idx)
|
||||||
hashValue=expected_checksum,
|
),
|
||||||
)
|
os.path.join(
|
||||||
|
file_name, os.path.relpath(f_path, fd.localpath)
|
||||||
|
),
|
||||||
|
f_path,
|
||||||
|
purposes=[primary_purpose],
|
||||||
)
|
)
|
||||||
|
|
||||||
inputs.add(dl)
|
inputs.add(file)
|
||||||
|
walk_idx += 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
file = objset.new_file(
|
||||||
|
objset.new_spdxid("source", str(download_idx + 1)),
|
||||||
|
file_name,
|
||||||
|
fd.localpath,
|
||||||
|
purposes=[primary_purpose],
|
||||||
|
)
|
||||||
|
inputs.add(file)
|
||||||
|
|
||||||
|
else:
|
||||||
|
dl = objset.add(
|
||||||
|
oe.spdx30.software_Package(
|
||||||
|
_id=objset.new_spdxid("source", str(download_idx + 1)),
|
||||||
|
creationInfo=objset.doc.creationInfo,
|
||||||
|
name=file_name,
|
||||||
|
software_primaryPurpose=primary_purpose,
|
||||||
|
software_downloadLocation=oe.spdx_common.fetch_data_to_uri(
|
||||||
|
fd, fd.name
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if fd.method.supports_checksum(fd):
|
||||||
|
# TODO Need something better than hard coding this
|
||||||
|
for checksum_id in ["sha256", "sha1"]:
|
||||||
|
expected_checksum = getattr(
|
||||||
|
fd, "%s_expected" % checksum_id, None
|
||||||
|
)
|
||||||
|
if expected_checksum is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
dl.verifiedUsing.append(
|
||||||
|
oe.spdx30.Hash(
|
||||||
|
algorithm=getattr(oe.spdx30.HashAlgorithm, checksum_id),
|
||||||
|
hashValue=expected_checksum,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
inputs.add(dl)
|
||||||
|
|
||||||
return inputs
|
return inputs
|
||||||
|
|
||||||
|
|||||||
@@ -239,6 +239,6 @@ def fetch_data_to_uri(fd, name):
|
|||||||
uri = uri + "://" + fd.host + fd.path
|
uri = uri + "://" + fd.host + fd.path
|
||||||
|
|
||||||
if fd.method.supports_srcrev():
|
if fd.method.supports_srcrev():
|
||||||
uri = uri + "@" + fd.revisions[name]
|
uri = uri + "@" + fd.revision
|
||||||
|
|
||||||
return uri
|
return uri
|
||||||
|
|||||||
Reference in New Issue
Block a user