Skip to contentSkip to conversation

features_check: Warn if not used

PATCH New Jacob Kroon 1 participant 3 messages Jun 10, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 features_check: Warn if not used

---
 meta/classes/features_check.bbclass | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Changes since v1:
Always warn if unused, regardless of where the class is included/inherited from

meta/classes/features_check.bbclass +15 -0
index 4ba827d4ab..b3c8047861 100644
@@ -16,7 +16,19 @@ python () {
     if d.getVar('PARSE_ALL_RECIPES', False):
         return
 
+    unused = True
+
     for kind in ['DISTRO', 'MACHINE', 'COMBINED']:
+        if d.getVar('ANY_OF_' + kind + '_FEATURES') is None and \
+           d.overridedata.get('ANY_OF_' + kind + '_FEATURES') is None and \
+           d.getVar('REQUIRED_' + kind + '_FEATURES') is None and \
+           d.overridedata.get('REQUIRED_' + kind + '_FEATURES') is None and \
+           d.getVar('CONFLICT_' + kind + '_FEATURES') is None and \
+           d.overridedata.get('CONFLICT_' + kind + '_FEATURES') is None:
+            continue
+
+        unused = False
+
         # Assume at least one var is set.
         features = set((d.getVar(kind + '_FEATURES') or '').split())
 
@@ -39,4 +51,7 @@ python () {
             if conflicts:
                 raise bb.parse.SkipRecipe("conflicting %s feature%s '%s' (in %s_FEATURES)"
                     % (kind.lower(), 's' if len(conflicts) > 1 else '', ' '.join(conflicts), kind))
+
+    if unused:
+        bb.warn("Recipe inherits features_check but doesn't use it")
 }
#1 lore raw

PATCH v2 2/3 meta: Don't inherit 'features_check' in recipes that don't utilize it

---
 meta/recipes-bsp/usbutils/usbutils_012.bb     | 2 +-
 meta/recipes-connectivity/bluez5/bluez5.inc   | 2 +-
 meta/recipes-core/glib-2.0/glib.inc           | 2 +-
 meta/recipes-core/glibc/glibc.inc             | 2 +-
 meta/recipes-core/libxml/libxml2_2.9.10.bb    | 2 +-
 meta/recipes-devtools/mtools/mtools_4.0.24.bb | 2 +-
 meta/recipes-graphics/libva/libva.inc         | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

Changes since v1:
Ignoring where the class is included from uncovered some more places that needed fixing

meta/recipes-bsp/usbutils/usbutils_012.bb +1 -1
index b670fa4ab6..28031e72a7 100644
@@ -15,7 +15,7 @@ SRC_URI = "${KERNELORG_MIRROR}/linux/utils/usb/usbutils/usbutils-${PV}.tar.gz \
 SRC_URI[md5sum] = "7484445cbcf04b3eacac892fe58f8d9f"
 SRC_URI[sha256sum] = "ae2e10aad530d95839b6f4d46cd41715eae6f0f1789310d793e9be21b3e7ae20"
 
-inherit autotools pkgconfig features_check update-alternatives
+inherit autotools pkgconfig update-alternatives
 
 ALTERNATIVE_${PN} = "lsusb"
 ALTERNATIVE_PRIORITY = "100"
meta/recipes-connectivity/bluez5/bluez5.inc +1 -1
index 150d909d73..eee7a53cd6 100644
@@ -57,7 +57,7 @@ S = "${WORKDIR}/bluez-${PV}"
 
 CVE_PRODUCT = "bluez"
 
-inherit autotools pkgconfig systemd update-rc.d features_check ptest gobject-introspection-data
+inherit autotools pkgconfig systemd update-rc.d ptest gobject-introspection-data
 
 EXTRA_OECONF = "\
   --enable-test \
meta/recipes-core/glib-2.0/glib.inc +1 -1
index fb84db83c2..a0055d81b0 100644
@@ -28,7 +28,7 @@ PACKAGES += "${PN}-codegen ${PN}-utils"
 
 LEAD_SONAME = "libglib-2.0.*"
 
-inherit meson gettext gtk-doc pkgconfig ptest-gnome upstream-version-is-even bash-completion gio-module-cache manpages features_check
+inherit meson gettext gtk-doc pkgconfig ptest-gnome upstream-version-is-even bash-completion gio-module-cache manpages
 
 DEPENDS_append_class-target = "${@' gtk-doc' if d.getVar('GTKDOC_ENABLED') == 'True' else ''}"
 
meta/recipes-core/glibc/glibc.inc +1 -1
index 23a6ca99ae..d2f02ad59b 100644
@@ -5,7 +5,7 @@ DEPENDS = "virtual/${TARGET_PREFIX}gcc libgcc-initial linux-libc-headers"
 
 PROVIDES = "virtual/libc"
 PROVIDES += "virtual/libintl virtual/libiconv"
-inherit autotools texinfo features_check systemd
+inherit autotools texinfo systemd
 
 LEAD_SONAME = "libc.so"
 
meta/recipes-core/libxml/libxml2_2.9.10.bb +1 -1
index 097aceb2c0..d11b083e8b 100644
@@ -37,7 +37,7 @@ PACKAGECONFIG ??= "python \
 PACKAGECONFIG[python] = "--with-python=${PYTHON},--without-python,python3"
 PACKAGECONFIG[ipv6] = "--enable-ipv6,--disable-ipv6,"
 
-inherit autotools pkgconfig binconfig-disabled ptest features_check
+inherit autotools pkgconfig binconfig-disabled ptest
 
 inherit ${@bb.utils.contains('PACKAGECONFIG', 'python', 'python3native', '', d)}
 
meta/recipes-devtools/mtools/mtools_4.0.24.bb +1 -1
index d7cc72d172..f11cdad37a 100644
@@ -35,7 +35,7 @@ SRC_URI = "${GNU_MIRROR}/mtools/mtools-${PV}.tar.bz2 \
 
 SRC_URI_append_class-native = " file://disable-hardcoded-configs.patch"
 
-inherit autotools texinfo features_check
+inherit autotools texinfo
 
 EXTRA_OECONF = "--without-x"
 
meta/recipes-graphics/libva/libva.inc +1 -1
index ac39e92de7..e7bec80c14 100644
@@ -24,4 +24,4 @@ UPSTREAM_CHECK_URI = "https://github.com/intel/libva/releases"
 
 DEPENDS = "libdrm"
 
-inherit meson pkgconfig features_check
+inherit meson pkgconfig
#2 lore raw

PATCH v2 3/3 insane: Check for feature check variables not being used

In reply to Jacob Kroon

Add a package QA check for wether any of the variables used by features_check.bbclass is set while not inheriting the class itself.

---
 meta/classes/insane.bbclass | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Changes since v1:
New patch for catching the other case, when feature_check is missing from being inherited

meta/classes/insane.bbclass +11 -1
index b7c613880b..649aea1da1 100644
@@ -26,7 +26,7 @@ WARN_QA ?= " libdir xorg-driver-abi \
             textrel incompatible-license files-invalid \
             infodir build-deps src-uri-bad symlink-to-sysroot multilib \
             invalid-packageconfig host-user-contaminated uppercase-pn patch-fuzz \
-            mime mime-xdg unlisted-pkg-lics \
+            mime mime-xdg unlisted-pkg-lics unhandled-features-check \
             "
 ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \
             perms dep-cmp pkgvarcheck perm-config perm-line perm-link \
@@ -980,6 +980,16 @@ def package_qa_check_src_uri(pn, d, messages):
         if re.search(r"github\.com/.+/.+/archive/.+", url):
             package_qa_handle_error("src-uri-bad", "%s: SRC_URI uses unstable GitHub archives" % pn, d)
 
+QARECIPETEST[unhandled-features-check] = "package_qa_check_unhandled_features_check"
+def package_qa_check_unhandled_features_check(pn, d, messages):
+    if not bb.data.inherits_class('features_check', d):
+        var_set = False
+        for kind in ['DISTRO', 'MACHINE', 'COMBINED']:
+            for var in ['ANY_OF_' + kind + '_FEATURES', 'REQUIRED_' + kind + '_FEATURES', 'CONFLICT_' + kind + '_FEATURES']:
+                if d.getVar(var) is not None or d.overridedata.get(var) is not None:
+                    var_set = True
+        if var_set:
+            package_qa_handle_error("unhandled-features-check", "%s: recipe doesn't inherit features_check" % pn, d)
 
 # The PACKAGE FUNC to scan each package
 python do_package_qa () {