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