package.bbclass 86 KB

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