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