Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # BB Class inspired by ebuild.sh |
| 2 | # |
| 3 | # This class will test files after installation for certain |
| 4 | # security issues and other kind of issues. |
| 5 | # |
| 6 | # Checks we do: |
| 7 | # -Check the ownership and permissions |
| 8 | # -Check the RUNTIME path for the $TMPDIR |
| 9 | # -Check if .la files wrongly point to workdir |
| 10 | # -Check if .pc files wrongly point to workdir |
| 11 | # -Check if packages contains .debug directories or .so files |
| 12 | # where they should be in -dev or -dbg |
| 13 | # -Check if config.log contains traces to broken autoconf tests |
| 14 | # -Check invalid characters (non-utf8) on some package metadata |
| 15 | # -Ensure that binaries in base_[bindir|sbindir|libdir] do not link |
| 16 | # into exec_prefix |
| 17 | # -Check that scripts in base_[bindir|sbindir|libdir] do not reference |
| 18 | # files under exec_prefix |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | # -Check if the package name is upper case |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | QA_SANE = "True" |
| 22 | |
| 23 | # Elect whether a given type of error is a warning or error, they may |
| 24 | # have been set by other files. |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 25 | WARN_QA ?= " libdir xorg-driver-abi \ |
| 26 | textrel incompatible-license files-invalid \ |
| 27 | infodir build-deps src-uri-bad symlink-to-sysroot multilib \ |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 28 | invalid-packageconfig host-user-contaminated uppercase-pn patch-fuzz \ |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 29 | mime mime-xdg unlisted-pkg-lics unhandled-features-check \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 30 | missing-update-alternatives native-last \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | " |
| 32 | ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \ |
| 33 | perms dep-cmp pkgvarcheck perm-config perm-line perm-link \ |
| 34 | split-strip packages-list pkgv-undefined var-undefined \ |
| 35 | version-going-backwards expanded-d invalid-chars \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | license-checksum dev-elf file-rdeps configure-unsafe \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 37 | configure-gettext perllocalpod shebang-size \ |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 38 | already-stripped installed-vs-shipped ldflags compile-host-path \ |
| 39 | install-host-path pn-overrides unknown-configure-option \ |
| 40 | useless-rpaths rpaths staticdev \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | # Add usrmerge QA check based on distro feature |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 43 | ERROR_QA:append = "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', ' usrmerge', '', d)}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | FAKEROOT_QA = "host-user-contaminated" |
| 46 | FAKEROOT_QA[doc] = "QA tests which need to run under fakeroot. If any \ |
| 47 | enabled tests are listed here, the do_package_qa task will run under fakeroot." |
| 48 | |
| 49 | ALL_QA = "${WARN_QA} ${ERROR_QA}" |
| 50 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 51 | UNKNOWN_CONFIGURE_WHITELIST ?= "--enable-nls --disable-nls --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot --disable-static" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | def package_qa_clean_path(path, d, pkg=None): |
| 54 | """ |
| 55 | Remove redundant paths from the path for display. If pkg isn't set then |
| 56 | TMPDIR is stripped, otherwise PKGDEST/pkg is stripped. |
| 57 | """ |
| 58 | if pkg: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 59 | path = path.replace(os.path.join(d.getVar("PKGDEST"), pkg), "/") |
| 60 | return path.replace(d.getVar("TMPDIR"), "/").replace("//", "/") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | |
| 62 | def package_qa_write_error(type, error, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 63 | logfile = d.getVar('QA_LOGFILE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | if logfile: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 65 | p = d.getVar('P') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 66 | with open(logfile, "a+") as f: |
| 67 | f.write("%s: %s [%s]\n" % (p, error, type)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | |
| 69 | def package_qa_handle_error(error_class, error_msg, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | if error_class in (d.getVar("ERROR_QA") or "").split(): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | package_qa_write_error(error_class, error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | bb.error("QA Issue: %s [%s]" % (error_msg, error_class)) |
| 73 | d.setVar("QA_SANE", False) |
| 74 | return False |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 75 | elif error_class in (d.getVar("WARN_QA") or "").split(): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | package_qa_write_error(error_class, error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | bb.warn("QA Issue: %s [%s]" % (error_msg, error_class)) |
| 78 | else: |
| 79 | bb.note("QA Issue: %s [%s]" % (error_msg, error_class)) |
| 80 | return True |
| 81 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | def package_qa_add_message(messages, section, new_msg): |
| 83 | if section not in messages: |
| 84 | messages[section] = new_msg |
| 85 | else: |
| 86 | messages[section] = messages[section] + "\n" + new_msg |
| 87 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 88 | QAPATHTEST[shebang-size] = "package_qa_check_shebang_size" |
| 89 | def package_qa_check_shebang_size(path, name, d, elf, messages): |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 90 | import stat |
| 91 | if os.path.islink(path) or stat.S_ISFIFO(os.stat(path).st_mode) or elf: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 92 | return |
| 93 | |
| 94 | try: |
| 95 | with open(path, 'rb') as f: |
| 96 | stanza = f.readline(130) |
| 97 | except IOError: |
| 98 | return |
| 99 | |
| 100 | if stanza.startswith(b'#!'): |
| 101 | #Shebang not found |
| 102 | try: |
| 103 | stanza = stanza.decode("utf-8") |
| 104 | except UnicodeDecodeError: |
| 105 | #If it is not a text file, it is not a script |
| 106 | return |
| 107 | |
| 108 | if len(stanza) > 129: |
| 109 | package_qa_add_message(messages, "shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is 128." % (name, package_qa_clean_path(path, d))) |
| 110 | return |
| 111 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | QAPATHTEST[libexec] = "package_qa_check_libexec" |
| 113 | def package_qa_check_libexec(path,name, d, elf, messages): |
| 114 | |
| 115 | # Skip the case where the default is explicitly /usr/libexec |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | libexec = d.getVar('libexecdir') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | if libexec == "/usr/libexec": |
| 118 | return True |
| 119 | |
| 120 | if 'libexec' in path.split(os.path.sep): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 121 | package_qa_add_message(messages, "libexec", "%s: %s is using libexec please relocate to %s" % (name, package_qa_clean_path(path, d), libexec)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | return False |
| 123 | |
| 124 | return True |
| 125 | |
| 126 | QAPATHTEST[rpaths] = "package_qa_check_rpath" |
| 127 | def package_qa_check_rpath(file,name, d, elf, messages): |
| 128 | """ |
| 129 | Check for dangerous RPATHs |
| 130 | """ |
| 131 | if not elf: |
| 132 | return |
| 133 | |
| 134 | if os.path.islink(file): |
| 135 | return |
| 136 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | bad_dirs = [d.getVar('BASE_WORKDIR'), d.getVar('STAGING_DIR_TARGET')] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | |
| 139 | phdrs = elf.run_objdump("-p", d) |
| 140 | |
| 141 | import re |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 142 | rpath_re = re.compile(r"\s+RPATH\s+(.*)") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | for line in phdrs.split("\n"): |
| 144 | m = rpath_re.match(line) |
| 145 | if m: |
| 146 | rpath = m.group(1) |
| 147 | for dir in bad_dirs: |
| 148 | if dir in rpath: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 149 | package_qa_add_message(messages, "rpaths", "package %s contains bad RPATH %s in file %s" % (name, rpath, file)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | |
| 151 | QAPATHTEST[useless-rpaths] = "package_qa_check_useless_rpaths" |
| 152 | def package_qa_check_useless_rpaths(file, name, d, elf, messages): |
| 153 | """ |
| 154 | Check for RPATHs that are useless but not dangerous |
| 155 | """ |
| 156 | def rpath_eq(a, b): |
| 157 | return os.path.normpath(a) == os.path.normpath(b) |
| 158 | |
| 159 | if not elf: |
| 160 | return |
| 161 | |
| 162 | if os.path.islink(file): |
| 163 | return |
| 164 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 165 | libdir = d.getVar("libdir") |
| 166 | base_libdir = d.getVar("base_libdir") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 167 | |
| 168 | phdrs = elf.run_objdump("-p", d) |
| 169 | |
| 170 | import re |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 171 | rpath_re = re.compile(r"\s+RPATH\s+(.*)") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | for line in phdrs.split("\n"): |
| 173 | m = rpath_re.match(line) |
| 174 | if m: |
| 175 | rpath = m.group(1) |
| 176 | if rpath_eq(rpath, libdir) or rpath_eq(rpath, base_libdir): |
| 177 | # The dynamic linker searches both these places anyway. There is no point in |
| 178 | # looking there again. |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 179 | package_qa_add_message(messages, "useless-rpaths", "%s: %s contains probably-redundant RPATH %s" % (name, package_qa_clean_path(file, d, name), rpath)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | |
| 181 | QAPATHTEST[dev-so] = "package_qa_check_dev" |
| 182 | def package_qa_check_dev(path, name, d, elf, messages): |
| 183 | """ |
| 184 | Check for ".so" library symlinks in non-dev packages |
| 185 | """ |
| 186 | |
| 187 | if not name.endswith("-dev") and not name.endswith("-dbg") and not name.endswith("-ptest") and not name.startswith("nativesdk-") and path.endswith(".so") and os.path.islink(path): |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 188 | package_qa_add_message(messages, "dev-so", "non -dev/-dbg/nativesdk- package %s contains symlink .so '%s'" % \ |
| 189 | (name, package_qa_clean_path(path, d, name))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 190 | |
| 191 | QAPATHTEST[dev-elf] = "package_qa_check_dev_elf" |
| 192 | def package_qa_check_dev_elf(path, name, d, elf, messages): |
| 193 | """ |
| 194 | Check that -dev doesn't contain real shared libraries. The test has to |
| 195 | check that the file is not a link and is an ELF object as some recipes |
| 196 | install link-time .so files that are linker scripts. |
| 197 | """ |
| 198 | if name.endswith("-dev") and path.endswith(".so") and not os.path.islink(path) and elf: |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 199 | package_qa_add_message(messages, "dev-elf", "-dev package %s contains non-symlink .so '%s'" % \ |
| 200 | (name, package_qa_clean_path(path, d, name))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 201 | |
| 202 | QAPATHTEST[staticdev] = "package_qa_check_staticdev" |
| 203 | def package_qa_check_staticdev(path, name, d, elf, messages): |
| 204 | """ |
| 205 | Check for ".a" library in non-staticdev packages |
| 206 | There are a number of exceptions to this rule, -pic packages can contain |
| 207 | static libraries, the _nonshared.a belong with their -dev packages and |
| 208 | libgcc.a, libgcov.a will be skipped in their packages |
| 209 | """ |
| 210 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 211 | if not name.endswith("-pic") and not name.endswith("-staticdev") and not name.endswith("-ptest") and path.endswith(".a") and not path.endswith("_nonshared.a") and not '/usr/lib/debug-static/' in path and not '/.debug-static/' in path: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 212 | package_qa_add_message(messages, "staticdev", "non -staticdev package contains static .a library: %s path '%s'" % \ |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 213 | (name, package_qa_clean_path(path,d, name))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 215 | QAPATHTEST[mime] = "package_qa_check_mime" |
| 216 | def package_qa_check_mime(path, name, d, elf, messages): |
| 217 | """ |
| 218 | Check if package installs mime types to /usr/share/mime/packages |
| 219 | while no inheriting mime.bbclass |
| 220 | """ |
| 221 | |
| 222 | if d.getVar("datadir") + "/mime/packages" in path and path.endswith('.xml') and not bb.data.inherits_class("mime", d): |
| 223 | package_qa_add_message(messages, "mime", "package contains mime types but does not inherit mime: %s path '%s'" % \ |
| 224 | (name, package_qa_clean_path(path,d))) |
| 225 | |
| 226 | QAPATHTEST[mime-xdg] = "package_qa_check_mime_xdg" |
| 227 | def package_qa_check_mime_xdg(path, name, d, elf, messages): |
| 228 | """ |
| 229 | Check if package installs desktop file containing MimeType and requires |
| 230 | mime-types.bbclass to create /usr/share/applications/mimeinfo.cache |
| 231 | """ |
| 232 | |
| 233 | if d.getVar("datadir") + "/applications" in path and path.endswith('.desktop') and not bb.data.inherits_class("mime-xdg", d): |
| 234 | mime_type_found = False |
| 235 | try: |
| 236 | with open(path, 'r') as f: |
| 237 | for line in f.read().split('\n'): |
| 238 | if 'MimeType' in line: |
| 239 | mime_type_found = True |
| 240 | break; |
| 241 | except: |
| 242 | # At least libreoffice installs symlinks with absolute paths that are dangling here. |
| 243 | # We could implement some magic but for few (one) recipes it is not worth the effort so just warn: |
| 244 | wstr = "%s cannot open %s - is it a symlink with absolute path?\n" % (name, package_qa_clean_path(path,d)) |
| 245 | wstr += "Please check if (linked) file contains key 'MimeType'.\n" |
| 246 | pkgname = name |
| 247 | if name == d.getVar('PN'): |
| 248 | pkgname = '${PN}' |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 249 | wstr += "If yes: add \'inhert mime-xdg\' and \'MIME_XDG_PACKAGES += \"%s\"\' / if no add \'INSANE_SKIP:%s += \"mime-xdg\"\' to recipe." % (pkgname, pkgname) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 250 | package_qa_add_message(messages, "mime-xdg", wstr) |
| 251 | if mime_type_found: |
| 252 | package_qa_add_message(messages, "mime-xdg", "package contains desktop file with key 'MimeType' but does not inhert mime-xdg: %s path '%s'" % \ |
| 253 | (name, package_qa_clean_path(path,d))) |
| 254 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 255 | def package_qa_check_libdir(d): |
| 256 | """ |
| 257 | Check for wrong library installation paths. For instance, catch |
| 258 | recipes installing /lib/bar.so when ${base_libdir}="lib32" or |
| 259 | installing in /usr/lib64 when ${libdir}="/usr/lib" |
| 260 | """ |
| 261 | import re |
| 262 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 263 | pkgdest = d.getVar('PKGDEST') |
| 264 | base_libdir = d.getVar("base_libdir") + os.sep |
| 265 | libdir = d.getVar("libdir") + os.sep |
| 266 | libexecdir = d.getVar("libexecdir") + os.sep |
| 267 | exec_prefix = d.getVar("exec_prefix") + os.sep |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 268 | |
| 269 | messages = [] |
| 270 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 271 | # The re's are purposely fuzzy, as some there are some .so.x.y.z files |
| 272 | # that don't follow the standard naming convention. It checks later |
| 273 | # that they are actual ELF files |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 274 | lib_re = re.compile(r"^/lib.+\.so(\..+)?$") |
| 275 | exec_re = re.compile(r"^%s.*/lib.+\.so(\..+)?$" % exec_prefix) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 276 | |
| 277 | for root, dirs, files in os.walk(pkgdest): |
| 278 | if root == pkgdest: |
| 279 | # Skip subdirectories for any packages with libdir in INSANE_SKIP |
| 280 | skippackages = [] |
| 281 | for package in dirs: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 282 | if 'libdir' in (d.getVar('INSANE_SKIP:' + package) or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | bb.note("Package %s skipping libdir QA test" % (package)) |
| 284 | skippackages.append(package) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 285 | elif d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-file-directory' and package.endswith("-dbg"): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 286 | bb.note("Package %s skipping libdir QA test for PACKAGE_DEBUG_SPLIT_STYLE equals debug-file-directory" % (package)) |
| 287 | skippackages.append(package) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 288 | for package in skippackages: |
| 289 | dirs.remove(package) |
| 290 | for file in files: |
| 291 | full_path = os.path.join(root, file) |
| 292 | rel_path = os.path.relpath(full_path, pkgdest) |
| 293 | if os.sep in rel_path: |
| 294 | package, rel_path = rel_path.split(os.sep, 1) |
| 295 | rel_path = os.sep + rel_path |
| 296 | if lib_re.match(rel_path): |
| 297 | if base_libdir not in rel_path: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 298 | # make sure it's an actual ELF file |
| 299 | elf = oe.qa.ELFFile(full_path) |
| 300 | try: |
| 301 | elf.open() |
| 302 | messages.append("%s: found library in wrong location: %s" % (package, rel_path)) |
| 303 | except (oe.qa.NotELFFileError): |
| 304 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 305 | if exec_re.match(rel_path): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 306 | if libdir not in rel_path and libexecdir not in rel_path: |
| 307 | # make sure it's an actual ELF file |
| 308 | elf = oe.qa.ELFFile(full_path) |
| 309 | try: |
| 310 | elf.open() |
| 311 | messages.append("%s: found library in wrong location: %s" % (package, rel_path)) |
| 312 | except (oe.qa.NotELFFileError): |
| 313 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 314 | |
| 315 | if messages: |
| 316 | package_qa_handle_error("libdir", "\n".join(messages), d) |
| 317 | |
| 318 | QAPATHTEST[debug-files] = "package_qa_check_dbg" |
| 319 | def package_qa_check_dbg(path, name, d, elf, messages): |
| 320 | """ |
| 321 | Check for ".debug" files or directories outside of the dbg package |
| 322 | """ |
| 323 | |
| 324 | if not "-dbg" in name and not "-ptest" in name: |
| 325 | if '.debug' in path.split(os.path.sep): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 326 | package_qa_add_message(messages, "debug-files", "non debug package contains .debug directory: %s path %s" % \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 327 | (name, package_qa_clean_path(path,d))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 328 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 329 | QAPATHTEST[arch] = "package_qa_check_arch" |
| 330 | def package_qa_check_arch(path,name,d, elf, messages): |
| 331 | """ |
| 332 | Check if archs are compatible |
| 333 | """ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 334 | import re, oe.elf |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 335 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | if not elf: |
| 337 | return |
| 338 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 339 | target_os = d.getVar('TARGET_OS') |
| 340 | target_arch = d.getVar('TARGET_ARCH') |
| 341 | provides = d.getVar('PROVIDES') |
| 342 | bpn = d.getVar('BPN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | |
| 344 | if target_arch == "allarch": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 345 | pn = d.getVar('PN') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 346 | package_qa_add_message(messages, "arch", pn + ": Recipe inherits the allarch class, but has packaged architecture-specific binaries") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 347 | return |
| 348 | |
| 349 | # FIXME: Cross package confuse this check, so just skip them |
| 350 | for s in ['cross', 'nativesdk', 'cross-canadian']: |
| 351 | if bb.data.inherits_class(s, d): |
| 352 | return |
| 353 | |
| 354 | # avoid following links to /usr/bin (e.g. on udev builds) |
| 355 | # we will check the files pointed to anyway... |
| 356 | if os.path.islink(path): |
| 357 | return |
| 358 | |
| 359 | #if this will throw an exception, then fix the dict above |
| 360 | (machine, osabi, abiversion, littleendian, bits) \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 361 | = oe.elf.machine_dict(d)[target_os][target_arch] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | |
| 363 | # Check the architecture and endiannes of the binary |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 364 | is_32 = (("virtual/kernel" in provides) or bb.data.inherits_class("module", d)) and \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 365 | (target_os == "linux-gnux32" or target_os == "linux-muslx32" or \ |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 366 | target_os == "linux-gnu_ilp32" or re.match(r'mips64.*32', d.getVar('DEFAULTTUNE'))) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 367 | is_bpf = (oe.qa.elf_machine_to_string(elf.machine()) == "BPF") |
| 368 | if not ((machine == elf.machine()) or is_32 or is_bpf): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 369 | package_qa_add_message(messages, "arch", "Architecture did not match (%s, expected %s) in %s" % \ |
| 370 | (oe.qa.elf_machine_to_string(elf.machine()), oe.qa.elf_machine_to_string(machine), package_qa_clean_path(path, d, name))) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 371 | elif not ((bits == elf.abiSize()) or is_32 or is_bpf): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 372 | package_qa_add_message(messages, "arch", "Bit size did not match (%d, expected %d) in %s" % \ |
| 373 | (elf.abiSize(), bits, package_qa_clean_path(path, d, name))) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 374 | elif not ((littleendian == elf.isLittleEndian()) or is_bpf): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 375 | package_qa_add_message(messages, "arch", "Endiannes did not match (%d, expected %d) in %s" % \ |
| 376 | (elf.isLittleEndian(), littleendian, package_qa_clean_path(path,d, name))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 377 | |
| 378 | QAPATHTEST[desktop] = "package_qa_check_desktop" |
| 379 | def package_qa_check_desktop(path, name, d, elf, messages): |
| 380 | """ |
| 381 | Run all desktop files through desktop-file-validate. |
| 382 | """ |
| 383 | if path.endswith(".desktop"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 384 | desktop_file_validate = os.path.join(d.getVar('STAGING_BINDIR_NATIVE'),'desktop-file-validate') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 385 | output = os.popen("%s %s" % (desktop_file_validate, path)) |
| 386 | # This only produces output on errors |
| 387 | for l in output: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 388 | package_qa_add_message(messages, "desktop", "Desktop file issue: " + l.strip()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 389 | |
| 390 | QAPATHTEST[textrel] = "package_qa_textrel" |
| 391 | def package_qa_textrel(path, name, d, elf, messages): |
| 392 | """ |
| 393 | Check if the binary contains relocations in .text |
| 394 | """ |
| 395 | |
| 396 | if not elf: |
| 397 | return |
| 398 | |
| 399 | if os.path.islink(path): |
| 400 | return |
| 401 | |
| 402 | phdrs = elf.run_objdump("-p", d) |
| 403 | sane = True |
| 404 | |
| 405 | import re |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 406 | textrel_re = re.compile(r"\s+TEXTREL\s+") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 407 | for line in phdrs.split("\n"): |
| 408 | if textrel_re.match(line): |
| 409 | sane = False |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 410 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 411 | |
| 412 | if not sane: |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 413 | path = package_qa_clean_path(path, d, name) |
| 414 | package_qa_add_message(messages, "textrel", "%s: ELF binary %s has relocations in .text" % (name, path)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 415 | |
| 416 | QAPATHTEST[ldflags] = "package_qa_hash_style" |
| 417 | def package_qa_hash_style(path, name, d, elf, messages): |
| 418 | """ |
| 419 | Check if the binary has the right hash style... |
| 420 | """ |
| 421 | |
| 422 | if not elf: |
| 423 | return |
| 424 | |
| 425 | if os.path.islink(path): |
| 426 | return |
| 427 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 428 | gnu_hash = "--hash-style=gnu" in d.getVar('LDFLAGS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 429 | if not gnu_hash: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 430 | gnu_hash = "--hash-style=both" in d.getVar('LDFLAGS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 431 | if not gnu_hash: |
| 432 | return |
| 433 | |
| 434 | sane = False |
| 435 | has_syms = False |
| 436 | |
| 437 | phdrs = elf.run_objdump("-p", d) |
| 438 | |
| 439 | # If this binary has symbols, we expect it to have GNU_HASH too. |
| 440 | for line in phdrs.split("\n"): |
| 441 | if "SYMTAB" in line: |
| 442 | has_syms = True |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 443 | if "GNU_HASH" in line or "DT_MIPS_XHASH" in line: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 444 | sane = True |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 445 | if ("[mips32]" in line or "[mips64]" in line) and d.getVar('TCLIBC') == "musl": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 446 | sane = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 447 | if has_syms and not sane: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 448 | path = package_qa_clean_path(path, d, name) |
| 449 | package_qa_add_message(messages, "ldflags", "File %s in package %s doesn't have GNU_HASH (didn't pass LDFLAGS?)" % (path, name)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 450 | |
| 451 | |
| 452 | QAPATHTEST[buildpaths] = "package_qa_check_buildpaths" |
| 453 | def package_qa_check_buildpaths(path, name, d, elf, messages): |
| 454 | """ |
| 455 | Check for build paths inside target files and error if not found in the whitelist |
| 456 | """ |
| 457 | # Ignore .debug files, not interesting |
| 458 | if path.find(".debug") != -1: |
| 459 | return |
| 460 | |
| 461 | # Ignore symlinks |
| 462 | if os.path.islink(path): |
| 463 | return |
| 464 | |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 465 | tmpdir = bytes(d.getVar('TMPDIR'), encoding="utf-8") |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 466 | with open(path, 'rb') as f: |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 467 | file_content = f.read() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 468 | if tmpdir in file_content: |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 469 | trimmed = path.replace(os.path.join (d.getVar("PKGDEST"), name), "") |
| 470 | package_qa_add_message(messages, "buildpaths", "File %s in package %s contains reference to TMPDIR" % (trimmed, name)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 471 | |
| 472 | |
| 473 | QAPATHTEST[xorg-driver-abi] = "package_qa_check_xorg_driver_abi" |
| 474 | def package_qa_check_xorg_driver_abi(path, name, d, elf, messages): |
| 475 | """ |
| 476 | Check that all packages containing Xorg drivers have ABI dependencies |
| 477 | """ |
| 478 | |
| 479 | # Skip dev, dbg or nativesdk packages |
| 480 | if name.endswith("-dev") or name.endswith("-dbg") or name.startswith("nativesdk-"): |
| 481 | return |
| 482 | |
| 483 | driverdir = d.expand("${libdir}/xorg/modules/drivers/") |
| 484 | if driverdir in path and path.endswith(".so"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 485 | mlprefix = d.getVar('MLPREFIX') or '' |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 486 | for rdep in bb.utils.explode_deps(d.getVar('RDEPENDS:' + name) or ""): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 487 | if rdep.startswith("%sxorg-abi-" % mlprefix): |
| 488 | return |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 489 | package_qa_add_message(messages, "xorg-driver-abi", "Package %s contains Xorg driver (%s) but no xorg-abi- dependencies" % (name, os.path.basename(path))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 490 | |
| 491 | QAPATHTEST[infodir] = "package_qa_check_infodir" |
| 492 | def package_qa_check_infodir(path, name, d, elf, messages): |
| 493 | """ |
| 494 | Check that /usr/share/info/dir isn't shipped in a particular package |
| 495 | """ |
| 496 | infodir = d.expand("${infodir}/dir") |
| 497 | |
| 498 | if infodir in path: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 499 | package_qa_add_message(messages, "infodir", "The /usr/share/info/dir file is not meant to be shipped in a particular package.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 500 | |
| 501 | QAPATHTEST[symlink-to-sysroot] = "package_qa_check_symlink_to_sysroot" |
| 502 | def package_qa_check_symlink_to_sysroot(path, name, d, elf, messages): |
| 503 | """ |
| 504 | Check that the package doesn't contain any absolute symlinks to the sysroot. |
| 505 | """ |
| 506 | if os.path.islink(path): |
| 507 | target = os.readlink(path) |
| 508 | if os.path.isabs(target): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 509 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 510 | if target.startswith(tmpdir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 511 | trimmed = path.replace(os.path.join (d.getVar("PKGDEST"), name), "") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 512 | package_qa_add_message(messages, "symlink-to-sysroot", "Symlink %s in %s points to TMPDIR" % (trimmed, name)) |
| 513 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 514 | # Check license variables |
| 515 | do_populate_lic[postfuncs] += "populate_lic_qa_checksum" |
| 516 | python populate_lic_qa_checksum() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 517 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 518 | Check for changes in the license files. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 519 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 520 | sane = True |
| 521 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 522 | lic_files = d.getVar('LIC_FILES_CHKSUM') or '' |
| 523 | lic = d.getVar('LICENSE') |
| 524 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 525 | |
| 526 | if lic == "CLOSED": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 527 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 528 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 529 | if not lic_files and d.getVar('SRC_URI'): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 530 | sane &= package_qa_handle_error("license-checksum", pn + ": Recipe file fetches files and does not have license file information (LIC_FILES_CHKSUM)", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 531 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 532 | srcdir = d.getVar('S') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 533 | corebase_licensefile = d.getVar('COREBASE') + "/LICENSE" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 534 | for url in lic_files.split(): |
| 535 | try: |
| 536 | (type, host, path, user, pswd, parm) = bb.fetch.decodeurl(url) |
| 537 | except bb.fetch.MalformedUrl: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 538 | sane &= package_qa_handle_error("license-checksum", pn + ": LIC_FILES_CHKSUM contains an invalid URL: " + url, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 539 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 540 | srclicfile = os.path.join(srcdir, path) |
| 541 | if not os.path.isfile(srclicfile): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 542 | sane &= package_qa_handle_error("license-checksum", pn + ": LIC_FILES_CHKSUM points to an invalid file: " + srclicfile, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 543 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 544 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 545 | if (srclicfile == corebase_licensefile): |
| 546 | bb.warn("${COREBASE}/LICENSE is not a valid license file, please use '${COMMON_LICENSE_DIR}/MIT' for a MIT License file in LIC_FILES_CHKSUM. This will become an error in the future") |
| 547 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 548 | recipemd5 = parm.get('md5', '') |
| 549 | beginline, endline = 0, 0 |
| 550 | if 'beginline' in parm: |
| 551 | beginline = int(parm['beginline']) |
| 552 | if 'endline' in parm: |
| 553 | endline = int(parm['endline']) |
| 554 | |
| 555 | if (not beginline) and (not endline): |
| 556 | md5chksum = bb.utils.md5_file(srclicfile) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 557 | with open(srclicfile, 'r', errors='replace') as f: |
| 558 | license = f.read().splitlines() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 559 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 560 | with open(srclicfile, 'rb') as f: |
| 561 | import hashlib |
| 562 | lineno = 0 |
| 563 | license = [] |
| 564 | m = hashlib.md5() |
| 565 | for line in f: |
| 566 | lineno += 1 |
| 567 | if (lineno >= beginline): |
| 568 | if ((lineno <= endline) or not endline): |
| 569 | m.update(line) |
| 570 | license.append(line.decode('utf-8', errors='replace').rstrip()) |
| 571 | else: |
| 572 | break |
| 573 | md5chksum = m.hexdigest() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 574 | if recipemd5 == md5chksum: |
| 575 | bb.note (pn + ": md5 checksum matched for ", url) |
| 576 | else: |
| 577 | if recipemd5: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 578 | msg = pn + ": The LIC_FILES_CHKSUM does not match for " + url |
| 579 | msg = msg + "\n" + pn + ": The new md5 checksum is " + md5chksum |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 580 | max_lines = int(d.getVar('QA_MAX_LICENSE_LINES') or 20) |
| 581 | if not license or license[-1] != '': |
| 582 | # Ensure that our license text ends with a line break |
| 583 | # (will be added with join() below). |
| 584 | license.append('') |
| 585 | remove = len(license) - max_lines |
| 586 | if remove > 0: |
| 587 | start = max_lines // 2 |
| 588 | end = start + remove - 1 |
| 589 | del license[start:end] |
| 590 | license.insert(start, '...') |
| 591 | msg = msg + "\n" + pn + ": Here is the selected license text:" + \ |
| 592 | "\n" + \ |
| 593 | "{:v^70}".format(" beginline=%d " % beginline if beginline else "") + \ |
| 594 | "\n" + "\n".join(license) + \ |
| 595 | "{:^^70}".format(" endline=%d " % endline if endline else "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 596 | if beginline: |
| 597 | if endline: |
| 598 | srcfiledesc = "%s (lines %d through to %d)" % (srclicfile, beginline, endline) |
| 599 | else: |
| 600 | srcfiledesc = "%s (beginning on line %d)" % (srclicfile, beginline) |
| 601 | elif endline: |
| 602 | srcfiledesc = "%s (ending on line %d)" % (srclicfile, endline) |
| 603 | else: |
| 604 | srcfiledesc = srclicfile |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 605 | msg = msg + "\n" + pn + ": Check if the license information has changed in %s to verify that the LICENSE value \"%s\" remains valid" % (srcfiledesc, lic) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 606 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 607 | else: |
| 608 | msg = pn + ": LIC_FILES_CHKSUM is not specified for " + url |
| 609 | msg = msg + "\n" + pn + ": The md5 checksum is " + md5chksum |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 610 | sane &= package_qa_handle_error("license-checksum", msg, d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 611 | |
| 612 | if not sane: |
| 613 | bb.fatal("Fatal QA errors found, failing task.") |
| 614 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 615 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 616 | def qa_check_staged(path,d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 617 | """ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 618 | Check staged la and pc files for common problems like references to the work |
| 619 | directory. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 620 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 621 | As this is run after every stage we should be able to find the one |
| 622 | responsible for the errors easily even if we look at every .pc and .la file. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 623 | """ |
| 624 | |
| 625 | sane = True |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 626 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 627 | workdir = os.path.join(tmpdir, "work") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 628 | recipesysroot = d.getVar("RECIPE_SYSROOT") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 629 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 630 | if bb.data.inherits_class("native", d) or bb.data.inherits_class("cross", d): |
| 631 | pkgconfigcheck = workdir |
| 632 | else: |
| 633 | pkgconfigcheck = tmpdir |
| 634 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 635 | skip = (d.getVar('INSANE_SKIP') or "").split() |
| 636 | skip_la = False |
| 637 | if 'la' in skip: |
| 638 | bb.note("Recipe %s skipping qa checking: la" % d.getVar('PN')) |
| 639 | skip_la = True |
| 640 | |
| 641 | skip_pkgconfig = False |
| 642 | if 'pkgconfig' in skip: |
| 643 | bb.note("Recipe %s skipping qa checking: pkgconfig" % d.getVar('PN')) |
| 644 | skip_pkgconfig = True |
| 645 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 646 | # find all .la and .pc files |
| 647 | # read the content |
| 648 | # and check for stuff that looks wrong |
| 649 | for root, dirs, files in os.walk(path): |
| 650 | for file in files: |
| 651 | path = os.path.join(root,file) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 652 | if file.endswith(".la") and not skip_la: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 653 | with open(path) as f: |
| 654 | file_content = f.read() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 655 | file_content = file_content.replace(recipesysroot, "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 656 | if workdir in file_content: |
| 657 | error_msg = "%s failed sanity test (workdir) in path %s" % (file,root) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 658 | sane &= package_qa_handle_error("la", error_msg, d) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 659 | elif file.endswith(".pc") and not skip_pkgconfig: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 660 | with open(path) as f: |
| 661 | file_content = f.read() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 662 | file_content = file_content.replace(recipesysroot, "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 663 | if pkgconfigcheck in file_content: |
| 664 | error_msg = "%s failed sanity test (tmpdir) in path %s" % (file,root) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 665 | sane &= package_qa_handle_error("pkgconfig", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 666 | |
| 667 | return sane |
| 668 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 669 | # Run all package-wide warnfuncs and errorfuncs |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 670 | def package_qa_package(warnfuncs, errorfuncs, package, d): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 671 | warnings = {} |
| 672 | errors = {} |
| 673 | |
| 674 | for func in warnfuncs: |
| 675 | func(package, d, warnings) |
| 676 | for func in errorfuncs: |
| 677 | func(package, d, errors) |
| 678 | |
| 679 | for w in warnings: |
| 680 | package_qa_handle_error(w, warnings[w], d) |
| 681 | for e in errors: |
| 682 | package_qa_handle_error(e, errors[e], d) |
| 683 | |
| 684 | return len(errors) == 0 |
| 685 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 686 | # Run all recipe-wide warnfuncs and errorfuncs |
| 687 | def package_qa_recipe(warnfuncs, errorfuncs, pn, d): |
| 688 | warnings = {} |
| 689 | errors = {} |
| 690 | |
| 691 | for func in warnfuncs: |
| 692 | func(pn, d, warnings) |
| 693 | for func in errorfuncs: |
| 694 | func(pn, d, errors) |
| 695 | |
| 696 | for w in warnings: |
| 697 | package_qa_handle_error(w, warnings[w], d) |
| 698 | for e in errors: |
| 699 | package_qa_handle_error(e, errors[e], d) |
| 700 | |
| 701 | return len(errors) == 0 |
| 702 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 703 | # Walk over all files in a directory and call func |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 704 | def package_qa_walk(warnfuncs, errorfuncs, package, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 705 | import oe.qa |
| 706 | |
| 707 | #if this will throw an exception, then fix the dict above |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 708 | target_os = d.getVar('TARGET_OS') |
| 709 | target_arch = d.getVar('TARGET_ARCH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 710 | |
| 711 | warnings = {} |
| 712 | errors = {} |
| 713 | for path in pkgfiles[package]: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 714 | elf = None |
| 715 | if os.path.isfile(path): |
| 716 | elf = oe.qa.ELFFile(path) |
| 717 | try: |
| 718 | elf.open() |
| 719 | except oe.qa.NotELFFileError: |
| 720 | elf = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 721 | for func in warnfuncs: |
| 722 | func(path, package, d, elf, warnings) |
| 723 | for func in errorfuncs: |
| 724 | func(path, package, d, elf, errors) |
| 725 | |
| 726 | for w in warnings: |
| 727 | package_qa_handle_error(w, warnings[w], d) |
| 728 | for e in errors: |
| 729 | package_qa_handle_error(e, errors[e], d) |
| 730 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 731 | def package_qa_check_rdepends(pkg, pkgdest, skip, taskdeps, packages, d): |
| 732 | # Don't do this check for kernel/module recipes, there aren't too many debug/development |
| 733 | # packages and you can get false positives e.g. on kernel-module-lirc-dev |
| 734 | if bb.data.inherits_class("kernel", d) or bb.data.inherits_class("module-base", d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 735 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 736 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 737 | if not "-dbg" in pkg and not "packagegroup-" in pkg and not "-image" in pkg: |
| 738 | localdata = bb.data.createCopy(d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 739 | localdata.setVar('OVERRIDES', localdata.getVar('OVERRIDES') + ':' + pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 740 | |
| 741 | # Now check the RDEPENDS |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 742 | rdepends = bb.utils.explode_deps(localdata.getVar('RDEPENDS') or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 743 | |
| 744 | # Now do the sanity check!!! |
| 745 | if "build-deps" not in skip: |
| 746 | for rdepend in rdepends: |
| 747 | if "-dbg" in rdepend and "debug-deps" not in skip: |
| 748 | error_msg = "%s rdepends on %s" % (pkg,rdepend) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 749 | package_qa_handle_error("debug-deps", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 750 | if (not "-dev" in pkg and not "-staticdev" in pkg) and rdepend.endswith("-dev") and "dev-deps" not in skip: |
| 751 | error_msg = "%s rdepends on %s" % (pkg, rdepend) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 752 | package_qa_handle_error("dev-deps", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 753 | if rdepend not in packages: |
| 754 | rdep_data = oe.packagedata.read_subpkgdata(rdepend, d) |
| 755 | if rdep_data and 'PN' in rdep_data and rdep_data['PN'] in taskdeps: |
| 756 | continue |
| 757 | if not rdep_data or not 'PN' in rdep_data: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 758 | pkgdata_dir = d.getVar("PKGDATA_DIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 759 | try: |
| 760 | possibles = os.listdir("%s/runtime-rprovides/%s/" % (pkgdata_dir, rdepend)) |
| 761 | except OSError: |
| 762 | possibles = [] |
| 763 | for p in possibles: |
| 764 | rdep_data = oe.packagedata.read_subpkgdata(p, d) |
| 765 | if rdep_data and 'PN' in rdep_data and rdep_data['PN'] in taskdeps: |
| 766 | break |
| 767 | if rdep_data and 'PN' in rdep_data and rdep_data['PN'] in taskdeps: |
| 768 | continue |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 769 | if rdep_data and 'PN' in rdep_data: |
| 770 | error_msg = "%s rdepends on %s, but it isn't a build dependency, missing %s in DEPENDS or PACKAGECONFIG?" % (pkg, rdepend, rdep_data['PN']) |
| 771 | else: |
| 772 | error_msg = "%s rdepends on %s, but it isn't a build dependency?" % (pkg, rdepend) |
| 773 | package_qa_handle_error("build-deps", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 774 | |
| 775 | if "file-rdeps" not in skip: |
| 776 | ignored_file_rdeps = set(['/bin/sh', '/usr/bin/env', 'rtld(GNU_HASH)']) |
| 777 | if bb.data.inherits_class('nativesdk', d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 778 | ignored_file_rdeps |= set(['/bin/bash', '/usr/bin/perl', 'perl']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 779 | # For Saving the FILERDEPENDS |
| 780 | filerdepends = {} |
| 781 | rdep_data = oe.packagedata.read_subpkgdata(pkg, d) |
| 782 | for key in rdep_data: |
| 783 | if key.startswith("FILERDEPENDS_"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 784 | for subkey in bb.utils.explode_deps(rdep_data[key]): |
| 785 | if subkey not in ignored_file_rdeps and \ |
| 786 | not subkey.startswith('perl('): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 787 | # We already know it starts with FILERDEPENDS_ |
| 788 | filerdepends[subkey] = key[13:] |
| 789 | |
| 790 | if filerdepends: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | done = rdepends[:] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 792 | # Add the rprovides of itself |
| 793 | if pkg not in done: |
| 794 | done.insert(0, pkg) |
| 795 | |
| 796 | # The python is not a package, but python-core provides it, so |
| 797 | # skip checking /usr/bin/python if python is in the rdeps, in |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 798 | # case there is a RDEPENDS:pkg = "python" in the recipe. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 799 | for py in [ d.getVar('MLPREFIX') + "python", "python" ]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 800 | if py in done: |
| 801 | filerdepends.pop("/usr/bin/python",None) |
| 802 | done.remove(py) |
| 803 | for rdep in done: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 804 | # The file dependencies may contain package names, e.g., |
| 805 | # perl |
| 806 | filerdepends.pop(rdep,None) |
| 807 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 808 | # For Saving the FILERPROVIDES, RPROVIDES and FILES_INFO |
| 809 | rdep_data = oe.packagedata.read_subpkgdata(rdep, d) |
| 810 | for key in rdep_data: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 811 | if key.startswith("FILERPROVIDES_") or key.startswith("RPROVIDES:"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 812 | for subkey in bb.utils.explode_deps(rdep_data[key]): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 813 | filerdepends.pop(subkey,None) |
| 814 | # Add the files list to the rprovides |
| 815 | if key == "FILES_INFO": |
| 816 | # Use eval() to make it as a dict |
| 817 | for subkey in eval(rdep_data[key]): |
| 818 | filerdepends.pop(subkey,None) |
| 819 | if not filerdepends: |
| 820 | # Break if all the file rdepends are met |
| 821 | break |
| 822 | if filerdepends: |
| 823 | for key in filerdepends: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 824 | error_msg = "%s contained in package %s requires %s, but no providers found in RDEPENDS:%s?" % \ |
| 825 | (filerdepends[key].replace(":%s" % pkg, "").replace("@underscore@", "_"), pkg, key, pkg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 826 | package_qa_handle_error("file-rdeps", error_msg, d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 827 | package_qa_check_rdepends[vardepsexclude] = "OVERRIDES" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 828 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 829 | def package_qa_check_deps(pkg, pkgdest, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 830 | |
| 831 | localdata = bb.data.createCopy(d) |
| 832 | localdata.setVar('OVERRIDES', pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 833 | |
| 834 | def check_valid_deps(var): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 835 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 836 | rvar = bb.utils.explode_dep_versions2(localdata.getVar(var) or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 837 | except ValueError as e: |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 838 | bb.fatal("%s:%s: %s" % (var, pkg, e)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 839 | for dep in rvar: |
| 840 | for v in rvar[dep]: |
| 841 | if v and not v.startswith(('< ', '= ', '> ', '<= ', '>=')): |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 842 | error_msg = "%s:%s is invalid: %s (%s) only comparisons <, =, >, <=, and >= are allowed" % (var, pkg, dep, v) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 843 | package_qa_handle_error("dep-cmp", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 844 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 845 | check_valid_deps('RDEPENDS') |
| 846 | check_valid_deps('RRECOMMENDS') |
| 847 | check_valid_deps('RSUGGESTS') |
| 848 | check_valid_deps('RPROVIDES') |
| 849 | check_valid_deps('RREPLACES') |
| 850 | check_valid_deps('RCONFLICTS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 851 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 852 | QAPKGTEST[usrmerge] = "package_qa_check_usrmerge" |
| 853 | def package_qa_check_usrmerge(pkg, d, messages): |
| 854 | pkgdest = d.getVar('PKGDEST') |
| 855 | pkg_dir = pkgdest + os.sep + pkg + os.sep |
| 856 | merged_dirs = ['bin', 'sbin', 'lib'] + d.getVar('MULTILIB_VARIANTS').split() |
| 857 | for f in merged_dirs: |
| 858 | if os.path.exists(pkg_dir + f) and not os.path.islink(pkg_dir + f): |
| 859 | msg = "%s package is not obeying usrmerge distro feature. /%s should be relocated to /usr." % (pkg, f) |
| 860 | package_qa_add_message(messages, "usrmerge", msg) |
| 861 | return False |
| 862 | return True |
| 863 | |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 864 | QAPKGTEST[perllocalpod] = "package_qa_check_perllocalpod" |
| 865 | def package_qa_check_perllocalpod(pkg, d, messages): |
| 866 | """ |
| 867 | Check that the recipe didn't ship a perlocal.pod file, which shouldn't be |
| 868 | installed in a distribution package. cpan.bbclass sets NO_PERLLOCAL=1 to |
| 869 | handle this for most recipes. |
| 870 | """ |
| 871 | import glob |
| 872 | pkgd = oe.path.join(d.getVar('PKGDEST'), pkg) |
| 873 | podpath = oe.path.join(pkgd, d.getVar("libdir"), "perl*", "*", "*", "perllocal.pod") |
| 874 | |
| 875 | matches = glob.glob(podpath) |
| 876 | if matches: |
| 877 | matches = [package_qa_clean_path(path, d, pkg) for path in matches] |
| 878 | msg = "%s contains perllocal.pod (%s), should not be installed" % (pkg, " ".join(matches)) |
| 879 | package_qa_add_message(messages, "perllocalpod", msg) |
| 880 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 881 | QAPKGTEST[expanded-d] = "package_qa_check_expanded_d" |
| 882 | def package_qa_check_expanded_d(package, d, messages): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 883 | """ |
| 884 | Check for the expanded D (${D}) value in pkg_* and FILES |
| 885 | variables, warn the user to use it correctly. |
| 886 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 887 | sane = True |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 888 | expanded_d = d.getVar('D') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 889 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 890 | for var in 'FILES','pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm': |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 891 | bbvar = d.getVar(var + ":" + package) or "" |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 892 | if expanded_d in bbvar: |
| 893 | if var == 'FILES': |
| 894 | package_qa_add_message(messages, "expanded-d", "FILES in %s recipe should not contain the ${D} variable as it references the local build directory not the target filesystem, best solution is to remove the ${D} reference" % package) |
| 895 | sane = False |
| 896 | else: |
| 897 | package_qa_add_message(messages, "expanded-d", "%s in %s recipe contains ${D}, it should be replaced by $D instead" % (var, package)) |
| 898 | sane = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 899 | return sane |
| 900 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 901 | QAPKGTEST[unlisted-pkg-lics] = "package_qa_check_unlisted_pkg_lics" |
| 902 | def package_qa_check_unlisted_pkg_lics(package, d, messages): |
| 903 | """ |
| 904 | Check that all licenses for a package are among the licenses for the recipe. |
| 905 | """ |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 906 | pkg_lics = d.getVar('LICENSE:' + package) |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 907 | if not pkg_lics: |
| 908 | return True |
| 909 | |
| 910 | recipe_lics_set = oe.license.list_licenses(d.getVar('LICENSE')) |
| 911 | unlisted = oe.license.list_licenses(pkg_lics) - recipe_lics_set |
| 912 | if not unlisted: |
| 913 | return True |
| 914 | |
| 915 | package_qa_add_message(messages, "unlisted-pkg-lics", |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 916 | "LICENSE:%s includes licenses (%s) that are not " |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 917 | "listed in LICENSE" % (package, ' '.join(unlisted))) |
| 918 | return False |
| 919 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 920 | def package_qa_check_encoding(keys, encode, d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 921 | def check_encoding(key, enc): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 922 | sane = True |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 923 | value = d.getVar(key) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 924 | if value: |
| 925 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 926 | s = value.encode(enc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 927 | except UnicodeDecodeError as e: |
| 928 | error_msg = "%s has non %s characters" % (key,enc) |
| 929 | sane = False |
| 930 | package_qa_handle_error("invalid-chars", error_msg, d) |
| 931 | return sane |
| 932 | |
| 933 | for key in keys: |
| 934 | sane = check_encoding(key, encode) |
| 935 | if not sane: |
| 936 | break |
| 937 | |
| 938 | HOST_USER_UID := "${@os.getuid()}" |
| 939 | HOST_USER_GID := "${@os.getgid()}" |
| 940 | |
| 941 | QAPATHTEST[host-user-contaminated] = "package_qa_check_host_user" |
| 942 | def package_qa_check_host_user(path, name, d, elf, messages): |
| 943 | """Check for paths outside of /home which are owned by the user running bitbake.""" |
| 944 | |
| 945 | if not os.path.lexists(path): |
| 946 | return |
| 947 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 948 | dest = d.getVar('PKGDEST') |
| 949 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 950 | home = os.path.join(dest, 'home') |
| 951 | if path == home or path.startswith(home + os.sep): |
| 952 | return |
| 953 | |
| 954 | try: |
| 955 | stat = os.lstat(path) |
| 956 | except OSError as exc: |
| 957 | import errno |
| 958 | if exc.errno != errno.ENOENT: |
| 959 | raise |
| 960 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 961 | check_uid = int(d.getVar('HOST_USER_UID')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 962 | if stat.st_uid == check_uid: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 963 | package_qa_add_message(messages, "host-user-contaminated", "%s: %s is owned by uid %d, which is the same as the user running bitbake. This may be due to host contamination" % (pn, package_qa_clean_path(path, d, name), check_uid)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 964 | return False |
| 965 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 966 | check_gid = int(d.getVar('HOST_USER_GID')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 967 | if stat.st_gid == check_gid: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 968 | package_qa_add_message(messages, "host-user-contaminated", "%s: %s is owned by gid %d, which is the same as the user running bitbake. This may be due to host contamination" % (pn, package_qa_clean_path(path, d, name), check_gid)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 969 | return False |
| 970 | return True |
| 971 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 972 | QARECIPETEST[src-uri-bad] = "package_qa_check_src_uri" |
| 973 | def package_qa_check_src_uri(pn, d, messages): |
| 974 | import re |
| 975 | |
| 976 | if "${PN}" in d.getVar("SRC_URI", False): |
| 977 | package_qa_handle_error("src-uri-bad", "%s: SRC_URI uses PN not BPN" % pn, d) |
| 978 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 979 | for url in d.getVar("SRC_URI").split(): |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 980 | if re.search(r"git(hu|la)b\.com/.+/.+/archive/.+", url): |
| 981 | package_qa_handle_error("src-uri-bad", "%s: SRC_URI uses unstable GitHub/GitLab archives, convert recipe to use git protocol" % pn, d) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 982 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 983 | QARECIPETEST[unhandled-features-check] = "package_qa_check_unhandled_features_check" |
| 984 | def package_qa_check_unhandled_features_check(pn, d, messages): |
| 985 | if not bb.data.inherits_class('features_check', d): |
| 986 | var_set = False |
| 987 | for kind in ['DISTRO', 'MACHINE', 'COMBINED']: |
| 988 | for var in ['ANY_OF_' + kind + '_FEATURES', 'REQUIRED_' + kind + '_FEATURES', 'CONFLICT_' + kind + '_FEATURES']: |
| 989 | if d.getVar(var) is not None or d.overridedata.get(var) is not None: |
| 990 | var_set = True |
| 991 | if var_set: |
| 992 | package_qa_handle_error("unhandled-features-check", "%s: recipe doesn't inherit features_check" % pn, d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 993 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 994 | QARECIPETEST[missing-update-alternatives] = "package_qa_check_missing_update_alternatives" |
| 995 | def package_qa_check_missing_update_alternatives(pn, d, messages): |
| 996 | # Look at all packages and find out if any of those sets ALTERNATIVE variable |
| 997 | # without inheriting update-alternatives class |
| 998 | for pkg in (d.getVar('PACKAGES') or '').split(): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 999 | if d.getVar('ALTERNATIVE:%s' % pkg) and not bb.data.inherits_class('update-alternatives', d): |
| 1000 | package_qa_handle_error("missing-update-alternatives", "%s: recipe defines ALTERNATIVE:%s but doesn't inherit update-alternatives. This might fail during do_rootfs later!" % (pn, pkg), d) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1001 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1002 | # The PACKAGE FUNC to scan each package |
| 1003 | python do_package_qa () { |
| 1004 | import subprocess |
| 1005 | import oe.packagedata |
| 1006 | |
| 1007 | bb.note("DO PACKAGE QA") |
| 1008 | |
| 1009 | bb.build.exec_func("read_subpackage_metadata", d) |
| 1010 | |
| 1011 | # Check non UTF-8 characters on recipe's metadata |
| 1012 | package_qa_check_encoding(['DESCRIPTION', 'SUMMARY', 'LICENSE', 'SECTION'], 'utf-8', d) |
| 1013 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1014 | logdir = d.getVar('T') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1015 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1016 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1017 | # Scan the packages... |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1018 | pkgdest = d.getVar('PKGDEST') |
| 1019 | packages = set((d.getVar('PACKAGES') or '').split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1020 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1021 | global pkgfiles |
| 1022 | pkgfiles = {} |
| 1023 | for pkg in packages: |
| 1024 | pkgfiles[pkg] = [] |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1025 | pkgdir = os.path.join(pkgdest, pkg) |
| 1026 | for walkroot, dirs, files in os.walk(pkgdir): |
| 1027 | # Don't walk into top-level CONTROL or DEBIAN directories as these |
| 1028 | # are temporary directories created by do_package. |
| 1029 | if walkroot == pkgdir: |
| 1030 | for control in ("CONTROL", "DEBIAN"): |
| 1031 | if control in dirs: |
| 1032 | dirs.remove(control) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1033 | for file in files: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1034 | pkgfiles[pkg].append(os.path.join(walkroot, file)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1035 | |
| 1036 | # no packages should be scanned |
| 1037 | if not packages: |
| 1038 | return |
| 1039 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1040 | import re |
| 1041 | # The package name matches the [a-z0-9.+-]+ regular expression |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 1042 | pkgname_pattern = re.compile(r"^[a-z0-9.+-]+$") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1043 | |
| 1044 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) |
| 1045 | taskdeps = set() |
| 1046 | for dep in taskdepdata: |
| 1047 | taskdeps.add(taskdepdata[dep][0]) |
| 1048 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1049 | def parse_test_matrix(matrix_name): |
| 1050 | testmatrix = d.getVarFlags(matrix_name) or {} |
| 1051 | g = globals() |
| 1052 | warnchecks = [] |
| 1053 | for w in (d.getVar("WARN_QA") or "").split(): |
| 1054 | if w in skip: |
| 1055 | continue |
| 1056 | if w in testmatrix and testmatrix[w] in g: |
| 1057 | warnchecks.append(g[testmatrix[w]]) |
| 1058 | |
| 1059 | errorchecks = [] |
| 1060 | for e in (d.getVar("ERROR_QA") or "").split(): |
| 1061 | if e in skip: |
| 1062 | continue |
| 1063 | if e in testmatrix and testmatrix[e] in g: |
| 1064 | errorchecks.append(g[testmatrix[e]]) |
| 1065 | return warnchecks, errorchecks |
| 1066 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1067 | for package in packages: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1068 | skip = set((d.getVar('INSANE_SKIP') or "").split() + |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1069 | (d.getVar('INSANE_SKIP:' + package) or "").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1070 | if skip: |
| 1071 | bb.note("Package %s skipping QA tests: %s" % (package, str(skip))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1072 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1073 | bb.note("Checking Package: %s" % package) |
| 1074 | # Check package name |
| 1075 | if not pkgname_pattern.match(package): |
| 1076 | package_qa_handle_error("pkgname", |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1077 | "%s doesn't match the [a-z0-9.+-]+ regex" % package, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1078 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1079 | warn_checks, error_checks = parse_test_matrix("QAPATHTEST") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1080 | package_qa_walk(warn_checks, error_checks, package, d) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1081 | |
| 1082 | warn_checks, error_checks = parse_test_matrix("QAPKGTEST") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1083 | package_qa_package(warn_checks, error_checks, package, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1084 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1085 | package_qa_check_rdepends(package, pkgdest, skip, taskdeps, packages, d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1086 | package_qa_check_deps(package, pkgdest, d) |
| 1087 | |
| 1088 | warn_checks, error_checks = parse_test_matrix("QARECIPETEST") |
| 1089 | package_qa_recipe(warn_checks, error_checks, pn, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1090 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1091 | if 'libdir' in d.getVar("ALL_QA").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1092 | package_qa_check_libdir(d) |
| 1093 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1094 | qa_sane = d.getVar("QA_SANE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1095 | if not qa_sane: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1096 | bb.fatal("QA run found fatal errors. Please consider fixing them.") |
| 1097 | bb.note("DONE with PACKAGE QA") |
| 1098 | } |
| 1099 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1100 | # binutils is used for most checks, so need to set as dependency |
| 1101 | # POPULATESYSROOTDEPS is defined in staging class. |
| 1102 | do_package_qa[depends] += "${POPULATESYSROOTDEPS}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1103 | do_package_qa[vardepsexclude] = "BB_TASKDEPDATA" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1104 | do_package_qa[rdeptask] = "do_packagedata" |
| 1105 | addtask do_package_qa after do_packagedata do_package before do_build |
| 1106 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1107 | # Add the package specific INSANE_SKIPs to the sstate dependencies |
| 1108 | python() { |
| 1109 | pkgs = (d.getVar('PACKAGES') or '').split() |
| 1110 | for pkg in pkgs: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1111 | d.appendVarFlag("do_package_qa", "vardeps", " INSANE_SKIP:{}".format(pkg)) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1114 | SSTATETASKS += "do_package_qa" |
| 1115 | do_package_qa[sstate-inputdirs] = "" |
| 1116 | do_package_qa[sstate-outputdirs] = "" |
| 1117 | python do_package_qa_setscene () { |
| 1118 | sstate_setscene(d) |
| 1119 | } |
| 1120 | addtask do_package_qa_setscene |
| 1121 | |
| 1122 | python do_qa_staging() { |
| 1123 | bb.note("QA checking staging") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1124 | if not qa_check_staged(d.expand('${SYSROOT_DESTDIR}${libdir}'), d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1125 | bb.fatal("QA staging was broken by the package built above") |
| 1126 | } |
| 1127 | |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 1128 | python do_qa_patch() { |
| 1129 | import subprocess |
| 1130 | |
| 1131 | ########################################################################### |
| 1132 | # Check patch.log for fuzz warnings |
| 1133 | # |
| 1134 | # Further information on why we check for patch fuzz warnings: |
| 1135 | # http://lists.openembedded.org/pipermail/openembedded-core/2018-March/148675.html |
| 1136 | # https://bugzilla.yoctoproject.org/show_bug.cgi?id=10450 |
| 1137 | ########################################################################### |
| 1138 | |
| 1139 | logdir = d.getVar('T') |
| 1140 | patchlog = os.path.join(logdir,"log.do_patch") |
| 1141 | |
| 1142 | if os.path.exists(patchlog): |
| 1143 | fuzzheader = '--- Patch fuzz start ---' |
| 1144 | fuzzfooter = '--- Patch fuzz end ---' |
| 1145 | statement = "grep -e '%s' %s > /dev/null" % (fuzzheader, patchlog) |
| 1146 | if subprocess.call(statement, shell=True) == 0: |
| 1147 | msg = "Fuzz detected:\n\n" |
| 1148 | fuzzmsg = "" |
| 1149 | inFuzzInfo = False |
| 1150 | f = open(patchlog, "r") |
| 1151 | for line in f: |
| 1152 | if fuzzheader in line: |
| 1153 | inFuzzInfo = True |
| 1154 | fuzzmsg = "" |
| 1155 | elif fuzzfooter in line: |
| 1156 | fuzzmsg = fuzzmsg.replace('\n\n', '\n') |
| 1157 | msg += fuzzmsg |
| 1158 | msg += "\n" |
| 1159 | inFuzzInfo = False |
| 1160 | elif inFuzzInfo and not 'Now at patch' in line: |
| 1161 | fuzzmsg += line |
| 1162 | f.close() |
| 1163 | msg += "The context lines in the patches can be updated with devtool:\n" |
| 1164 | msg += "\n" |
| 1165 | msg += " devtool modify %s\n" % d.getVar('PN') |
| 1166 | msg += " devtool finish --force-patch-refresh %s <layer_path>\n\n" % d.getVar('PN') |
| 1167 | msg += "Don't forget to review changes done by devtool!\n" |
| 1168 | if 'patch-fuzz' in d.getVar('ERROR_QA'): |
| 1169 | bb.error(msg) |
| 1170 | elif 'patch-fuzz' in d.getVar('WARN_QA'): |
| 1171 | bb.warn(msg) |
| 1172 | msg = "Patch log indicates that patches do not apply cleanly." |
| 1173 | package_qa_handle_error("patch-fuzz", msg, d) |
| 1174 | } |
| 1175 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1176 | python do_qa_configure() { |
| 1177 | import subprocess |
| 1178 | |
| 1179 | ########################################################################### |
| 1180 | # Check config.log for cross compile issues |
| 1181 | ########################################################################### |
| 1182 | |
| 1183 | configs = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1184 | workdir = d.getVar('WORKDIR') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1185 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1186 | skip = (d.getVar('INSANE_SKIP') or "").split() |
| 1187 | skip_configure_unsafe = False |
| 1188 | if 'configure-unsafe' in skip: |
| 1189 | bb.note("Recipe %s skipping qa checking: configure-unsafe" % d.getVar('PN')) |
| 1190 | skip_configure_unsafe = True |
| 1191 | |
| 1192 | if bb.data.inherits_class('autotools', d) and not skip_configure_unsafe: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1193 | bb.note("Checking autotools environment for common misconfiguration") |
| 1194 | for root, dirs, files in os.walk(workdir): |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1195 | statement = "grep -q -F -e 'is unsafe for cross-compilation' %s" % \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1196 | os.path.join(root,"config.log") |
| 1197 | if "config.log" in files: |
| 1198 | if subprocess.call(statement, shell=True) == 0: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1199 | error_msg = """This autoconf log indicates errors, it looked at host include and/or library paths while determining system capabilities. |
| 1200 | Rerun configure task after fixing this.""" |
| 1201 | package_qa_handle_error("configure-unsafe", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1202 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1203 | if "configure.ac" in files: |
| 1204 | configs.append(os.path.join(root,"configure.ac")) |
| 1205 | if "configure.in" in files: |
| 1206 | configs.append(os.path.join(root, "configure.in")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1207 | |
| 1208 | ########################################################################### |
| 1209 | # Check gettext configuration and dependencies are correct |
| 1210 | ########################################################################### |
| 1211 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1212 | skip_configure_gettext = False |
| 1213 | if 'configure-gettext' in skip: |
| 1214 | bb.note("Recipe %s skipping qa checking: configure-gettext" % d.getVar('PN')) |
| 1215 | skip_configure_gettext = True |
| 1216 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1217 | cnf = d.getVar('EXTRA_OECONF') or "" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1218 | if not ("gettext" in d.getVar('P') or "gcc-runtime" in d.getVar('P') or \ |
| 1219 | "--disable-nls" in cnf or skip_configure_gettext): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1220 | ml = d.getVar("MLPREFIX") or "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1221 | if bb.data.inherits_class('cross-canadian', d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1222 | gt = "nativesdk-gettext" |
| 1223 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1224 | gt = "gettext-native" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1225 | deps = bb.utils.explode_deps(d.getVar('DEPENDS') or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1226 | if gt not in deps: |
| 1227 | for config in configs: |
| 1228 | gnu = "grep \"^[[:space:]]*AM_GNU_GETTEXT\" %s >/dev/null" % config |
| 1229 | if subprocess.call(gnu, shell=True) == 0: |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 1230 | error_msg = "AM_GNU_GETTEXT used but no inherit gettext" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1231 | package_qa_handle_error("configure-gettext", error_msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1232 | |
| 1233 | ########################################################################### |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1234 | # Check unrecognised configure options (with a white list) |
| 1235 | ########################################################################### |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1236 | if bb.data.inherits_class("autotools", d) or bb.data.inherits_class("meson", d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1237 | bb.note("Checking configure output for unrecognised options") |
| 1238 | try: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1239 | if bb.data.inherits_class("autotools", d): |
| 1240 | flag = "WARNING: unrecognized options:" |
| 1241 | log = os.path.join(d.getVar('B'), 'config.log') |
| 1242 | if bb.data.inherits_class("meson", d): |
| 1243 | flag = "WARNING: Unknown options:" |
| 1244 | log = os.path.join(d.getVar('T'), 'log.do_configure') |
| 1245 | output = subprocess.check_output(['grep', '-F', flag, log]).decode("utf-8").replace(', ', ' ').replace('"', '') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1246 | options = set() |
| 1247 | for line in output.splitlines(): |
| 1248 | options |= set(line.partition(flag)[2].split()) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1249 | whitelist = set(d.getVar("UNKNOWN_CONFIGURE_WHITELIST").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1250 | options -= whitelist |
| 1251 | if options: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1252 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1253 | error_msg = pn + ": configure was passed unrecognised options: " + " ".join(options) |
| 1254 | package_qa_handle_error("unknown-configure-option", error_msg, d) |
| 1255 | except subprocess.CalledProcessError: |
| 1256 | pass |
| 1257 | |
| 1258 | # Check invalid PACKAGECONFIG |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1259 | pkgconfig = (d.getVar("PACKAGECONFIG") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1260 | if pkgconfig: |
| 1261 | pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {} |
| 1262 | for pconfig in pkgconfig: |
| 1263 | if pconfig not in pkgconfigflags: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1264 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1265 | error_msg = "%s: invalid PACKAGECONFIG: %s" % (pn, pconfig) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1266 | package_qa_handle_error("invalid-packageconfig", error_msg, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1267 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1268 | qa_sane = d.getVar("QA_SANE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1269 | if not qa_sane: |
| 1270 | bb.fatal("Fatal QA errors found, failing task.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | python do_qa_unpack() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1274 | src_uri = d.getVar('SRC_URI') |
| 1275 | s_dir = d.getVar('S') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1276 | if src_uri and not os.path.exists(s_dir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1277 | bb.warn('%s: the directory %s (%s) pointed to by the S variable doesn\'t exist - please set S within the recipe to point to where the source has been unpacked to' % (d.getVar('PN'), d.getVar('S', False), s_dir)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | # The Staging Func, to check all staging |
| 1281 | #addtask qa_staging after do_populate_sysroot before do_build |
| 1282 | do_populate_sysroot[postfuncs] += "do_qa_staging " |
| 1283 | |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 1284 | # Check for patch fuzz |
| 1285 | do_patch[postfuncs] += "do_qa_patch " |
| 1286 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1287 | # Check broken config.log files, for packages requiring Gettext which |
| 1288 | # don't have it in DEPENDS. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1289 | #addtask qa_configure after do_configure before do_compile |
| 1290 | do_configure[postfuncs] += "do_qa_configure " |
| 1291 | |
| 1292 | # Check does S exist. |
| 1293 | do_unpack[postfuncs] += "do_qa_unpack" |
| 1294 | |
| 1295 | python () { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1296 | import re |
| 1297 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1298 | tests = d.getVar('ALL_QA').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1299 | if "desktop" in tests: |
| 1300 | d.appendVar("PACKAGE_DEPENDS", " desktop-file-utils-native") |
| 1301 | |
| 1302 | ########################################################################### |
| 1303 | # Check various variables |
| 1304 | ########################################################################### |
| 1305 | |
| 1306 | # Checking ${FILESEXTRAPATHS} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1307 | extrapaths = (d.getVar("FILESEXTRAPATHS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1308 | if '__default' not in extrapaths.split(":"): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1309 | msg = "FILESEXTRAPATHS-variable, must always use :prepend (or :append)\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1310 | msg += "type of assignment, and don't forget the colon.\n" |
| 1311 | msg += "Please assign it with the format of:\n" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1312 | msg += " FILESEXTRAPATHS:append := \":${THISDIR}/Your_Files_Path\" or\n" |
| 1313 | msg += " FILESEXTRAPATHS:prepend := \"${THISDIR}/Your_Files_Path:\"\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1314 | msg += "in your bbappend file\n\n" |
| 1315 | msg += "Your incorrect assignment is:\n" |
| 1316 | msg += "%s\n" % extrapaths |
| 1317 | bb.warn(msg) |
| 1318 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1319 | overrides = d.getVar('OVERRIDES').split(':') |
| 1320 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1321 | if pn in overrides: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1322 | msg = 'Recipe %s has PN of "%s" which is in OVERRIDES, this can result in unexpected behaviour.' % (d.getVar("FILE"), pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1323 | package_qa_handle_error("pn-overrides", msg, d) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 1324 | prog = re.compile(r'[A-Z]') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1325 | if prog.search(pn): |
| 1326 | package_qa_handle_error("uppercase-pn", 'PN: %s is upper case, this can result in unexpected behavior.' % pn, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1327 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1328 | # Some people mistakenly use DEPENDS:${PN} instead of DEPENDS and wonder |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 1329 | # why it doesn't work. |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1330 | if (d.getVar(d.expand('DEPENDS:${PN}'))): |
| 1331 | package_qa_handle_error("pkgvarcheck", "recipe uses DEPENDS:${PN}, should use DEPENDS", d) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 1332 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1333 | issues = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1334 | if (d.getVar('PACKAGES') or "").split(): |
| 1335 | for dep in (d.getVar('QADEPENDS') or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1336 | d.appendVarFlag('do_package_qa', 'depends', " %s:do_populate_sysroot" % dep) |
| 1337 | for var in 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RCONFLICTS', 'RPROVIDES', 'RREPLACES', 'FILES', 'pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm', 'ALLOW_EMPTY': |
| 1338 | if d.getVar(var, False): |
| 1339 | issues.append(var) |
| 1340 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1341 | fakeroot_tests = d.getVar('FAKEROOT_QA').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1342 | if set(tests) & set(fakeroot_tests): |
| 1343 | d.setVarFlag('do_package_qa', 'fakeroot', '1') |
| 1344 | d.appendVarFlag('do_package_qa', 'depends', ' virtual/fakeroot-native:do_populate_sysroot') |
| 1345 | else: |
| 1346 | d.setVarFlag('do_package_qa', 'rdeptask', '') |
| 1347 | for i in issues: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1348 | package_qa_handle_error("pkgvarcheck", "%s: Variable %s is set as not being package specific, please fix this." % (d.getVar("FILE"), i), d) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1349 | |
| 1350 | if 'native-last' not in (d.getVar('INSANE_SKIP') or "").split(): |
| 1351 | for native_class in ['native', 'nativesdk']: |
| 1352 | if bb.data.inherits_class(native_class, d): |
| 1353 | |
| 1354 | inherited_classes = d.getVar('__inherit_cache', False) or [] |
| 1355 | needle = os.path.join('classes', native_class) |
| 1356 | |
| 1357 | bbclassextend = (d.getVar('BBCLASSEXTEND') or '').split() |
| 1358 | # BBCLASSEXTEND items are always added in the end |
| 1359 | skip_classes = bbclassextend |
| 1360 | if bb.data.inherits_class('native', d) or 'native' in bbclassextend: |
| 1361 | # native also inherits nopackages and relocatable bbclasses |
| 1362 | skip_classes.extend(['nopackages', 'relocatable']) |
| 1363 | |
| 1364 | broken_order = [] |
| 1365 | for class_item in reversed(inherited_classes): |
| 1366 | if needle not in class_item: |
| 1367 | for extend_item in skip_classes: |
| 1368 | if os.path.join('classes', '%s.bbclass' % extend_item) in class_item: |
| 1369 | break |
| 1370 | else: |
| 1371 | pn = d.getVar('PN') |
| 1372 | broken_order.append(os.path.basename(class_item)) |
| 1373 | else: |
| 1374 | break |
| 1375 | if broken_order: |
| 1376 | package_qa_handle_error("native-last", "%s: native/nativesdk class is not inherited last, this can result in unexpected behaviour. " |
| 1377 | "Classes inherited after native/nativesdk: %s" % (pn, " ".join(broken_order)), d) |
| 1378 | |
| 1379 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1380 | qa_sane = d.getVar("QA_SANE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1381 | if not qa_sane: |
| 1382 | bb.fatal("Fatal QA errors found, failing task.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1383 | } |