classes/insane: create one CachedPath instance in qa_check_staged
PATCH v2 1/3 classes/insane: create one CachedPath instance in qa_check_staged
There's no need to create a new CachedPath instance for every file that we want to scan, just create one at the beginning of the function.
--- meta/classes-global/insane.bbclass | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
meta/classes-global/insane.bbclass +4 -3
@@ -732,6 +732,10 @@ def qa_check_staged(path,d): workdir = os.path.join(tmpdir, "work") recipesysroot = d.getVar("RECIPE_SYSROOT") + # package_qa_check_shebang_size needs the global cpath to be already created + global cpath + cpath = oe.cachedpath.CachedPath() + if bb.data.inherits_class("native", d) or bb.data.inherits_class("cross", d): pkgconfigcheck = workdir else:
@@ -775,10 +779,7 @@ def qa_check_staged(path,d): oe.qa.handle_error("pkgconfig", error_msg, d) if not skip_shebang_size: - global cpath - cpath = oe.cachedpath.CachedPath() package_qa_check_shebang_size(path, "", d, None) - cpath = None # Walk over all files in a directory and call func def package_qa_walk(checkfuncs, package, d):
Signature · 1 line
2.43.0
PATCH v2 2/3 classes/insane: clean up do_qa_sysroot
do_populate_sysroot copies SYSROOT_DIRS into SYSROOT_DESTDIR, so there's no need to loop over SYSROOT_DIRS when checking files: qa_check_staged can just recurse down the entire tree.
--- meta/classes-global/insane.bbclass | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
meta/classes-global/insane.bbclass +1 -3
@@ -1225,9 +1225,7 @@ addtask do_package_qa_setscene python do_qa_sysroot() { bb.note("QA checking do_populate_sysroot") - sysroot_destdir = d.expand('${SYSROOT_DESTDIR}') - for sysroot_dir in d.expand('${SYSROOT_DIRS}').split(): - qa_check_staged(sysroot_destdir + sysroot_dir, d) + qa_check_staged(d.getVar("SYSROOT_DESTDIR"), d) oe.qa.exit_with_message_if_errors("do_populate_sysroot for this recipe installed files with QA issues", d) } do_populate_sysroot[postfuncs] += "do_qa_sysroot"
Signature · 1 line
2.43.0
PATCH v2 3/3 classes/insane: increase shebang size limit
In reply to Ross BurtonSince Linux 5.1 the shebang buffer has been 256 bytes[1], so update the check to match.
Also rewrite the test, create a variable for the magic number (that has the same name as the kernel #define), read double that so we either have a full line, or definitely are over the buffer, don't pointlessly try to decode the bytes as UTF-8, and consolidate the test logic to entirely inside the try block.
Also update the tests: sysroot-shebang-test needs updating to write a longer shebang, and generalise the test case so that the string being searched for isn't so specific.
[1] linux 6eb3c3d0a52dc ("exec: increase BINPRM_BUF_SIZE to 256")
--- .../sysroot-test/sysroot-shebang-test_1.0.bb | 4 ++-- meta/classes-global/insane.bbclass | 23 ++++++++----------- meta/lib/oeqa/selftest/cases/sysroot.py | 3 +-- 3 files changed, 13 insertions(+), 17 deletions(-)
meta-selftest/recipes-test/sysroot-test/sysroot-shebang-test_1.0.bb +2 -2
@@ -1,11 +1,11 @@ -SUMMARY = "Check that shebang does not exceed 128 characters" +SUMMARY = "Check that shebang does not exceed 256 characters" LICENSE = "CLOSED" INHIBIT_DEFAULT_DEPS = "1" EXCLUDE_FROM_WORLD = "1" do_install() { install -d ${D}${bindir} - echo '#!BiM3cnVd1Amtv6PG+FynrQiVMbZnX5ELgF21q3EkuB+44JEGWtq8TvBJ7EGidfVs3eR3wVOUbLnjYDlKUWcm7YC/ute7f+KDHbwxziRUSUBZAUqgjiQdfQ0HnxajI0ozbM863E9JV9k13yZKYfh9/zR77Y6Dl4Dd3zOWS75LSpkAXV' > ${D}${bindir}/max-shebang + echo '#!4Shfcy9Ej8gPKDGNkyhmtxrwPinmpZQ1pCS3snbdqlNx7YfmTpHkeJakCMaDnQXx4c4TmtyJpGBn5F7IO1FShYG9EwtALDOsRKEDOJKRj2L7hW92wZTzlqx4mMqREqNa7Hrwql4DYVv8vmEMhIwvtHO3UaVpgvLY9Y3HhfopUVUMZJi5Xs9KKkRisrM0HBePG67tbeWL9ZstNuPKH1ikyeNB7PprwLrsjZ6EngCrhFTfYzRSuXhdrQQBBsLZBRDsy5QE' > ${D}${bindir}/max-shebang chmod 755 ${D}${bindir}/max-shebang }
meta/classes-global/insane.bbclass +10 -13
@@ -83,25 +83,22 @@ QAPATHTEST[shebang-size] = "package_qa_check_shebang_size" def package_qa_check_shebang_size(path, name, d, elf): global cpath + # From kernel 5.1 onwards (specifically linux 6eb3c3d0a52dc ("exec: increase + # BINPRM_BUF_SIZE to 256")) the shebang buffer was increased from 128 bytes + # to 256 bytes. + BINPRM_BUF_SIZE = 256 + if elf or cpath.islink(path) or not cpath.isfile(path): return try: with open(path, 'rb') as f: - stanza = f.readline(130) + stanza = f.readline(BINPRM_BUF_SIZE * 2) + if stanza.startswith(b'#!') and len(stanza) > BINPRM_BUF_SIZE: + oe.qa.handle_error("shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is %d" % (name, package_qa_clean_path(path, d, name), BINPRM_BUF_SIZE), d) + return except IOError: - return - - if stanza.startswith(b'#!'): - try: - stanza.decode("utf-8") - except UnicodeDecodeError: - #If it is not a text file, it is not a script - return - - if len(stanza) > 129: - oe.qa.handle_error("shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is 128." % (name, package_qa_clean_path(path, d, name)), d) - return + pass QAPATHTEST[libexec] = "package_qa_check_libexec" def package_qa_check_libexec(path,name, d, elf):
meta/lib/oeqa/selftest/cases/sysroot.py +1 -2
@@ -44,9 +44,8 @@ TESTSTRING:pn-sysroot-test-arch2 = "%s" Expected: Fail when a shebang bigger than the max shebang-size is reached. Author: Paulo Neves <[email protected]> """ - expected = "maximum shebang size exceeded, the maximum size is 128. [shebang-size]" res = bitbake("sysroot-shebang-test-native -c populate_sysroot", ignore_status=True) - self.assertTrue(expected in res.output, msg=res.output) + self.assertTrue("[shebang-size]" in res.output, msg=res.output) self.assertTrue(res.status != 0) def test_sysroot_la(self):
Signature · 1 line
2.43.0