package.bbclass 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  1. #
  2. # Packaging process
  3. #
  4. # Executive summary: This class iterates over the functions listed in PACKAGEFUNCS
  5. # Taking D and splitting it up into the packages listed in PACKAGES, placing the
  6. # resulting output in PKGDEST.
  7. #
  8. # There are the following default steps but PACKAGEFUNCS can be extended:
  9. #
  10. # a) package_get_auto_pr - get PRAUTO from remote PR service
  11. #
  12. # b) perform_packagecopy - Copy D into PKGD
  13. #
  14. # c) package_do_split_locales - Split out the locale files, updates FILES and PACKAGES
  15. #
  16. # d) split_and_strip_files - split the files into runtime and debug and strip them.
  17. # Debug files include debug info split, and associated sources that end up in -dbg packages
  18. #
  19. # e) fixup_perms - Fix up permissions in the package before we split it.
  20. #
  21. # f) populate_packages - Split the files in PKGD into separate packages in PKGDEST/<pkgname>
  22. # Also triggers the binary stripping code to put files in -dbg packages.
  23. #
  24. # g) package_do_filedeps - Collect perfile run-time dependency metadata
  25. # The data is stores in FILER{PROVIDES,DEPENDS}_file_pkg variables with
  26. # a list of affected files in FILER{PROVIDES,DEPENDS}FLIST_pkg
  27. #
  28. # h) package_do_shlibs - Look at the shared libraries generated and autotmatically add any
  29. # dependencies found. Also stores the package name so anyone else using this library
  30. # knows which package to depend on.
  31. #
  32. # i) package_do_pkgconfig - Keep track of which packages need and provide which .pc files
  33. #
  34. # j) read_shlibdeps - Reads the stored shlibs information into the metadata
  35. #
  36. # k) package_depchains - Adds automatic dependencies to -dbg and -dev packages
  37. #
  38. # l) emit_pkgdata - saves the packaging data into PKGDATA_DIR for use in later
  39. # packaging steps
  40. inherit packagedata
  41. inherit chrpath
  42. inherit package_pkgdata
  43. # Need the package_qa_handle_error() in insane.bbclass
  44. inherit insane
  45. PKGD = "${WORKDIR}/package"
  46. PKGDEST = "${WORKDIR}/packages-split"
  47. LOCALE_SECTION ?= ''
  48. ALL_MULTILIB_PACKAGE_ARCHS = "${@all_multilib_tune_values(d, 'PACKAGE_ARCHS')}"
  49. # rpm is used for the per-file dependency identification
  50. # dwarfsrcfiles is used to determine the list of debug source files
  51. PACKAGE_DEPENDS += "rpm-native dwarfsrcfiles-native"
  52. # If your postinstall can execute at rootfs creation time rather than on
  53. # target but depends on a native/cross tool in order to execute, you need to
  54. # list that tool in PACKAGE_WRITE_DEPS. Target package dependencies belong
  55. # in the package dependencies as normal, this is just for native/cross support
  56. # tools at rootfs build time.
  57. PACKAGE_WRITE_DEPS ??= ""
  58. def legitimize_package_name(s):
  59. """
  60. Make sure package names are legitimate strings
  61. """
  62. import re
  63. def fixutf(m):
  64. cp = m.group(1)
  65. if cp:
  66. return ('\\u%s' % cp).encode('latin-1').decode('unicode_escape')
  67. # Handle unicode codepoints encoded as <U0123>, as in glibc locale files.
  68. s = re.sub(r'<U([0-9A-Fa-f]{1,4})>', fixutf, s)
  69. # Remaining package name validity fixes
  70. return s.lower().replace('_', '-').replace('@', '+').replace(',', '+').replace('/', '-')
  71. def do_split_packages(d, root, file_regex, output_pattern, description, postinst=None, recursive=False, hook=None, extra_depends=None, aux_files_pattern=None, postrm=None, allow_dirs=False, prepend=False, match_path=False, aux_files_pattern_verbatim=None, allow_links=False, summary=None):
  72. """
  73. Used in .bb files to split up dynamically generated subpackages of a
  74. given package, usually plugins or modules.
  75. Arguments:
  76. root -- the path in which to search
  77. file_regex -- regular expression to match searched files. Use
  78. parentheses () to mark the part of this expression
  79. that should be used to derive the module name (to be
  80. substituted where %s is used in other function
  81. arguments as noted below)
  82. output_pattern -- pattern to use for the package names. Must include %s.
  83. description -- description to set for each package. Must include %s.
  84. postinst -- postinstall script to use for all packages (as a
  85. string)
  86. recursive -- True to perform a recursive search - default False
  87. hook -- a hook function to be called for every match. The
  88. function will be called with the following arguments
  89. (in the order listed):
  90. f: full path to the file/directory match
  91. pkg: the package name
  92. file_regex: as above
  93. output_pattern: as above
  94. modulename: the module name derived using file_regex
  95. extra_depends -- extra runtime dependencies (RDEPENDS) to be set for
  96. all packages. The default value of None causes a
  97. dependency on the main package (${PN}) - if you do
  98. not want this, pass '' for this parameter.
  99. aux_files_pattern -- extra item(s) to be added to FILES for each
  100. package. Can be a single string item or a list of
  101. strings for multiple items. Must include %s.
  102. postrm -- postrm script to use for all packages (as a string)
  103. allow_dirs -- True allow directories to be matched - default False
  104. prepend -- if True, prepend created packages to PACKAGES instead
  105. of the default False which appends them
  106. match_path -- match file_regex on the whole relative path to the
  107. root rather than just the file name
  108. aux_files_pattern_verbatim -- extra item(s) to be added to FILES for
  109. each package, using the actual derived module name
  110. rather than converting it to something legal for a
  111. package name. Can be a single string item or a list
  112. of strings for multiple items. Must include %s.
  113. allow_links -- True to allow symlinks to be matched - default False
  114. summary -- Summary to set for each package. Must include %s;
  115. defaults to description if not set.
  116. """
  117. dvar = d.getVar('PKGD')
  118. root = d.expand(root)
  119. output_pattern = d.expand(output_pattern)
  120. extra_depends = d.expand(extra_depends)
  121. # If the root directory doesn't exist, don't error out later but silently do
  122. # no splitting.
  123. if not os.path.exists(dvar + root):
  124. return []
  125. ml = d.getVar("MLPREFIX")
  126. if ml:
  127. if not output_pattern.startswith(ml):
  128. output_pattern = ml + output_pattern
  129. newdeps = []
  130. for dep in (extra_depends or "").split():
  131. if dep.startswith(ml):
  132. newdeps.append(dep)
  133. else:
  134. newdeps.append(ml + dep)
  135. if newdeps:
  136. extra_depends = " ".join(newdeps)
  137. packages = d.getVar('PACKAGES').split()
  138. split_packages = set()
  139. if postinst:
  140. postinst = '#!/bin/sh\n' + postinst + '\n'
  141. if postrm:
  142. postrm = '#!/bin/sh\n' + postrm + '\n'
  143. if not recursive:
  144. objs = os.listdir(dvar + root)
  145. else:
  146. objs = []
  147. for walkroot, dirs, files in os.walk(dvar + root):
  148. for file in files:
  149. relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
  150. if relpath:
  151. objs.append(relpath)
  152. if extra_depends == None:
  153. extra_depends = d.getVar("PN")
  154. if not summary:
  155. summary = description
  156. for o in sorted(objs):
  157. import re, stat
  158. if match_path:
  159. m = re.match(file_regex, o)
  160. else:
  161. m = re.match(file_regex, os.path.basename(o))
  162. if not m:
  163. continue
  164. f = os.path.join(dvar + root, o)
  165. mode = os.lstat(f).st_mode
  166. if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
  167. continue
  168. on = legitimize_package_name(m.group(1))
  169. pkg = output_pattern % on
  170. split_packages.add(pkg)
  171. if not pkg in packages:
  172. if prepend:
  173. packages = [pkg] + packages
  174. else:
  175. packages.append(pkg)
  176. oldfiles = d.getVar('FILES_' + pkg)
  177. newfile = os.path.join(root, o)
  178. # These names will be passed through glob() so if the filename actually
  179. # contains * or ? (rare, but possible) we need to handle that specially
  180. newfile = newfile.replace('*', '[*]')
  181. newfile = newfile.replace('?', '[?]')
  182. if not oldfiles:
  183. the_files = [newfile]
  184. if aux_files_pattern:
  185. if type(aux_files_pattern) is list:
  186. for fp in aux_files_pattern:
  187. the_files.append(fp % on)
  188. else:
  189. the_files.append(aux_files_pattern % on)
  190. if aux_files_pattern_verbatim:
  191. if type(aux_files_pattern_verbatim) is list:
  192. for fp in aux_files_pattern_verbatim:
  193. the_files.append(fp % m.group(1))
  194. else:
  195. the_files.append(aux_files_pattern_verbatim % m.group(1))
  196. d.setVar('FILES_' + pkg, " ".join(the_files))
  197. else:
  198. d.setVar('FILES_' + pkg, oldfiles + " " + newfile)
  199. if extra_depends != '':
  200. d.appendVar('RDEPENDS_' + pkg, ' ' + extra_depends)
  201. if not d.getVar('DESCRIPTION_' + pkg):
  202. d.setVar('DESCRIPTION_' + pkg, description % on)
  203. if not d.getVar('SUMMARY_' + pkg):
  204. d.setVar('SUMMARY_' + pkg, summary % on)
  205. if postinst:
  206. d.setVar('pkg_postinst_' + pkg, postinst)
  207. if postrm:
  208. d.setVar('pkg_postrm_' + pkg, postrm)
  209. if callable(hook):
  210. hook(f, pkg, file_regex, output_pattern, m.group(1))
  211. d.setVar('PACKAGES', ' '.join(packages))
  212. return list(split_packages)
  213. PACKAGE_DEPENDS += "file-native pigz-native"
  214. python () {
  215. if d.getVar('PACKAGES') != '':
  216. deps = ""
  217. for dep in (d.getVar('PACKAGE_DEPENDS') or "").split():
  218. deps += " %s:do_populate_sysroot" % dep
  219. d.appendVarFlag('do_package', 'depends', deps)
  220. # shlibs requires any DEPENDS to have already packaged for the *.list files
  221. d.appendVarFlag('do_package', 'deptask', " do_packagedata")
  222. }
  223. # Get a list of files from file vars by searching files under current working directory
  224. # The list contains symlinks, directories and normal files.
  225. def files_from_filevars(filevars):
  226. import os,glob
  227. cpath = oe.cachedpath.CachedPath()
  228. files = []
  229. for f in filevars:
  230. if os.path.isabs(f):
  231. f = '.' + f
  232. if not f.startswith("./"):
  233. f = './' + f
  234. globbed = glob.glob(f)
  235. if globbed:
  236. if [ f ] != globbed:
  237. files += globbed
  238. continue
  239. files.append(f)
  240. symlink_paths = []
  241. for ind, f in enumerate(files):
  242. # Handle directory symlinks. Truncate path to the lowest level symlink
  243. parent = ''
  244. for dirname in f.split('/')[:-1]:
  245. parent = os.path.join(parent, dirname)
  246. if dirname == '.':
  247. continue
  248. if cpath.islink(parent):
  249. bb.warn("FILES contains file '%s' which resides under a "
  250. "directory symlink. Please fix the recipe and use the "
  251. "real path for the file." % f[1:])
  252. symlink_paths.append(f)
  253. files[ind] = parent
  254. f = parent
  255. break
  256. if not cpath.islink(f):
  257. if cpath.isdir(f):
  258. newfiles = [ os.path.join(f,x) for x in os.listdir(f) ]
  259. if newfiles:
  260. files += newfiles
  261. return files, symlink_paths
  262. # Called in package_<rpm,ipk,deb>.bbclass to get the correct list of configuration files
  263. def get_conffiles(pkg, d):
  264. pkgdest = d.getVar('PKGDEST')
  265. root = os.path.join(pkgdest, pkg)
  266. cwd = os.getcwd()
  267. os.chdir(root)
  268. conffiles = d.getVar('CONFFILES_%s' % pkg);
  269. if conffiles == None:
  270. conffiles = d.getVar('CONFFILES')
  271. if conffiles == None:
  272. conffiles = ""
  273. conffiles = conffiles.split()
  274. conf_orig_list = files_from_filevars(conffiles)[0]
  275. # Remove links and directories from conf_orig_list to get conf_list which only contains normal files
  276. conf_list = []
  277. for f in conf_orig_list:
  278. if os.path.isdir(f):
  279. continue
  280. if os.path.islink(f):
  281. continue
  282. if not os.path.exists(f):
  283. continue
  284. conf_list.append(f)
  285. # Remove the leading './'
  286. for i in range(0, len(conf_list)):
  287. conf_list[i] = conf_list[i][1:]
  288. os.chdir(cwd)
  289. return conf_list
  290. def checkbuildpath(file, d):
  291. tmpdir = d.getVar('TMPDIR')
  292. with open(file) as f:
  293. file_content = f.read()
  294. if tmpdir in file_content:
  295. return True
  296. return False
  297. def parse_debugsources_from_dwarfsrcfiles_output(dwarfsrcfiles_output):
  298. debugfiles = {}
  299. for line in dwarfsrcfiles_output.splitlines():
  300. if line.startswith("\t"):
  301. debugfiles[os.path.normpath(line.split()[0])] = ""
  302. return debugfiles.keys()
  303. def source_info(file, d, fatal=True):
  304. import subprocess
  305. cmd = ["dwarfsrcfiles", file]
  306. try:
  307. output = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT)
  308. retval = 0
  309. except subprocess.CalledProcessError as exc:
  310. output = exc.output
  311. retval = exc.returncode
  312. # 255 means a specific file wasn't fully parsed to get the debug file list, which is not a fatal failure
  313. if retval != 0 and retval != 255:
  314. msg = "dwarfsrcfiles failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")
  315. if fatal:
  316. bb.fatal(msg)
  317. bb.note(msg)
  318. debugsources = parse_debugsources_from_dwarfsrcfiles_output(output)
  319. return list(debugsources)
  320. def splitdebuginfo(file, dvar, debugdir, debuglibdir, debugappend, debugsrcdir, d):
  321. # Function to split a single file into two components, one is the stripped
  322. # target system binary, the other contains any debugging information. The
  323. # two files are linked to reference each other.
  324. #
  325. # return a mapping of files:debugsources
  326. import stat
  327. import subprocess
  328. src = file[len(dvar):]
  329. dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend
  330. debugfile = dvar + dest
  331. sources = []
  332. # Split the file...
  333. bb.utils.mkdirhier(os.path.dirname(debugfile))
  334. #bb.note("Split %s -> %s" % (file, debugfile))
  335. # Only store off the hard link reference if we successfully split!
  336. dvar = d.getVar('PKGD')
  337. objcopy = d.getVar("OBJCOPY")
  338. # We ignore kernel modules, we don't generate debug info files.
  339. if file.find("/lib/modules/") != -1 and file.endswith(".ko"):
  340. return (file, sources)
  341. newmode = None
  342. if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
  343. origmode = os.stat(file)[stat.ST_MODE]
  344. newmode = origmode | stat.S_IWRITE | stat.S_IREAD
  345. os.chmod(file, newmode)
  346. # We need to extract the debug src information here...
  347. if debugsrcdir:
  348. sources = source_info(file, d)
  349. bb.utils.mkdirhier(os.path.dirname(debugfile))
  350. subprocess.check_output([objcopy, '--only-keep-debug', file, debugfile], stderr=subprocess.STDOUT)
  351. # Set the debuglink to have the view of the file path on the target
  352. subprocess.check_output([objcopy, '--add-gnu-debuglink', debugfile, file], stderr=subprocess.STDOUT)
  353. if newmode:
  354. os.chmod(file, origmode)
  355. return (file, sources)
  356. def copydebugsources(debugsrcdir, sources, d):
  357. # The debug src information written out to sourcefile is further processed
  358. # and copied to the destination here.
  359. import stat
  360. import subprocess
  361. if debugsrcdir and sources:
  362. sourcefile = d.expand("${WORKDIR}/debugsources.list")
  363. bb.utils.remove(sourcefile)
  364. # filenames are null-separated - this is an artefact of the previous use
  365. # of rpm's debugedit, which was writing them out that way, and the code elsewhere
  366. # is still assuming that.
  367. debuglistoutput = '\0'.join(sources) + '\0'
  368. with open(sourcefile, 'a') as sf:
  369. sf.write(debuglistoutput)
  370. dvar = d.getVar('PKGD')
  371. strip = d.getVar("STRIP")
  372. objcopy = d.getVar("OBJCOPY")
  373. workdir = d.getVar("WORKDIR")
  374. workparentdir = os.path.dirname(os.path.dirname(workdir))
  375. workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir)
  376. # If build path exists in sourcefile, it means toolchain did not use
  377. # -fdebug-prefix-map to compile
  378. if checkbuildpath(sourcefile, d):
  379. localsrc_prefix = workparentdir + "/"
  380. else:
  381. localsrc_prefix = "/usr/src/debug/"
  382. nosuchdir = []
  383. basepath = dvar
  384. for p in debugsrcdir.split("/"):
  385. basepath = basepath + "/" + p
  386. if not cpath.exists(basepath):
  387. nosuchdir.append(basepath)
  388. bb.utils.mkdirhier(basepath)
  389. cpath.updatecache(basepath)
  390. # Ignore files from the recipe sysroots (target and native)
  391. processdebugsrc = "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | "
  392. # We need to ignore files that are not actually ours
  393. # we do this by only paying attention to items from this package
  394. processdebugsrc += "fgrep -zw '%s' | "
  395. # Remove prefix in the source paths
  396. processdebugsrc += "sed 's#%s##g' | "
  397. processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)"
  398. cmd = processdebugsrc % (sourcefile, workbasedir, localsrc_prefix, workparentdir, dvar, debugsrcdir)
  399. try:
  400. subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
  401. except subprocess.CalledProcessError:
  402. # Can "fail" if internal headers/transient sources are attempted
  403. pass
  404. # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
  405. # Work around this by manually finding and copying any symbolic links that made it through.
  406. cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
  407. (dvar, debugsrcdir, dvar, debugsrcdir, workparentdir, dvar, debugsrcdir)
  408. subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
  409. # The copy by cpio may have resulted in some empty directories! Remove these
  410. cmd = "find %s%s -empty -type d -delete" % (dvar, debugsrcdir)
  411. subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
  412. # Also remove debugsrcdir if its empty
  413. for p in nosuchdir[::-1]:
  414. if os.path.exists(p) and not os.listdir(p):
  415. os.rmdir(p)
  416. #
  417. # Package data handling routines
  418. #
  419. def get_package_mapping (pkg, basepkg, d):
  420. import oe.packagedata
  421. data = oe.packagedata.read_subpkgdata(pkg, d)
  422. key = "PKG_%s" % pkg
  423. if key in data:
  424. # Have to avoid undoing the write_extra_pkgs(global_variants...)
  425. if bb.data.inherits_class('allarch', d) and not d.getVar('MULTILIB_VARIANTS') \
  426. and data[key] == basepkg:
  427. return pkg
  428. return data[key]
  429. return pkg
  430. def get_package_additional_metadata (pkg_type, d):
  431. base_key = "PACKAGE_ADD_METADATA"
  432. for key in ("%s_%s" % (base_key, pkg_type.upper()), base_key):
  433. if d.getVar(key, False) is None:
  434. continue
  435. d.setVarFlag(key, "type", "list")
  436. if d.getVarFlag(key, "separator") is None:
  437. d.setVarFlag(key, "separator", "\\n")
  438. metadata_fields = [field.strip() for field in oe.data.typed_value(key, d)]
  439. return "\n".join(metadata_fields).strip()
  440. def runtime_mapping_rename (varname, pkg, d):
  441. #bb.note("%s before: %s" % (varname, d.getVar(varname)))
  442. new_depends = {}
  443. deps = bb.utils.explode_dep_versions2(d.getVar(varname) or "")
  444. for depend in deps:
  445. new_depend = get_package_mapping(depend, pkg, d)
  446. new_depends[new_depend] = deps[depend]
  447. d.setVar(varname, bb.utils.join_deps(new_depends, commasep=False))
  448. #bb.note("%s after: %s" % (varname, d.getVar(varname)))
  449. #
  450. # Package functions suitable for inclusion in PACKAGEFUNCS
  451. #
  452. python package_get_auto_pr() {
  453. import oe.prservice
  454. import re
  455. # Support per recipe PRSERV_HOST
  456. pn = d.getVar('PN')
  457. host = d.getVar("PRSERV_HOST_" + pn)
  458. if not (host is None):
  459. d.setVar("PRSERV_HOST", host)
  460. pkgv = d.getVar("PKGV")
  461. # PR Server not active, handle AUTOINC
  462. if not d.getVar('PRSERV_HOST'):
  463. if 'AUTOINC' in pkgv:
  464. d.setVar("PKGV", pkgv.replace("AUTOINC", "0"))
  465. return
  466. auto_pr = None
  467. pv = d.getVar("PV")
  468. version = d.getVar("PRAUTOINX")
  469. pkgarch = d.getVar("PACKAGE_ARCH")
  470. checksum = d.getVar("BB_TASKHASH")
  471. if d.getVar('PRSERV_LOCKDOWN'):
  472. auto_pr = d.getVar('PRAUTO_' + version + '_' + pkgarch) or d.getVar('PRAUTO_' + version) or None
  473. if auto_pr is None:
  474. bb.fatal("Can NOT get PRAUTO from lockdown exported file")
  475. d.setVar('PRAUTO',str(auto_pr))
  476. return
  477. try:
  478. conn = d.getVar("__PRSERV_CONN")
  479. if conn is None:
  480. conn = oe.prservice.prserv_make_conn(d)
  481. if conn is not None:
  482. if "AUTOINC" in pkgv:
  483. srcpv = bb.fetch2.get_srcrev(d)
  484. base_ver = "AUTOINC-%s" % version[:version.find(srcpv)]
  485. value = conn.getPR(base_ver, pkgarch, srcpv)
  486. d.setVar("PKGV", pkgv.replace("AUTOINC", str(value)))
  487. auto_pr = conn.getPR(version, pkgarch, checksum)
  488. except Exception as e:
  489. bb.fatal("Can NOT get PRAUTO, exception %s" % str(e))
  490. if auto_pr is None:
  491. bb.fatal("Can NOT get PRAUTO from remote PR service")
  492. d.setVar('PRAUTO',str(auto_pr))
  493. }
  494. LOCALEBASEPN ??= "${PN}"
  495. python package_do_split_locales() {
  496. if (d.getVar('PACKAGE_NO_LOCALE') == '1'):
  497. bb.debug(1, "package requested not splitting locales")
  498. return
  499. packages = (d.getVar('PACKAGES') or "").split()
  500. datadir = d.getVar('datadir')
  501. if not datadir:
  502. bb.note("datadir not defined")
  503. return
  504. dvar = d.getVar('PKGD')
  505. pn = d.getVar('LOCALEBASEPN')
  506. if pn + '-locale' in packages:
  507. packages.remove(pn + '-locale')
  508. localedir = os.path.join(dvar + datadir, 'locale')
  509. if not cpath.isdir(localedir):
  510. bb.debug(1, "No locale files in this package")
  511. return
  512. locales = os.listdir(localedir)
  513. summary = d.getVar('SUMMARY') or pn
  514. description = d.getVar('DESCRIPTION') or ""
  515. locale_section = d.getVar('LOCALE_SECTION')
  516. mlprefix = d.getVar('MLPREFIX') or ""
  517. for l in sorted(locales):
  518. ln = legitimize_package_name(l)
  519. pkg = pn + '-locale-' + ln
  520. packages.append(pkg)
  521. d.setVar('FILES_' + pkg, os.path.join(datadir, 'locale', l))
  522. d.setVar('RRECOMMENDS_' + pkg, '%svirtual-locale-%s' % (mlprefix, ln))
  523. d.setVar('RPROVIDES_' + pkg, '%s-locale %s%s-translation' % (pn, mlprefix, ln))
  524. d.setVar('SUMMARY_' + pkg, '%s - %s translations' % (summary, l))
  525. d.setVar('DESCRIPTION_' + pkg, '%s This package contains language translation files for the %s locale.' % (description, l))
  526. if locale_section:
  527. d.setVar('SECTION_' + pkg, locale_section)
  528. d.setVar('PACKAGES', ' '.join(packages))
  529. # Disabled by RP 18/06/07
  530. # Wildcards aren't supported in debian
  531. # They break with ipkg since glibc-locale* will mean that
  532. # glibc-localedata-translit* won't install as a dependency
  533. # for some other package which breaks meta-toolchain
  534. # Probably breaks since virtual-locale- isn't provided anywhere
  535. #rdep = (d.getVar('RDEPENDS_%s' % pn) or "").split()
  536. #rdep.append('%s-locale*' % pn)
  537. #d.setVar('RDEPENDS_%s' % pn, ' '.join(rdep))
  538. }
  539. python perform_packagecopy () {
  540. import subprocess
  541. dest = d.getVar('D')
  542. dvar = d.getVar('PKGD')
  543. # Start by package population by taking a copy of the installed
  544. # files to operate on
  545. # Preserve sparse files and hard links
  546. cmd = 'tar -cf - -C %s -p -S . | tar -xf - -C %s' % (dest, dvar)
  547. subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
  548. # replace RPATHs for the nativesdk binaries, to make them relocatable
  549. if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d):
  550. rpath_replace (dvar, d)
  551. }
  552. perform_packagecopy[cleandirs] = "${PKGD}"
  553. perform_packagecopy[dirs] = "${PKGD}"
  554. # We generate a master list of directories to process, we start by
  555. # seeding this list with reasonable defaults, then load from
  556. # the fs-perms.txt files
  557. python fixup_perms () {
  558. import pwd, grp
  559. # init using a string with the same format as a line as documented in
  560. # the fs-perms.txt file
  561. # <path> <mode> <uid> <gid> <walk> <fmode> <fuid> <fgid>
  562. # <path> link <link target>
  563. #
  564. # __str__ can be used to print out an entry in the input format
  565. #
  566. # if fs_perms_entry.path is None:
  567. # an error occurred
  568. # if fs_perms_entry.link, you can retrieve:
  569. # fs_perms_entry.path = path
  570. # fs_perms_entry.link = target of link
  571. # if not fs_perms_entry.link, you can retrieve:
  572. # fs_perms_entry.path = path
  573. # fs_perms_entry.mode = expected dir mode or None
  574. # fs_perms_entry.uid = expected uid or -1
  575. # fs_perms_entry.gid = expected gid or -1
  576. # fs_perms_entry.walk = 'true' or something else
  577. # fs_perms_entry.fmode = expected file mode or None
  578. # fs_perms_entry.fuid = expected file uid or -1
  579. # fs_perms_entry_fgid = expected file gid or -1
  580. class fs_perms_entry():
  581. def __init__(self, line):
  582. lsplit = line.split()
  583. if len(lsplit) == 3 and lsplit[1].lower() == "link":
  584. self._setlink(lsplit[0], lsplit[2])
  585. elif len(lsplit) == 8:
  586. self._setdir(lsplit[0], lsplit[1], lsplit[2], lsplit[3], lsplit[4], lsplit[5], lsplit[6], lsplit[7])
  587. else:
  588. msg = "Fixup Perms: invalid config line %s" % line
  589. package_qa_handle_error("perm-config", msg, d)
  590. self.path = None
  591. self.link = None
  592. def _setdir(self, path, mode, uid, gid, walk, fmode, fuid, fgid):
  593. self.path = os.path.normpath(path)
  594. self.link = None
  595. self.mode = self._procmode(mode)
  596. self.uid = self._procuid(uid)
  597. self.gid = self._procgid(gid)
  598. self.walk = walk.lower()
  599. self.fmode = self._procmode(fmode)
  600. self.fuid = self._procuid(fuid)
  601. self.fgid = self._procgid(fgid)
  602. def _setlink(self, path, link):
  603. self.path = os.path.normpath(path)
  604. self.link = link
  605. def _procmode(self, mode):
  606. if not mode or (mode and mode == "-"):
  607. return None
  608. else:
  609. return int(mode,8)
  610. # Note uid/gid -1 has special significance in os.lchown
  611. def _procuid(self, uid):
  612. if uid is None or uid == "-":
  613. return -1
  614. elif uid.isdigit():
  615. return int(uid)
  616. else:
  617. return pwd.getpwnam(uid).pw_uid
  618. def _procgid(self, gid):
  619. if gid is None or gid == "-":
  620. return -1
  621. elif gid.isdigit():
  622. return int(gid)
  623. else:
  624. return grp.getgrnam(gid).gr_gid
  625. # Use for debugging the entries
  626. def __str__(self):
  627. if self.link:
  628. return "%s link %s" % (self.path, self.link)
  629. else:
  630. mode = "-"
  631. if self.mode:
  632. mode = "0%o" % self.mode
  633. fmode = "-"
  634. if self.fmode:
  635. fmode = "0%o" % self.fmode
  636. uid = self._mapugid(self.uid)
  637. gid = self._mapugid(self.gid)
  638. fuid = self._mapugid(self.fuid)
  639. fgid = self._mapugid(self.fgid)
  640. return "%s %s %s %s %s %s %s %s" % (self.path, mode, uid, gid, self.walk, fmode, fuid, fgid)
  641. def _mapugid(self, id):
  642. if id is None or id == -1:
  643. return "-"
  644. else:
  645. return "%d" % id
  646. # Fix the permission, owner and group of path
  647. def fix_perms(path, mode, uid, gid, dir):
  648. if mode and not os.path.islink(path):
  649. #bb.note("Fixup Perms: chmod 0%o %s" % (mode, dir))
  650. os.chmod(path, mode)
  651. # -1 is a special value that means don't change the uid/gid
  652. # if they are BOTH -1, don't bother to lchown
  653. if not (uid == -1 and gid == -1):
  654. #bb.note("Fixup Perms: lchown %d:%d %s" % (uid, gid, dir))
  655. os.lchown(path, uid, gid)
  656. # Return a list of configuration files based on either the default
  657. # files/fs-perms.txt or the contents of FILESYSTEM_PERMS_TABLES
  658. # paths are resolved via BBPATH
  659. def get_fs_perms_list(d):
  660. str = ""
  661. bbpath = d.getVar('BBPATH')
  662. fs_perms_tables = d.getVar('FILESYSTEM_PERMS_TABLES') or ""
  663. for conf_file in fs_perms_tables.split():
  664. confpath = bb.utils.which(bbpath, conf_file)
  665. if confpath:
  666. str += " %s" % bb.utils.which(bbpath, conf_file)
  667. else:
  668. bb.warn("cannot find %s specified in FILESYSTEM_PERMS_TABLES" % conf_file)
  669. return str
  670. dvar = d.getVar('PKGD')
  671. fs_perms_table = {}
  672. fs_link_table = {}
  673. # By default all of the standard directories specified in
  674. # bitbake.conf will get 0755 root:root.
  675. target_path_vars = [ 'base_prefix',
  676. 'prefix',
  677. 'exec_prefix',
  678. 'base_bindir',
  679. 'base_sbindir',
  680. 'base_libdir',
  681. 'datadir',
  682. 'sysconfdir',
  683. 'servicedir',
  684. 'sharedstatedir',
  685. 'localstatedir',
  686. 'infodir',
  687. 'mandir',
  688. 'docdir',
  689. 'bindir',
  690. 'sbindir',
  691. 'libexecdir',
  692. 'libdir',
  693. 'includedir',
  694. 'oldincludedir' ]
  695. for path in target_path_vars:
  696. dir = d.getVar(path) or ""
  697. if dir == "":
  698. continue
  699. fs_perms_table[dir] = fs_perms_entry(d.expand("%s 0755 root root false - - -" % (dir)))
  700. # Now we actually load from the configuration files
  701. for conf in get_fs_perms_list(d).split():
  702. if os.path.exists(conf):
  703. f = open(conf)
  704. for line in f:
  705. if line.startswith('#'):
  706. continue
  707. lsplit = line.split()
  708. if len(lsplit) == 0:
  709. continue
  710. if len(lsplit) != 8 and not (len(lsplit) == 3 and lsplit[1].lower() == "link"):
  711. msg = "Fixup perms: %s invalid line: %s" % (conf, line)
  712. package_qa_handle_error("perm-line", msg, d)
  713. continue
  714. entry = fs_perms_entry(d.expand(line))
  715. if entry and entry.path:
  716. if entry.link:
  717. fs_link_table[entry.path] = entry
  718. if entry.path in fs_perms_table:
  719. fs_perms_table.pop(entry.path)
  720. else:
  721. fs_perms_table[entry.path] = entry
  722. if entry.path in fs_link_table:
  723. fs_link_table.pop(entry.path)
  724. f.close()
  725. # Debug -- list out in-memory table
  726. #for dir in fs_perms_table:
  727. # bb.note("Fixup Perms: %s: %s" % (dir, str(fs_perms_table[dir])))
  728. #for link in fs_link_table:
  729. # bb.note("Fixup Perms: %s: %s" % (link, str(fs_link_table[link])))
  730. # We process links first, so we can go back and fixup directory ownership
  731. # for any newly created directories
  732. # Process in sorted order so /run gets created before /run/lock, etc.
  733. for entry in sorted(fs_link_table.values(), key=lambda x: x.link):
  734. link = entry.link
  735. dir = entry.path
  736. origin = dvar + dir
  737. if not (cpath.exists(origin) and cpath.isdir(origin) and not cpath.islink(origin)):
  738. continue
  739. if link[0] == "/":
  740. target = dvar + link
  741. ptarget = link
  742. else:
  743. target = os.path.join(os.path.dirname(origin), link)
  744. ptarget = os.path.join(os.path.dirname(dir), link)
  745. if os.path.exists(target):
  746. msg = "Fixup Perms: Unable to correct directory link, target already exists: %s -> %s" % (dir, ptarget)
  747. package_qa_handle_error("perm-link", msg, d)
  748. continue
  749. # Create path to move directory to, move it, and then setup the symlink
  750. bb.utils.mkdirhier(os.path.dirname(target))
  751. #bb.note("Fixup Perms: Rename %s -> %s" % (dir, ptarget))
  752. os.rename(origin, target)
  753. #bb.note("Fixup Perms: Link %s -> %s" % (dir, link))
  754. os.symlink(link, origin)
  755. for dir in fs_perms_table:
  756. origin = dvar + dir
  757. if not (cpath.exists(origin) and cpath.isdir(origin)):
  758. continue
  759. fix_perms(origin, fs_perms_table[dir].mode, fs_perms_table[dir].uid, fs_perms_table[dir].gid, dir)
  760. if fs_perms_table[dir].walk == 'true':
  761. for root, dirs, files in os.walk(origin):
  762. for dr in dirs:
  763. each_dir = os.path.join(root, dr)
  764. fix_perms(each_dir, fs_perms_table[dir].mode, fs_perms_table[dir].uid, fs_perms_table[dir].gid, dir)
  765. for f in files:
  766. each_file = os.path.join(root, f)
  767. fix_perms(each_file, fs_perms_table[dir].fmode, fs_perms_table[dir].fuid, fs_perms_table[dir].fgid, dir)
  768. }
  769. python split_and_strip_files () {
  770. import stat, errno
  771. import subprocess
  772. dvar = d.getVar('PKGD')
  773. pn = d.getVar('PN')
  774. targetos = d.getVar('TARGET_OS')
  775. oldcwd = os.getcwd()
  776. os.chdir(dvar)
  777. # We default to '.debug' style
  778. if d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-file-directory':
  779. # Single debug-file-directory style debug info
  780. debugappend = ".debug"
  781. debugdir = ""
  782. debuglibdir = "/usr/lib/debug"
  783. debugsrcdir = "/usr/src/debug"
  784. elif d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-without-src':
  785. # Original OE-core, a.k.a. ".debug", style debug info, but without sources in /usr/src/debug
  786. debugappend = ""
  787. debugdir = "/.debug"
  788. debuglibdir = ""
  789. debugsrcdir = ""
  790. elif d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-with-srcpkg':
  791. debugappend = ""
  792. debugdir = "/.debug"
  793. debuglibdir = ""
  794. debugsrcdir = "/usr/src/debug"
  795. else:
  796. # Original OE-core, a.k.a. ".debug", style debug info
  797. debugappend = ""
  798. debugdir = "/.debug"
  799. debuglibdir = ""
  800. debugsrcdir = "/usr/src/debug"
  801. #
  802. # First lets figure out all of the files we may have to process ... do this only once!
  803. #
  804. elffiles = {}
  805. symlinks = {}
  806. kernmods = []
  807. staticlibs = []
  808. inodes = {}
  809. libdir = os.path.abspath(dvar + os.sep + d.getVar("libdir"))
  810. baselibdir = os.path.abspath(dvar + os.sep + d.getVar("base_libdir"))
  811. skipfiles = (d.getVar("INHIBIT_PACKAGE_STRIP_FILES") or "").split()
  812. if (d.getVar('INHIBIT_PACKAGE_STRIP') != '1' or \
  813. d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'):
  814. checkelf = {}
  815. checkelflinks = {}
  816. for root, dirs, files in cpath.walk(dvar):
  817. for f in files:
  818. file = os.path.join(root, f)
  819. if file.endswith(".ko") and file.find("/lib/modules/") != -1:
  820. kernmods.append(file)
  821. continue
  822. if oe.package.is_static_lib(file):
  823. staticlibs.append(file)
  824. continue
  825. # Skip debug files
  826. if debugappend and file.endswith(debugappend):
  827. continue
  828. if debugdir and debugdir in os.path.dirname(file[len(dvar):]):
  829. continue
  830. if file in skipfiles:
  831. continue
  832. try:
  833. ltarget = cpath.realpath(file, dvar, False)
  834. s = cpath.lstat(ltarget)
  835. except OSError as e:
  836. (err, strerror) = e.args
  837. if err != errno.ENOENT:
  838. raise
  839. # Skip broken symlinks
  840. continue
  841. if not s:
  842. continue
  843. # Check its an executable
  844. if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \
  845. or ((file.startswith(libdir) or file.startswith(baselibdir)) and (".so" in f or ".node" in f)):
  846. if cpath.islink(file):
  847. checkelflinks[file] = ltarget
  848. continue
  849. # Use a reference of device ID and inode number to identify files
  850. file_reference = "%d_%d" % (s.st_dev, s.st_ino)
  851. checkelf[file] = (file, file_reference)
  852. results = oe.utils.multiprocess_launch(oe.package.is_elf, checkelflinks.values(), d)
  853. results_map = {}
  854. for (ltarget, elf_file) in results:
  855. results_map[ltarget] = elf_file
  856. for file in checkelflinks:
  857. ltarget = checkelflinks[file]
  858. # If it's a symlink, and points to an ELF file, we capture the readlink target
  859. if results_map[ltarget]:
  860. target = os.readlink(file)
  861. #bb.note("Sym: %s (%d)" % (ltarget, results_map[ltarget]))
  862. symlinks[file] = target
  863. results = oe.utils.multiprocess_launch(oe.package.is_elf, checkelf.keys(), d)
  864. # Sort results by file path. This ensures that the files are always
  865. # processed in the same order, which is important to make sure builds
  866. # are reproducible when dealing with hardlinks
  867. results.sort(key=lambda x: x[0])
  868. for (file, elf_file) in results:
  869. # It's a file (or hardlink), not a link
  870. # ...but is it ELF, and is it already stripped?
  871. if elf_file & 1:
  872. if elf_file & 2:
  873. if 'already-stripped' in (d.getVar('INSANE_SKIP_' + pn) or "").split():
  874. bb.note("Skipping file %s from %s for already-stripped QA test" % (file[len(dvar):], pn))
  875. else:
  876. msg = "File '%s' from %s was already stripped, this will prevent future debugging!" % (file[len(dvar):], pn)
  877. package_qa_handle_error("already-stripped", msg, d)
  878. continue
  879. # At this point we have an unstripped elf file. We need to:
  880. # a) Make sure any file we strip is not hardlinked to anything else outside this tree
  881. # b) Only strip any hardlinked file once (no races)
  882. # c) Track any hardlinks between files so that we can reconstruct matching debug file hardlinks
  883. # Use a reference of device ID and inode number to identify files
  884. file_reference = checkelf[file][1]
  885. if file_reference in inodes:
  886. os.unlink(file)
  887. os.link(inodes[file_reference][0], file)
  888. inodes[file_reference].append(file)
  889. else:
  890. inodes[file_reference] = [file]
  891. # break hardlink
  892. bb.utils.break_hardlinks(file)
  893. elffiles[file] = elf_file
  894. # Modified the file so clear the cache
  895. cpath.updatecache(file)
  896. #
  897. # First lets process debug splitting
  898. #
  899. if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'):
  900. results = oe.utils.multiprocess_launch(splitdebuginfo, list(elffiles), d, extraargs=(dvar, debugdir, debuglibdir, debugappend, debugsrcdir, d))
  901. if debugsrcdir and not targetos.startswith("mingw"):
  902. for file in staticlibs:
  903. results.extend(source_info(file, d, fatal=False))
  904. sources = set()
  905. for r in results:
  906. sources.update(r[1])
  907. # Hardlink our debug symbols to the other hardlink copies
  908. for ref in inodes:
  909. if len(inodes[ref]) == 1:
  910. continue
  911. target = inodes[ref][0][len(dvar):]
  912. for file in inodes[ref][1:]:
  913. src = file[len(dvar):]
  914. dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(target) + debugappend
  915. fpath = dvar + dest
  916. ftarget = dvar + debuglibdir + os.path.dirname(target) + debugdir + "/" + os.path.basename(target) + debugappend
  917. bb.utils.mkdirhier(os.path.dirname(fpath))
  918. # Only one hardlink of separated debug info file in each directory
  919. if not os.access(fpath, os.R_OK):
  920. #bb.note("Link %s -> %s" % (fpath, ftarget))
  921. os.link(ftarget, fpath)
  922. # Create symlinks for all cases we were able to split symbols
  923. for file in symlinks:
  924. src = file[len(dvar):]
  925. dest = debuglibdir + os.path.dirname(src) + debugdir + "/" + os.path.basename(src) + debugappend
  926. fpath = dvar + dest
  927. # Skip it if the target doesn't exist
  928. try:
  929. s = os.stat(fpath)
  930. except OSError as e:
  931. (err, strerror) = e.args
  932. if err != errno.ENOENT:
  933. raise
  934. continue
  935. ltarget = symlinks[file]
  936. lpath = os.path.dirname(ltarget)
  937. lbase = os.path.basename(ltarget)
  938. ftarget = ""
  939. if lpath and lpath != ".":
  940. ftarget += lpath + debugdir + "/"
  941. ftarget += lbase + debugappend
  942. if lpath.startswith(".."):
  943. ftarget = os.path.join("..", ftarget)
  944. bb.utils.mkdirhier(os.path.dirname(fpath))
  945. #bb.note("Symlink %s -> %s" % (fpath, ftarget))
  946. os.symlink(ftarget, fpath)
  947. # Process the debugsrcdir if requested...
  948. # This copies and places the referenced sources for later debugging...
  949. copydebugsources(debugsrcdir, sources, d)
  950. #
  951. # End of debug splitting
  952. #
  953. #
  954. # Now lets go back over things and strip them
  955. #
  956. if (d.getVar('INHIBIT_PACKAGE_STRIP') != '1'):
  957. strip = d.getVar("STRIP")
  958. sfiles = []
  959. for file in elffiles:
  960. elf_file = int(elffiles[file])
  961. #bb.note("Strip %s" % file)
  962. sfiles.append((file, elf_file, strip))
  963. for f in kernmods:
  964. sfiles.append((f, 16, strip))
  965. oe.utils.multiprocess_launch(oe.package.runstrip, sfiles, d)
  966. #
  967. # End of strip
  968. #
  969. os.chdir(oldcwd)
  970. }
  971. python populate_packages () {
  972. import glob, re
  973. workdir = d.getVar('WORKDIR')
  974. outdir = d.getVar('DEPLOY_DIR')
  975. dvar = d.getVar('PKGD')
  976. packages = d.getVar('PACKAGES').split()
  977. pn = d.getVar('PN')
  978. bb.utils.mkdirhier(outdir)
  979. os.chdir(dvar)
  980. autodebug = not (d.getVar("NOAUTOPACKAGEDEBUG") or False)
  981. split_source_package = (d.getVar('PACKAGE_DEBUG_SPLIT_STYLE') == 'debug-with-srcpkg')
  982. # If debug-with-srcpkg mode is enabled then add the source package if it
  983. # doesn't exist and add the source file contents to the source package.
  984. if split_source_package:
  985. src_package_name = ('%s-src' % d.getVar('PN'))
  986. if not src_package_name in packages:
  987. packages.append(src_package_name)
  988. d.setVar('FILES_%s' % src_package_name, '/usr/src/debug')
  989. # Sanity check PACKAGES for duplicates
  990. # Sanity should be moved to sanity.bbclass once we have the infrastructure
  991. package_dict = {}
  992. for i, pkg in enumerate(packages):
  993. if pkg in package_dict:
  994. msg = "%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg
  995. package_qa_handle_error("packages-list", msg, d)
  996. # Ensure the source package gets the chance to pick up the source files
  997. # before the debug package by ordering it first in PACKAGES. Whether it
  998. # actually picks up any source files is controlled by
  999. # PACKAGE_DEBUG_SPLIT_STYLE.
  1000. elif pkg.endswith("-src"):
  1001. package_dict[pkg] = (10, i)
  1002. elif autodebug and pkg.endswith("-dbg"):
  1003. package_dict[pkg] = (30, i)
  1004. else:
  1005. package_dict[pkg] = (50, i)
  1006. packages = sorted(package_dict.keys(), key=package_dict.get)
  1007. d.setVar('PACKAGES', ' '.join(packages))
  1008. pkgdest = d.getVar('PKGDEST')
  1009. seen = []
  1010. # os.mkdir masks the permissions with umask so we have to unset it first
  1011. oldumask = os.umask(0)
  1012. debug = []
  1013. for root, dirs, files in cpath.walk(dvar):
  1014. dir = root[len(dvar):]
  1015. if not dir:
  1016. dir = os.sep
  1017. for f in (files + dirs):
  1018. path = "." + os.path.join(dir, f)
  1019. if "/.debug/" in path or path.endswith("/.debug"):
  1020. debug.append(path)
  1021. for pkg in packages:
  1022. root = os.path.join(pkgdest, pkg)
  1023. bb.utils.mkdirhier(root)
  1024. filesvar = d.getVar('FILES_%s' % pkg) or ""
  1025. if "//" in filesvar:
  1026. msg = "FILES variable for package %s contains '//' which is invalid. Attempting to fix this but you should correct the metadata.\n" % pkg
  1027. package_qa_handle_error("files-invalid", msg, d)
  1028. filesvar.replace("//", "/")
  1029. origfiles = filesvar.split()
  1030. files, symlink_paths = files_from_filevars(origfiles)
  1031. if autodebug and pkg.endswith("-dbg"):
  1032. files.extend(debug)
  1033. for file in files:
  1034. if (not cpath.islink(file)) and (not cpath.exists(file)):
  1035. continue
  1036. if file in seen:
  1037. continue
  1038. seen.append(file)
  1039. def mkdir(src, dest, p):
  1040. src = os.path.join(src, p)
  1041. dest = os.path.join(dest, p)
  1042. fstat = cpath.stat(src)
  1043. os.mkdir(dest)
  1044. os.chmod(dest, fstat.st_mode)
  1045. os.chown(dest, fstat.st_uid, fstat.st_gid)
  1046. if p not in seen:
  1047. seen.append(p)
  1048. cpath.updatecache(dest)
  1049. def mkdir_recurse(src, dest, paths):
  1050. if cpath.exists(dest + '/' + paths):
  1051. return
  1052. while paths.startswith("./"):
  1053. paths = paths[2:]
  1054. p = "."
  1055. for c in paths.split("/"):
  1056. p = os.path.join(p, c)
  1057. if not cpath.exists(os.path.join(dest, p)):
  1058. mkdir(src, dest, p)
  1059. if cpath.isdir(file) and not cpath.islink(file):
  1060. mkdir_recurse(dvar, root, file)
  1061. continue
  1062. mkdir_recurse(dvar, root, os.path.dirname(file))
  1063. fpath = os.path.join(root,file)
  1064. if not cpath.islink(file):
  1065. os.link(file, fpath)
  1066. continue
  1067. ret = bb.utils.copyfile(file, fpath)
  1068. if ret is False or ret == 0:
  1069. bb.fatal("File population failed")
  1070. # Check if symlink paths exist
  1071. for file in symlink_paths:
  1072. if not os.path.exists(os.path.join(root,file)):
  1073. bb.fatal("File '%s' cannot be packaged into '%s' because its "
  1074. "parent directory structure does not exist. One of "
  1075. "its parent directories is a symlink whose target "
  1076. "directory is not included in the package." %
  1077. (file, pkg))
  1078. os.umask(oldumask)
  1079. os.chdir(workdir)
  1080. # Handle LICENSE_EXCLUSION
  1081. package_list = []
  1082. for pkg in packages:
  1083. if d.getVar('LICENSE_EXCLUSION-' + pkg):
  1084. msg = "%s has an incompatible license. Excluding from packaging." % pkg
  1085. package_qa_handle_error("incompatible-license", msg, d)
  1086. else:
  1087. package_list.append(pkg)
  1088. d.setVar('PACKAGES', ' '.join(package_list))
  1089. unshipped = []
  1090. for root, dirs, files in cpath.walk(dvar):
  1091. dir = root[len(dvar):]
  1092. if not dir:
  1093. dir = os.sep
  1094. for f in (files + dirs):
  1095. path = os.path.join(dir, f)
  1096. if ('.' + path) not in seen:
  1097. unshipped.append(path)
  1098. if unshipped != []:
  1099. msg = pn + ": Files/directories were installed but not shipped in any package:"
  1100. if "installed-vs-shipped" in (d.getVar('INSANE_SKIP_' + pn) or "").split():
  1101. bb.note("Package %s skipping QA tests: installed-vs-shipped" % pn)
  1102. else:
  1103. for f in unshipped:
  1104. msg = msg + "\n " + f
  1105. msg = msg + "\nPlease set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.\n"
  1106. msg = msg + "%s: %d installed and not shipped files." % (pn, len(unshipped))
  1107. package_qa_handle_error("installed-vs-shipped", msg, d)
  1108. }
  1109. populate_packages[dirs] = "${D}"
  1110. python package_fixsymlinks () {
  1111. import errno
  1112. pkgdest = d.getVar('PKGDEST')
  1113. packages = d.getVar("PACKAGES", False).split()
  1114. dangling_links = {}
  1115. pkg_files = {}
  1116. for pkg in packages:
  1117. dangling_links[pkg] = []
  1118. pkg_files[pkg] = []
  1119. inst_root = os.path.join(pkgdest, pkg)
  1120. for path in pkgfiles[pkg]:
  1121. rpath = path[len(inst_root):]
  1122. pkg_files[pkg].append(rpath)
  1123. rtarget = cpath.realpath(path, inst_root, True, assume_dir = True)
  1124. if not cpath.lexists(rtarget):
  1125. dangling_links[pkg].append(os.path.normpath(rtarget[len(inst_root):]))
  1126. newrdepends = {}
  1127. for pkg in dangling_links:
  1128. for l in dangling_links[pkg]:
  1129. found = False
  1130. bb.debug(1, "%s contains dangling link %s" % (pkg, l))
  1131. for p in packages:
  1132. if l in pkg_files[p]:
  1133. found = True
  1134. bb.debug(1, "target found in %s" % p)
  1135. if p == pkg:
  1136. break
  1137. if pkg not in newrdepends:
  1138. newrdepends[pkg] = []
  1139. newrdepends[pkg].append(p)
  1140. break
  1141. if found == False:
  1142. bb.note("%s contains dangling symlink to %s" % (pkg, l))
  1143. for pkg in newrdepends:
  1144. rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "")
  1145. for p in newrdepends[pkg]:
  1146. if p not in rdepends:
  1147. rdepends[p] = []
  1148. d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
  1149. }
  1150. python package_package_name_hook() {
  1151. """
  1152. A package_name_hook function can be used to rewrite the package names by
  1153. changing PKG. For an example, see debian.bbclass.
  1154. """
  1155. pass
  1156. }
  1157. EXPORT_FUNCTIONS package_name_hook
  1158. PKGDESTWORK = "${WORKDIR}/pkgdata"
  1159. PKGDATA_VARS = "PN PE PV PR PKGE PKGV PKGR LICENSE DESCRIPTION SUMMARY RDEPENDS RPROVIDES RRECOMMENDS RSUGGESTS RREPLACES RCONFLICTS SECTION PKG ALLOW_EMPTY FILES CONFFILES FILES_INFO pkg_postinst pkg_postrm pkg_preinst pkg_prerm"
  1160. python emit_pkgdata() {
  1161. from glob import glob
  1162. import json
  1163. def process_postinst_on_target(pkg, mlprefix):
  1164. defer_fragment = """
  1165. if [ -n "$D" ]; then
  1166. $INTERCEPT_DIR/postinst_intercept delay_to_first_boot %s mlprefix=%s
  1167. exit 0
  1168. fi
  1169. """ % (pkg, mlprefix)
  1170. postinst = d.getVar('pkg_postinst_%s' % pkg)
  1171. postinst_ontarget = d.getVar('pkg_postinst_ontarget_%s' % pkg)
  1172. if postinst_ontarget:
  1173. bb.debug(1, 'adding deferred pkg_postinst_ontarget() to pkg_postinst() for %s' % pkg)
  1174. if not postinst:
  1175. postinst = '#!/bin/sh\n'
  1176. postinst += defer_fragment
  1177. postinst += postinst_ontarget
  1178. d.setVar('pkg_postinst_%s' % pkg, postinst)
  1179. def add_set_e_to_scriptlets(pkg):
  1180. for scriptlet_name in ('pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'):
  1181. scriptlet = d.getVar('%s_%s' % (scriptlet_name, pkg))
  1182. if scriptlet:
  1183. scriptlet_split = scriptlet.split('\n')
  1184. if scriptlet_split[0].startswith("#!"):
  1185. scriptlet = scriptlet_split[0] + "\nset -e\n" + "\n".join(scriptlet_split[1:])
  1186. else:
  1187. scriptlet = "set -e\n" + "\n".join(scriptlet_split[0:])
  1188. d.setVar('%s_%s' % (scriptlet_name, pkg), scriptlet)
  1189. def write_if_exists(f, pkg, var):
  1190. def encode(str):
  1191. import codecs
  1192. c = codecs.getencoder("unicode_escape")
  1193. return c(str)[0].decode("latin1")
  1194. val = d.getVar('%s_%s' % (var, pkg))
  1195. if val:
  1196. f.write('%s_%s: %s\n' % (var, pkg, encode(val)))
  1197. return val
  1198. val = d.getVar('%s' % (var))
  1199. if val:
  1200. f.write('%s: %s\n' % (var, encode(val)))
  1201. return val
  1202. def write_extra_pkgs(variants, pn, packages, pkgdatadir):
  1203. for variant in variants:
  1204. with open("%s/%s-%s" % (pkgdatadir, variant, pn), 'w') as fd:
  1205. fd.write("PACKAGES: %s\n" % ' '.join(
  1206. map(lambda pkg: '%s-%s' % (variant, pkg), packages.split())))
  1207. def write_extra_runtime_pkgs(variants, packages, pkgdatadir):
  1208. for variant in variants:
  1209. for pkg in packages.split():
  1210. ml_pkg = "%s-%s" % (variant, pkg)
  1211. subdata_file = "%s/runtime/%s" % (pkgdatadir, ml_pkg)
  1212. with open(subdata_file, 'w') as fd:
  1213. fd.write("PKG_%s: %s" % (ml_pkg, pkg))
  1214. packages = d.getVar('PACKAGES')
  1215. pkgdest = d.getVar('PKGDEST')
  1216. pkgdatadir = d.getVar('PKGDESTWORK')
  1217. data_file = pkgdatadir + d.expand("/${PN}" )
  1218. f = open(data_file, 'w')
  1219. f.write("PACKAGES: %s\n" % packages)
  1220. f.close()
  1221. pn = d.getVar('PN')
  1222. global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split()
  1223. variants = (d.getVar('MULTILIB_VARIANTS') or "").split()
  1224. if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d):
  1225. write_extra_pkgs(variants, pn, packages, pkgdatadir)
  1226. if bb.data.inherits_class('allarch', d) and not variants \
  1227. and not bb.data.inherits_class('packagegroup', d):
  1228. write_extra_pkgs(global_variants, pn, packages, pkgdatadir)
  1229. workdir = d.getVar('WORKDIR')
  1230. for pkg in packages.split():
  1231. pkgval = d.getVar('PKG_%s' % pkg)
  1232. if pkgval is None:
  1233. pkgval = pkg
  1234. d.setVar('PKG_%s' % pkg, pkg)
  1235. pkgdestpkg = os.path.join(pkgdest, pkg)
  1236. files = {}
  1237. total_size = 0
  1238. seen = set()
  1239. for f in pkgfiles[pkg]:
  1240. relpth = os.path.relpath(f, pkgdestpkg)
  1241. fstat = os.lstat(f)
  1242. files[os.sep + relpth] = fstat.st_size
  1243. if fstat.st_ino not in seen:
  1244. seen.add(fstat.st_ino)
  1245. total_size += fstat.st_size
  1246. d.setVar('FILES_INFO', json.dumps(files, sort_keys=True))
  1247. process_postinst_on_target(pkg, d.getVar("MLPREFIX"))
  1248. add_set_e_to_scriptlets(pkg)
  1249. subdata_file = pkgdatadir + "/runtime/%s" % pkg
  1250. with open(subdata_file, 'w') as sf:
  1251. for var in (d.getVar('PKGDATA_VARS') or "").split():
  1252. val = write_if_exists(sf, pkg, var)
  1253. write_if_exists(sf, pkg, 'FILERPROVIDESFLIST')
  1254. for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split():
  1255. write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile)
  1256. write_if_exists(sf, pkg, 'FILERDEPENDSFLIST')
  1257. for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split():
  1258. write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile)
  1259. sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size))
  1260. # Symlinks needed for rprovides lookup
  1261. rprov = d.getVar('RPROVIDES_%s' % pkg) or d.getVar('RPROVIDES')
  1262. if rprov:
  1263. for p in rprov.strip().split():
  1264. subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg)
  1265. bb.utils.mkdirhier(os.path.dirname(subdata_sym))
  1266. oe.path.symlink("../../runtime/%s" % pkg, subdata_sym, True)
  1267. allow_empty = d.getVar('ALLOW_EMPTY_%s' % pkg)
  1268. if not allow_empty:
  1269. allow_empty = d.getVar('ALLOW_EMPTY')
  1270. root = "%s/%s" % (pkgdest, pkg)
  1271. os.chdir(root)
  1272. g = glob('*')
  1273. if g or allow_empty == "1":
  1274. # Symlinks needed for reverse lookups (from the final package name)
  1275. subdata_sym = pkgdatadir + "/runtime-reverse/%s" % pkgval
  1276. oe.path.symlink("../runtime/%s" % pkg, subdata_sym, True)
  1277. packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
  1278. open(packagedfile, 'w').close()
  1279. if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d):
  1280. write_extra_runtime_pkgs(variants, packages, pkgdatadir)
  1281. if bb.data.inherits_class('allarch', d) and not variants \
  1282. and not bb.data.inherits_class('packagegroup', d):
  1283. write_extra_runtime_pkgs(global_variants, packages, pkgdatadir)
  1284. }
  1285. emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse ${PKGDESTWORK}/runtime-rprovides"
  1286. ldconfig_postinst_fragment() {
  1287. if [ x"$D" = "x" ]; then
  1288. if [ -x /sbin/ldconfig ]; then /sbin/ldconfig ; fi
  1289. fi
  1290. }
  1291. RPMDEPS = "${STAGING_LIBDIR_NATIVE}/rpm/rpmdeps --alldeps"
  1292. # Collect perfile run-time dependency metadata
  1293. # Output:
  1294. # FILERPROVIDESFLIST_pkg - list of all files w/ deps
  1295. # FILERPROVIDES_filepath_pkg - per file dep
  1296. #
  1297. # FILERDEPENDSFLIST_pkg - list of all files w/ deps
  1298. # FILERDEPENDS_filepath_pkg - per file dep
  1299. python package_do_filedeps() {
  1300. if d.getVar('SKIP_FILEDEPS') == '1':
  1301. return
  1302. pkgdest = d.getVar('PKGDEST')
  1303. packages = d.getVar('PACKAGES')
  1304. rpmdeps = d.getVar('RPMDEPS')
  1305. def chunks(files, n):
  1306. return [files[i:i+n] for i in range(0, len(files), n)]
  1307. pkglist = []
  1308. for pkg in packages.split():
  1309. if d.getVar('SKIP_FILEDEPS_' + pkg) == '1':
  1310. continue
  1311. if pkg.endswith('-dbg') or pkg.endswith('-doc') or pkg.find('-locale-') != -1 or pkg.find('-localedata-') != -1 or pkg.find('-gconv-') != -1 or pkg.find('-charmap-') != -1 or pkg.startswith('kernel-module-') or pkg.endswith('-src'):
  1312. continue
  1313. for files in chunks(pkgfiles[pkg], 100):
  1314. pkglist.append((pkg, files, rpmdeps, pkgdest))
  1315. processed = oe.utils.multiprocess_launch(oe.package.filedeprunner, pkglist, d)
  1316. provides_files = {}
  1317. requires_files = {}
  1318. for result in processed:
  1319. (pkg, provides, requires) = result
  1320. if pkg not in provides_files:
  1321. provides_files[pkg] = []
  1322. if pkg not in requires_files:
  1323. requires_files[pkg] = []
  1324. for file in sorted(provides):
  1325. provides_files[pkg].append(file)
  1326. key = "FILERPROVIDES_" + file + "_" + pkg
  1327. d.appendVar(key, " " + " ".join(provides[file]))
  1328. for file in sorted(requires):
  1329. requires_files[pkg].append(file)
  1330. key = "FILERDEPENDS_" + file + "_" + pkg
  1331. d.appendVar(key, " " + " ".join(requires[file]))
  1332. for pkg in requires_files:
  1333. d.setVar("FILERDEPENDSFLIST_" + pkg, " ".join(requires_files[pkg]))
  1334. for pkg in provides_files:
  1335. d.setVar("FILERPROVIDESFLIST_" + pkg, " ".join(provides_files[pkg]))
  1336. }
  1337. SHLIBSDIRS = "${WORKDIR_PKGDATA}/${MLPREFIX}shlibs2"
  1338. SHLIBSWORKDIR = "${PKGDESTWORK}/${MLPREFIX}shlibs2"
  1339. python package_do_shlibs() {
  1340. import re, pipes
  1341. import subprocess
  1342. exclude_shlibs = d.getVar('EXCLUDE_FROM_SHLIBS', False)
  1343. if exclude_shlibs:
  1344. bb.note("not generating shlibs")
  1345. return
  1346. lib_re = re.compile(r"^.*\.so")
  1347. libdir_re = re.compile(r".*/%s$" % d.getVar('baselib'))
  1348. packages = d.getVar('PACKAGES')
  1349. shlib_pkgs = []
  1350. exclusion_list = d.getVar("EXCLUDE_PACKAGES_FROM_SHLIBS")
  1351. if exclusion_list:
  1352. for pkg in packages.split():
  1353. if pkg not in exclusion_list.split():
  1354. shlib_pkgs.append(pkg)
  1355. else:
  1356. bb.note("not generating shlibs for %s" % pkg)
  1357. else:
  1358. shlib_pkgs = packages.split()
  1359. targetos = d.getVar('TARGET_OS')
  1360. workdir = d.getVar('WORKDIR')
  1361. ver = d.getVar('PKGV')
  1362. if not ver:
  1363. msg = "PKGV not defined"
  1364. package_qa_handle_error("pkgv-undefined", msg, d)
  1365. return
  1366. pkgdest = d.getVar('PKGDEST')
  1367. shlibswork_dir = d.getVar('SHLIBSWORKDIR')
  1368. def linux_so(file, pkg, pkgver, d):
  1369. needs_ldconfig = False
  1370. needed = set()
  1371. sonames = set()
  1372. renames = []
  1373. ldir = os.path.dirname(file).replace(pkgdest + "/" + pkg, '')
  1374. cmd = d.getVar('OBJDUMP') + " -p " + pipes.quote(file) + " 2>/dev/null"
  1375. fd = os.popen(cmd)
  1376. lines = fd.readlines()
  1377. fd.close()
  1378. rpath = tuple()
  1379. for l in lines:
  1380. m = re.match(r"\s+RPATH\s+([^\s]*)", l)
  1381. if m:
  1382. rpaths = m.group(1).replace("$ORIGIN", ldir).split(":")
  1383. rpath = tuple(map(os.path.normpath, rpaths))
  1384. for l in lines:
  1385. m = re.match(r"\s+NEEDED\s+([^\s]*)", l)
  1386. if m:
  1387. dep = m.group(1)
  1388. if dep not in needed:
  1389. needed.add((dep, file, rpath))
  1390. m = re.match(r"\s+SONAME\s+([^\s]*)", l)
  1391. if m:
  1392. this_soname = m.group(1)
  1393. prov = (this_soname, ldir, pkgver)
  1394. if not prov in sonames:
  1395. # if library is private (only used by package) then do not build shlib for it
  1396. if not private_libs or this_soname not in private_libs:
  1397. sonames.add(prov)
  1398. if libdir_re.match(os.path.dirname(file)):
  1399. needs_ldconfig = True
  1400. if snap_symlinks and (os.path.basename(file) != this_soname):
  1401. renames.append((file, os.path.join(os.path.dirname(file), this_soname)))
  1402. return (needs_ldconfig, needed, sonames, renames)
  1403. def darwin_so(file, needed, sonames, renames, pkgver):
  1404. if not os.path.exists(file):
  1405. return
  1406. ldir = os.path.dirname(file).replace(pkgdest + "/" + pkg, '')
  1407. def get_combinations(base):
  1408. #
  1409. # Given a base library name, find all combinations of this split by "." and "-"
  1410. #
  1411. combos = []
  1412. options = base.split(".")
  1413. for i in range(1, len(options) + 1):
  1414. combos.append(".".join(options[0:i]))
  1415. options = base.split("-")
  1416. for i in range(1, len(options) + 1):
  1417. combos.append("-".join(options[0:i]))
  1418. return combos
  1419. if (file.endswith('.dylib') or file.endswith('.so')) and not pkg.endswith('-dev') and not pkg.endswith('-dbg') and not pkg.endswith('-src'):
  1420. # Drop suffix
  1421. name = os.path.basename(file).rsplit(".",1)[0]
  1422. # Find all combinations
  1423. combos = get_combinations(name)
  1424. for combo in combos:
  1425. if not combo in sonames:
  1426. prov = (combo, ldir, pkgver)
  1427. sonames.add(prov)
  1428. if file.endswith('.dylib') or file.endswith('.so'):
  1429. rpath = []
  1430. p = subprocess.Popen([d.expand("${HOST_PREFIX}otool"), '-l', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  1431. out, err = p.communicate()
  1432. # If returned successfully, process stdout for results
  1433. if p.returncode == 0:
  1434. for l in out.split("\n"):
  1435. l = l.strip()
  1436. if l.startswith('path '):
  1437. rpath.append(l.split()[1])
  1438. p = subprocess.Popen([d.expand("${HOST_PREFIX}otool"), '-L', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  1439. out, err = p.communicate()
  1440. # If returned successfully, process stdout for results
  1441. if p.returncode == 0:
  1442. for l in out.split("\n"):
  1443. l = l.strip()
  1444. if not l or l.endswith(":"):
  1445. continue
  1446. if "is not an object file" in l:
  1447. continue
  1448. name = os.path.basename(l.split()[0]).rsplit(".", 1)[0]
  1449. if name and name not in needed[pkg]:
  1450. needed[pkg].add((name, file, tuple()))
  1451. def mingw_dll(file, needed, sonames, renames, pkgver):
  1452. if not os.path.exists(file):
  1453. return
  1454. if file.endswith(".dll"):
  1455. # assume all dlls are shared objects provided by the package
  1456. sonames.add((os.path.basename(file), os.path.dirname(file).replace(pkgdest + "/" + pkg, ''), pkgver))
  1457. if (file.endswith(".dll") or file.endswith(".exe")):
  1458. # use objdump to search for "DLL Name: .*\.dll"
  1459. p = subprocess.Popen([d.expand("${HOST_PREFIX}objdump"), "-p", file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  1460. out, err = p.communicate()
  1461. # process the output, grabbing all .dll names
  1462. if p.returncode == 0:
  1463. for m in re.finditer(r"DLL Name: (.*?\.dll)$", out.decode(), re.MULTILINE | re.IGNORECASE):
  1464. dllname = m.group(1)
  1465. if dllname:
  1466. needed[pkg].add((dllname, file, tuple()))
  1467. if d.getVar('PACKAGE_SNAP_LIB_SYMLINKS') == "1":
  1468. snap_symlinks = True
  1469. else:
  1470. snap_symlinks = False
  1471. use_ldconfig = bb.utils.contains('DISTRO_FEATURES', 'ldconfig', True, False, d)
  1472. needed = {}
  1473. shlib_provider = oe.package.read_shlib_providers(d)
  1474. for pkg in shlib_pkgs:
  1475. private_libs = d.getVar('PRIVATE_LIBS_' + pkg) or d.getVar('PRIVATE_LIBS') or ""
  1476. private_libs = private_libs.split()
  1477. needs_ldconfig = False
  1478. bb.debug(2, "calculating shlib provides for %s" % pkg)
  1479. pkgver = d.getVar('PKGV_' + pkg)
  1480. if not pkgver:
  1481. pkgver = d.getVar('PV_' + pkg)
  1482. if not pkgver:
  1483. pkgver = ver
  1484. needed[pkg] = set()
  1485. sonames = set()
  1486. renames = []
  1487. linuxlist = []
  1488. for file in pkgfiles[pkg]:
  1489. soname = None
  1490. if cpath.islink(file):
  1491. continue
  1492. if targetos == "darwin" or targetos == "darwin8":
  1493. darwin_so(file, needed, sonames, renames, pkgver)
  1494. elif targetos.startswith("mingw"):
  1495. mingw_dll(file, needed, sonames, renames, pkgver)
  1496. elif os.access(file, os.X_OK) or lib_re.match(file):
  1497. linuxlist.append(file)
  1498. if linuxlist:
  1499. results = oe.utils.multiprocess_launch(linux_so, linuxlist, d, extraargs=(pkg, pkgver, d))
  1500. for r in results:
  1501. ldconfig = r[0]
  1502. needed[pkg] |= r[1]
  1503. sonames |= r[2]
  1504. renames.extend(r[3])
  1505. needs_ldconfig = needs_ldconfig or ldconfig
  1506. for (old, new) in renames:
  1507. bb.note("Renaming %s to %s" % (old, new))
  1508. os.rename(old, new)
  1509. pkgfiles[pkg].remove(old)
  1510. shlibs_file = os.path.join(shlibswork_dir, pkg + ".list")
  1511. if len(sonames):
  1512. fd = open(shlibs_file, 'w')
  1513. for s in sonames:
  1514. if s[0] in shlib_provider and s[1] in shlib_provider[s[0]]:
  1515. (old_pkg, old_pkgver) = shlib_provider[s[0]][s[1]]
  1516. if old_pkg != pkg:
  1517. bb.warn('%s-%s was registered as shlib provider for %s, changing it to %s-%s because it was built later' % (old_pkg, old_pkgver, s[0], pkg, pkgver))
  1518. bb.debug(1, 'registering %s-%s as shlib provider for %s' % (pkg, pkgver, s[0]))
  1519. fd.write(s[0] + ':' + s[1] + ':' + s[2] + '\n')
  1520. if s[0] not in shlib_provider:
  1521. shlib_provider[s[0]] = {}
  1522. shlib_provider[s[0]][s[1]] = (pkg, pkgver)
  1523. fd.close()
  1524. if needs_ldconfig and use_ldconfig:
  1525. bb.debug(1, 'adding ldconfig call to postinst for %s' % pkg)
  1526. postinst = d.getVar('pkg_postinst_%s' % pkg)
  1527. if not postinst:
  1528. postinst = '#!/bin/sh\n'
  1529. postinst += d.getVar('ldconfig_postinst_fragment')
  1530. d.setVar('pkg_postinst_%s' % pkg, postinst)
  1531. bb.debug(1, 'LIBNAMES: pkg %s sonames %s' % (pkg, sonames))
  1532. assumed_libs = d.getVar('ASSUME_SHLIBS')
  1533. if assumed_libs:
  1534. libdir = d.getVar("libdir")
  1535. for e in assumed_libs.split():
  1536. l, dep_pkg = e.split(":")
  1537. lib_ver = None
  1538. dep_pkg = dep_pkg.rsplit("_", 1)
  1539. if len(dep_pkg) == 2:
  1540. lib_ver = dep_pkg[1]
  1541. dep_pkg = dep_pkg[0]
  1542. if l not in shlib_provider:
  1543. shlib_provider[l] = {}
  1544. shlib_provider[l][libdir] = (dep_pkg, lib_ver)
  1545. libsearchpath = [d.getVar('libdir'), d.getVar('base_libdir')]
  1546. for pkg in shlib_pkgs:
  1547. bb.debug(2, "calculating shlib requirements for %s" % pkg)
  1548. private_libs = d.getVar('PRIVATE_LIBS_' + pkg) or d.getVar('PRIVATE_LIBS') or ""
  1549. private_libs = private_libs.split()
  1550. deps = list()
  1551. for n in needed[pkg]:
  1552. # if n is in private libraries, don't try to search provider for it
  1553. # this could cause problem in case some abc.bb provides private
  1554. # /opt/abc/lib/libfoo.so.1 and contains /usr/bin/abc depending on system library libfoo.so.1
  1555. # but skipping it is still better alternative than providing own
  1556. # version and then adding runtime dependency for the same system library
  1557. if private_libs and n[0] in private_libs:
  1558. bb.debug(2, '%s: Dependency %s covered by PRIVATE_LIBS' % (pkg, n[0]))
  1559. continue
  1560. if n[0] in shlib_provider.keys():
  1561. shlib_provider_path = []
  1562. for k in shlib_provider[n[0]].keys():
  1563. shlib_provider_path.append(k)
  1564. match = None
  1565. for p in list(n[2]) + shlib_provider_path + libsearchpath:
  1566. if p in shlib_provider[n[0]]:
  1567. match = p
  1568. break
  1569. if match:
  1570. (dep_pkg, ver_needed) = shlib_provider[n[0]][match]
  1571. bb.debug(2, '%s: Dependency %s requires package %s (used by files: %s)' % (pkg, n[0], dep_pkg, n[1]))
  1572. if dep_pkg == pkg:
  1573. continue
  1574. if ver_needed:
  1575. dep = "%s (>= %s)" % (dep_pkg, ver_needed)
  1576. else:
  1577. dep = dep_pkg
  1578. if not dep in deps:
  1579. deps.append(dep)
  1580. continue
  1581. bb.note("Couldn't find shared library provider for %s, used by files: %s" % (n[0], n[1]))
  1582. deps_file = os.path.join(pkgdest, pkg + ".shlibdeps")
  1583. if os.path.exists(deps_file):
  1584. os.remove(deps_file)
  1585. if len(deps):
  1586. fd = open(deps_file, 'w')
  1587. for dep in sorted(deps):
  1588. fd.write(dep + '\n')
  1589. fd.close()
  1590. }
  1591. python package_do_pkgconfig () {
  1592. import re
  1593. packages = d.getVar('PACKAGES')
  1594. workdir = d.getVar('WORKDIR')
  1595. pkgdest = d.getVar('PKGDEST')
  1596. shlibs_dirs = d.getVar('SHLIBSDIRS').split()
  1597. shlibswork_dir = d.getVar('SHLIBSWORKDIR')
  1598. pc_re = re.compile(r'(.*)\.pc$')
  1599. var_re = re.compile(r'(.*)=(.*)')
  1600. field_re = re.compile(r'(.*): (.*)')
  1601. pkgconfig_provided = {}
  1602. pkgconfig_needed = {}
  1603. for pkg in packages.split():
  1604. pkgconfig_provided[pkg] = []
  1605. pkgconfig_needed[pkg] = []
  1606. for file in pkgfiles[pkg]:
  1607. m = pc_re.match(file)
  1608. if m:
  1609. pd = bb.data.init()
  1610. name = m.group(1)
  1611. pkgconfig_provided[pkg].append(name)
  1612. if not os.access(file, os.R_OK):
  1613. continue
  1614. f = open(file, 'r')
  1615. lines = f.readlines()
  1616. f.close()
  1617. for l in lines:
  1618. m = var_re.match(l)
  1619. if m:
  1620. name = m.group(1)
  1621. val = m.group(2)
  1622. pd.setVar(name, pd.expand(val))
  1623. continue
  1624. m = field_re.match(l)
  1625. if m:
  1626. hdr = m.group(1)
  1627. exp = pd.expand(m.group(2))
  1628. if hdr == 'Requires':
  1629. pkgconfig_needed[pkg] += exp.replace(',', ' ').split()
  1630. for pkg in packages.split():
  1631. pkgs_file = os.path.join(shlibswork_dir, pkg + ".pclist")
  1632. if pkgconfig_provided[pkg] != []:
  1633. f = open(pkgs_file, 'w')
  1634. for p in pkgconfig_provided[pkg]:
  1635. f.write('%s\n' % p)
  1636. f.close()
  1637. # Go from least to most specific since the last one found wins
  1638. for dir in reversed(shlibs_dirs):
  1639. if not os.path.exists(dir):
  1640. continue
  1641. for file in os.listdir(dir):
  1642. m = re.match(r'^(.*)\.pclist$', file)
  1643. if m:
  1644. pkg = m.group(1)
  1645. fd = open(os.path.join(dir, file))
  1646. lines = fd.readlines()
  1647. fd.close()
  1648. pkgconfig_provided[pkg] = []
  1649. for l in lines:
  1650. pkgconfig_provided[pkg].append(l.rstrip())
  1651. for pkg in packages.split():
  1652. deps = []
  1653. for n in pkgconfig_needed[pkg]:
  1654. found = False
  1655. for k in pkgconfig_provided.keys():
  1656. if n in pkgconfig_provided[k]:
  1657. if k != pkg and not (k in deps):
  1658. deps.append(k)
  1659. found = True
  1660. if found == False:
  1661. bb.note("couldn't find pkgconfig module '%s' in any package" % n)
  1662. deps_file = os.path.join(pkgdest, pkg + ".pcdeps")
  1663. if len(deps):
  1664. fd = open(deps_file, 'w')
  1665. for dep in deps:
  1666. fd.write(dep + '\n')
  1667. fd.close()
  1668. }
  1669. def read_libdep_files(d):
  1670. pkglibdeps = {}
  1671. packages = d.getVar('PACKAGES').split()
  1672. for pkg in packages:
  1673. pkglibdeps[pkg] = {}
  1674. for extension in ".shlibdeps", ".pcdeps", ".clilibdeps":
  1675. depsfile = d.expand("${PKGDEST}/" + pkg + extension)
  1676. if os.access(depsfile, os.R_OK):
  1677. fd = open(depsfile)
  1678. lines = fd.readlines()
  1679. fd.close()
  1680. for l in lines:
  1681. l.rstrip()
  1682. deps = bb.utils.explode_dep_versions2(l)
  1683. for dep in deps:
  1684. if not dep in pkglibdeps[pkg]:
  1685. pkglibdeps[pkg][dep] = deps[dep]
  1686. return pkglibdeps
  1687. python read_shlibdeps () {
  1688. pkglibdeps = read_libdep_files(d)
  1689. packages = d.getVar('PACKAGES').split()
  1690. for pkg in packages:
  1691. rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "")
  1692. for dep in sorted(pkglibdeps[pkg]):
  1693. # Add the dep if it's not already there, or if no comparison is set
  1694. if dep not in rdepends:
  1695. rdepends[dep] = []
  1696. for v in pkglibdeps[pkg][dep]:
  1697. if v not in rdepends[dep]:
  1698. rdepends[dep].append(v)
  1699. d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
  1700. }
  1701. python package_depchains() {
  1702. """
  1703. For a given set of prefix and postfix modifiers, make those packages
  1704. RRECOMMENDS on the corresponding packages for its RDEPENDS.
  1705. Example: If package A depends upon package B, and A's .bb emits an
  1706. A-dev package, this would make A-dev Recommends: B-dev.
  1707. If only one of a given suffix is specified, it will take the RRECOMMENDS
  1708. based on the RDEPENDS of *all* other packages. If more than one of a given
  1709. suffix is specified, its will only use the RDEPENDS of the single parent
  1710. package.
  1711. """
  1712. packages = d.getVar('PACKAGES')
  1713. postfixes = (d.getVar('DEPCHAIN_POST') or '').split()
  1714. prefixes = (d.getVar('DEPCHAIN_PRE') or '').split()
  1715. def pkg_adddeprrecs(pkg, base, suffix, getname, depends, d):
  1716. #bb.note('depends for %s is %s' % (base, depends))
  1717. rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg) or "")
  1718. for depend in sorted(depends):
  1719. if depend.find('-native') != -1 or depend.find('-cross') != -1 or depend.startswith('virtual/'):
  1720. #bb.note("Skipping %s" % depend)
  1721. continue
  1722. if depend.endswith('-dev'):
  1723. depend = depend[:-4]
  1724. if depend.endswith('-dbg'):
  1725. depend = depend[:-4]
  1726. pkgname = getname(depend, suffix)
  1727. #bb.note("Adding %s for %s" % (pkgname, depend))
  1728. if pkgname not in rreclist and pkgname != pkg:
  1729. rreclist[pkgname] = []
  1730. #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
  1731. d.setVar('RRECOMMENDS_%s' % pkg, bb.utils.join_deps(rreclist, commasep=False))
  1732. def pkg_addrrecs(pkg, base, suffix, getname, rdepends, d):
  1733. #bb.note('rdepends for %s is %s' % (base, rdepends))
  1734. rreclist = bb.utils.explode_dep_versions2(d.getVar('RRECOMMENDS_' + pkg) or "")
  1735. for depend in sorted(rdepends):
  1736. if depend.find('virtual-locale-') != -1:
  1737. #bb.note("Skipping %s" % depend)
  1738. continue
  1739. if depend.endswith('-dev'):
  1740. depend = depend[:-4]
  1741. if depend.endswith('-dbg'):
  1742. depend = depend[:-4]
  1743. pkgname = getname(depend, suffix)
  1744. #bb.note("Adding %s for %s" % (pkgname, depend))
  1745. if pkgname not in rreclist and pkgname != pkg:
  1746. rreclist[pkgname] = []
  1747. #bb.note('setting: RRECOMMENDS_%s=%s' % (pkg, ' '.join(rreclist)))
  1748. d.setVar('RRECOMMENDS_%s' % pkg, bb.utils.join_deps(rreclist, commasep=False))
  1749. def add_dep(list, dep):
  1750. if dep not in list:
  1751. list.append(dep)
  1752. depends = []
  1753. for dep in bb.utils.explode_deps(d.getVar('DEPENDS') or ""):
  1754. add_dep(depends, dep)
  1755. rdepends = []
  1756. for pkg in packages.split():
  1757. for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + pkg) or ""):
  1758. add_dep(rdepends, dep)
  1759. #bb.note('rdepends is %s' % rdepends)
  1760. def post_getname(name, suffix):
  1761. return '%s%s' % (name, suffix)
  1762. def pre_getname(name, suffix):
  1763. return '%s%s' % (suffix, name)
  1764. pkgs = {}
  1765. for pkg in packages.split():
  1766. for postfix in postfixes:
  1767. if pkg.endswith(postfix):
  1768. if not postfix in pkgs:
  1769. pkgs[postfix] = {}
  1770. pkgs[postfix][pkg] = (pkg[:-len(postfix)], post_getname)
  1771. for prefix in prefixes:
  1772. if pkg.startswith(prefix):
  1773. if not prefix in pkgs:
  1774. pkgs[prefix] = {}
  1775. pkgs[prefix][pkg] = (pkg[:-len(prefix)], pre_getname)
  1776. if "-dbg" in pkgs:
  1777. pkglibdeps = read_libdep_files(d)
  1778. pkglibdeplist = []
  1779. for pkg in pkglibdeps:
  1780. for k in pkglibdeps[pkg]:
  1781. add_dep(pkglibdeplist, k)
  1782. dbgdefaultdeps = ((d.getVar('DEPCHAIN_DBGDEFAULTDEPS') == '1') or (bb.data.inherits_class('packagegroup', d)))
  1783. for suffix in pkgs:
  1784. for pkg in pkgs[suffix]:
  1785. if d.getVarFlag('RRECOMMENDS_' + pkg, 'nodeprrecs'):
  1786. continue
  1787. (base, func) = pkgs[suffix][pkg]
  1788. if suffix == "-dev":
  1789. pkg_adddeprrecs(pkg, base, suffix, func, depends, d)
  1790. elif suffix == "-dbg":
  1791. if not dbgdefaultdeps:
  1792. pkg_addrrecs(pkg, base, suffix, func, pkglibdeplist, d)
  1793. continue
  1794. if len(pkgs[suffix]) == 1:
  1795. pkg_addrrecs(pkg, base, suffix, func, rdepends, d)
  1796. else:
  1797. rdeps = []
  1798. for dep in bb.utils.explode_deps(d.getVar('RDEPENDS_' + base) or ""):
  1799. add_dep(rdeps, dep)
  1800. pkg_addrrecs(pkg, base, suffix, func, rdeps, d)
  1801. }
  1802. # Since bitbake can't determine which variables are accessed during package
  1803. # iteration, we need to list them here:
  1804. PACKAGEVARS = "FILES RDEPENDS RRECOMMENDS SUMMARY DESCRIPTION RSUGGESTS RPROVIDES RCONFLICTS PKG ALLOW_EMPTY pkg_postinst pkg_postrm pkg_postinst_ontarget INITSCRIPT_NAME INITSCRIPT_PARAMS DEBIAN_NOAUTONAME ALTERNATIVE PKGE PKGV PKGR USERADD_PARAM GROUPADD_PARAM CONFFILES SYSTEMD_SERVICE LICENSE SECTION pkg_preinst pkg_prerm RREPLACES GROUPMEMS_PARAM SYSTEMD_AUTO_ENABLE SKIP_FILEDEPS PRIVATE_LIBS"
  1805. def gen_packagevar(d):
  1806. ret = []
  1807. pkgs = (d.getVar("PACKAGES") or "").split()
  1808. vars = (d.getVar("PACKAGEVARS") or "").split()
  1809. for p in pkgs:
  1810. for v in vars:
  1811. ret.append(v + "_" + p)
  1812. # Ensure that changes to INCOMPATIBLE_LICENSE re-run do_package for
  1813. # affected recipes.
  1814. ret.append('LICENSE_EXCLUSION-%s' % p)
  1815. return " ".join(ret)
  1816. PACKAGE_PREPROCESS_FUNCS ?= ""
  1817. # Functions for setting up PKGD
  1818. PACKAGEBUILDPKGD ?= " \
  1819. package_prepare_pkgdata \
  1820. perform_packagecopy \
  1821. ${PACKAGE_PREPROCESS_FUNCS} \
  1822. split_and_strip_files \
  1823. fixup_perms \
  1824. "
  1825. # Functions which split PKGD up into separate packages
  1826. PACKAGESPLITFUNCS ?= " \
  1827. package_do_split_locales \
  1828. populate_packages"
  1829. # Functions which process metadata based on split packages
  1830. PACKAGEFUNCS += " \
  1831. package_fixsymlinks \
  1832. package_name_hook \
  1833. package_do_filedeps \
  1834. package_do_shlibs \
  1835. package_do_pkgconfig \
  1836. read_shlibdeps \
  1837. package_depchains \
  1838. emit_pkgdata"
  1839. python do_package () {
  1840. # Change the following version to cause sstate to invalidate the package
  1841. # cache. This is useful if an item this class depends on changes in a
  1842. # way that the output of this class changes. rpmdeps is a good example
  1843. # as any change to rpmdeps requires this to be rerun.
  1844. # PACKAGE_BBCLASS_VERSION = "2"
  1845. # Init cachedpath
  1846. global cpath
  1847. cpath = oe.cachedpath.CachedPath()
  1848. ###########################################################################
  1849. # Sanity test the setup
  1850. ###########################################################################
  1851. packages = (d.getVar('PACKAGES') or "").split()
  1852. if len(packages) < 1:
  1853. bb.debug(1, "No packages to build, skipping do_package")
  1854. return
  1855. workdir = d.getVar('WORKDIR')
  1856. outdir = d.getVar('DEPLOY_DIR')
  1857. dest = d.getVar('D')
  1858. dvar = d.getVar('PKGD')
  1859. pn = d.getVar('PN')
  1860. if not workdir or not outdir or not dest or not dvar or not pn:
  1861. msg = "WORKDIR, DEPLOY_DIR, D, PN and PKGD all must be defined, unable to package"
  1862. package_qa_handle_error("var-undefined", msg, d)
  1863. return
  1864. bb.build.exec_func("package_get_auto_pr", d)
  1865. ###########################################################################
  1866. # Optimisations
  1867. ###########################################################################
  1868. # Continually expanding complex expressions is inefficient, particularly
  1869. # when we write to the datastore and invalidate the expansion cache. This
  1870. # code pre-expands some frequently used variables
  1871. def expandVar(x, d):
  1872. d.setVar(x, d.getVar(x))
  1873. for x in 'PN', 'PV', 'BPN', 'TARGET_SYS', 'EXTENDPRAUTO':
  1874. expandVar(x, d)
  1875. ###########################################################################
  1876. # Setup PKGD (from D)
  1877. ###########################################################################
  1878. for f in (d.getVar('PACKAGEBUILDPKGD') or '').split():
  1879. bb.build.exec_func(f, d)
  1880. ###########################################################################
  1881. # Split up PKGD into PKGDEST
  1882. ###########################################################################
  1883. cpath = oe.cachedpath.CachedPath()
  1884. for f in (d.getVar('PACKAGESPLITFUNCS') or '').split():
  1885. bb.build.exec_func(f, d)
  1886. ###########################################################################
  1887. # Process PKGDEST
  1888. ###########################################################################
  1889. # Build global list of files in each split package
  1890. global pkgfiles
  1891. pkgfiles = {}
  1892. packages = d.getVar('PACKAGES').split()
  1893. pkgdest = d.getVar('PKGDEST')
  1894. for pkg in packages:
  1895. pkgfiles[pkg] = []
  1896. for walkroot, dirs, files in cpath.walk(pkgdest + "/" + pkg):
  1897. for file in files:
  1898. pkgfiles[pkg].append(walkroot + os.sep + file)
  1899. for f in (d.getVar('PACKAGEFUNCS') or '').split():
  1900. bb.build.exec_func(f, d)
  1901. qa_sane = d.getVar("QA_SANE")
  1902. if not qa_sane:
  1903. bb.fatal("Fatal QA errors found, failing task.")
  1904. }
  1905. do_package[dirs] = "${SHLIBSWORKDIR} ${PKGDESTWORK} ${D}"
  1906. do_package[vardeps] += "${PACKAGEBUILDPKGD} ${PACKAGESPLITFUNCS} ${PACKAGEFUNCS} ${@gen_packagevar(d)}"
  1907. addtask package after do_install
  1908. SSTATETASKS += "do_package"
  1909. do_package[cleandirs] = "${PKGDEST} ${PKGDESTWORK}"
  1910. do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST} ${PKGDESTWORK}"
  1911. do_package_setscene[dirs] = "${STAGING_DIR}"
  1912. python do_package_setscene () {
  1913. sstate_setscene(d)
  1914. }
  1915. addtask do_package_setscene
  1916. do_packagedata () {
  1917. :
  1918. }
  1919. addtask packagedata before do_build after do_package
  1920. SSTATETASKS += "do_packagedata"
  1921. do_packagedata[sstate-inputdirs] = "${PKGDESTWORK}"
  1922. do_packagedata[sstate-outputdirs] = "${PKGDATA_DIR}"
  1923. do_packagedata[stamp-extra-info] = "${MACHINE_ARCH}"
  1924. python do_packagedata_setscene () {
  1925. sstate_setscene(d)
  1926. }
  1927. addtask do_packagedata_setscene
  1928. #
  1929. # Helper functions for the package writing classes
  1930. #
  1931. def mapping_rename_hook(d):
  1932. """
  1933. Rewrite variables to account for package renaming in things
  1934. like debian.bbclass or manual PKG variable name changes
  1935. """
  1936. pkg = d.getVar("PKG")
  1937. runtime_mapping_rename("RDEPENDS", pkg, d)
  1938. runtime_mapping_rename("RRECOMMENDS", pkg, d)
  1939. runtime_mapping_rename("RSUGGESTS", pkg, d)