package.bbclass 95 KB

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