insane.bbclass 65 KB

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