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