Skip to content

Commit

Permalink
Remove the dependencies to baked in files
Browse files Browse the repository at this point in the history
Remove the deps of LICENSE_CREATE_PACKAGE
or COPY_LIC_MANIFEST when looking up
licenses in an image recipe. Replaced it by
internal methods

Closes #56
  • Loading branch information
priv-kweihmann committed Mar 5, 2019
1 parent b9c4787 commit 8acd368
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
15 changes: 2 additions & 13 deletions classes/sca-image-summary.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ inherit sca-helper
inherit sca-conv-checkstyle-helper
inherit sca-global

ROOTFS_POSTPROCESS_COMMAND =+ " do_sca_image_pkg_list; "

SCA_IMAGE_SUMMARY_PKG_LIST = "${T}/pkgs.json"

python do_sca_image_pkg_list() {
import json
from oe.rootfs import image_list_installed_packages
with open(d.getVar("SCA_IMAGE_SUMMARY_PKG_LIST"), "w") as o:
json.dump(image_list_installed_packages(d), o)
}

python sca_image_summary_init() {
for item in d.getVar("SCA_ENABLED_MODULES").split(" "):
for taskstr in ["do_sca_deploy_{}".format(item), "do_sca_deploy_{}_image".format(item)]:
Expand All @@ -29,7 +18,7 @@ python do_sca_image_summary() {

xml_output = ""
_json = {}
with open(d.getVar("SCA_IMAGE_SUMMARY_PKG_LIST")) as i:
with open(d.getVar("SCA_IMAGE_PKG_LIST")) as i:
_json = json.load(i)

for rpm, v in _json.items():
Expand Down Expand Up @@ -70,4 +59,4 @@ python do_sca_image_summary() {
bb.warn("Image contains {}".format(",".join(warn_log)))
}

addtask do_sca_image_summary after do_rootfs before do_image_complete
addtask do_sca_image_summary after do_rootfs before do_image_complete
18 changes: 5 additions & 13 deletions classes/sca-license-filter.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,16 @@ def sca_filter_by_license_image(d):
import oe.packagedata
import bb
import os
import json

if not sca_is_wildcard_lic(d) and (d.getVar("LICENSE_CREATE_PACKAGE") != "1" or \
d.getVar("COPY_LIC_MANIFEST") != 1):
bb.warn("License-Filter can only be used with LICENSE_CREATE_PACKAGE and COPY_LIC_MANIFEST set to '1'")
return []

if not d.getVar("IMAGE_ROOTFS"):
if not d.getVar("IMAGE_ROOTFS") or not os.path.exists(d.getVar("SCA_IMAGE_PKG_LIST")):
bb.warn("License-Filter can only be applied on image-level")
return []

## extract installed package list from rootfs
pack_list = []
if os.path.exists(os.path.join(d.getVar("IMAGE_ROOTFS"), "usr/share/common-licenses/license.manifest")):
with open(os.path.join(d.getVar("IMAGE_ROOTFS"), "usr/share/common-licenses/license.manifest"), "r") as i:
for item in i.readlines():
if not item.startswith("PACKAGE NAME: "):
continue
pack_list.append(item.replace("PACKAGE NAME: ", "").strip())
with open(d.getVar("SCA_IMAGE_PKG_LIST")) as i:
pack_list = json.load(i).keys()

ignores = []
for item in pack_list:
Expand All @@ -57,7 +49,7 @@ def sca_filter_by_license_image(d):
else:
ignores.append(k)
except Exception as e:
bb.warn("{} -> {}".format(item, e))
bb.note("{} -> {} - {}".format(item, e, oe.packagedata.read_subpkgdata_dict(item, d)))

return list(set(ignores))

Expand Down
13 changes: 13 additions & 0 deletions classes/sca-license-image-helper.bbclass
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## This class contains helper methods
## when dealing with licenses and images

ROOTFS_POSTPROCESS_COMMAND =+ " do_sca_image_pkg_list; "

SCA_IMAGE_PKG_LIST = "${T}/pkgs.json"

python do_sca_image_pkg_list() {
import json
from oe.rootfs import image_list_installed_packages
with open(d.getVar("SCA_IMAGE_PKG_LIST"), "w") as o:
json.dump(image_list_installed_packages(d), o)
}
2 changes: 2 additions & 0 deletions classes/sca-on-image.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def sca_on_image_init(d):
enabledModules.append(item)
if any(enabledModules):
bb.note("Using SCA Module(s) {}".format(",".join(sorted(enabledModules))))
## inherit license-helper class
BBHandler.inherit("sca-license-image-helper".format(item), "sca-on-image", 1, d)
if d.getVar("SCA_ENABLE_IMAGE_SUMMARY") == "1":
BBHandler.inherit("sca-{}".format("image-summary"), "sca-on-image", 1, d)
func = "sca-{}-init".format("image-summary").replace("-", "_")
Expand Down

0 comments on commit 8acd368

Please sign in to comment.