bitbake-layers 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. #!/usr/bin/env python
  2. # This script has subcommands which operate against your bitbake layers, either
  3. # displaying useful information, or acting against them.
  4. # See the help output for details on available commands.
  5. # Copyright (C) 2011 Mentor Graphics Corporation
  6. # Copyright (C) 2012 Intel Corporation
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. import cmd
  21. import logging
  22. import os
  23. import sys
  24. import fnmatch
  25. from collections import defaultdict
  26. import re
  27. bindir = os.path.dirname(__file__)
  28. topdir = os.path.dirname(bindir)
  29. sys.path[0:0] = [os.path.join(topdir, 'lib')]
  30. import bb.cache
  31. import bb.cooker
  32. import bb.providers
  33. import bb.utils
  34. import bb.tinfoil
  35. logger = logging.getLogger('BitBake')
  36. def main(args):
  37. cmds = Commands()
  38. if args:
  39. # Allow user to specify e.g. show-layers instead of show_layers
  40. args = [args[0].replace('-', '_')] + args[1:]
  41. cmds.onecmd(' '.join(args))
  42. else:
  43. cmds.do_help('')
  44. return cmds.returncode
  45. class Commands(cmd.Cmd):
  46. def __init__(self):
  47. cmd.Cmd.__init__(self)
  48. self.bbhandler = bb.tinfoil.Tinfoil()
  49. self.returncode = 0
  50. self.bblayers = (self.bbhandler.config_data.getVar('BBLAYERS', True) or "").split()
  51. def default(self, line):
  52. """Handle unrecognised commands"""
  53. sys.stderr.write("Unrecognised command or option\n")
  54. self.do_help('')
  55. def do_help(self, topic):
  56. """display general help or help on a specified command"""
  57. if topic:
  58. sys.stdout.write('%s: ' % topic)
  59. cmd.Cmd.do_help(self, topic.replace('-', '_'))
  60. else:
  61. sys.stdout.write("usage: bitbake-layers <command> [arguments]\n\n")
  62. sys.stdout.write("Available commands:\n")
  63. procnames = list(set(self.get_names()))
  64. for procname in procnames:
  65. if procname[:3] == 'do_':
  66. sys.stdout.write(" %s\n" % procname[3:].replace('_', '-'))
  67. doc = getattr(self, procname).__doc__
  68. if doc:
  69. sys.stdout.write(" %s\n" % doc.splitlines()[0])
  70. def do_show_layers(self, args):
  71. """show current configured layers"""
  72. self.bbhandler.prepare(config_only = True)
  73. logger.plain("%s %s %s" % ("layer".ljust(20), "path".ljust(40), "priority"))
  74. logger.plain('=' * 74)
  75. for layerdir in self.bblayers:
  76. layername = self.get_layer_name(layerdir)
  77. layerpri = 0
  78. for layer, _, regex, pri in self.bbhandler.cooker.recipecache.bbfile_config_priorities:
  79. if regex.match(os.path.join(layerdir, 'test')):
  80. layerpri = pri
  81. break
  82. logger.plain("%s %s %d" % (layername.ljust(20), layerdir.ljust(40), layerpri))
  83. def version_str(self, pe, pv, pr = None):
  84. verstr = "%s" % pv
  85. if pr:
  86. verstr = "%s-%s" % (verstr, pr)
  87. if pe:
  88. verstr = "%s:%s" % (pe, verstr)
  89. return verstr
  90. def do_show_overlayed(self, args):
  91. """list overlayed recipes (where the same recipe exists in another layer)
  92. usage: show-overlayed [-f] [-s]
  93. Lists the names of overlayed recipes and the available versions in each
  94. layer, with the preferred version first. Note that skipped recipes that
  95. are overlayed will also be listed, with a " (skipped)" suffix.
  96. Options:
  97. -f instead of the default formatting, list filenames of higher priority
  98. recipes with the ones they overlay indented underneath
  99. -s only list overlayed recipes where the version is the same
  100. """
  101. self.bbhandler.prepare()
  102. show_filenames = False
  103. show_same_ver_only = False
  104. for arg in args.split():
  105. if arg == '-f':
  106. show_filenames = True
  107. elif arg == '-s':
  108. show_same_ver_only = True
  109. else:
  110. sys.stderr.write("show-overlayed: invalid option %s\n" % arg)
  111. self.do_help('')
  112. return
  113. items_listed = self.list_recipes('Overlayed recipes', None, True, show_same_ver_only, show_filenames, True)
  114. # Check for overlayed .bbclass files
  115. classes = defaultdict(list)
  116. for layerdir in self.bblayers:
  117. classdir = os.path.join(layerdir, 'classes')
  118. if os.path.exists(classdir):
  119. for classfile in os.listdir(classdir):
  120. if os.path.splitext(classfile)[1] == '.bbclass':
  121. classes[classfile].append(classdir)
  122. # Locating classes and other files is a bit more complicated than recipes -
  123. # layer priority is not a factor; instead BitBake uses the first matching
  124. # file in BBPATH, which is manipulated directly by each layer's
  125. # conf/layer.conf in turn, thus the order of layers in bblayers.conf is a
  126. # factor - however, each layer.conf is free to either prepend or append to
  127. # BBPATH (or indeed do crazy stuff with it). Thus the order in BBPATH might
  128. # not be exactly the order present in bblayers.conf either.
  129. bbpath = str(self.bbhandler.config_data.getVar('BBPATH', True))
  130. overlayed_class_found = False
  131. for (classfile, classdirs) in classes.items():
  132. if len(classdirs) > 1:
  133. if not overlayed_class_found:
  134. logger.plain('=== Overlayed classes ===')
  135. overlayed_class_found = True
  136. mainfile = bb.utils.which(bbpath, os.path.join('classes', classfile))
  137. if show_filenames:
  138. logger.plain('%s' % mainfile)
  139. else:
  140. # We effectively have to guess the layer here
  141. logger.plain('%s:' % classfile)
  142. mainlayername = '?'
  143. for layerdir in self.bblayers:
  144. classdir = os.path.join(layerdir, 'classes')
  145. if mainfile.startswith(classdir):
  146. mainlayername = self.get_layer_name(layerdir)
  147. logger.plain(' %s' % mainlayername)
  148. for classdir in classdirs:
  149. fullpath = os.path.join(classdir, classfile)
  150. if fullpath != mainfile:
  151. if show_filenames:
  152. print(' %s' % fullpath)
  153. else:
  154. print(' %s' % self.get_layer_name(os.path.dirname(classdir)))
  155. if overlayed_class_found:
  156. items_listed = True;
  157. if not items_listed:
  158. logger.plain('No overlayed files found.')
  159. def do_show_recipes(self, args):
  160. """list available recipes, showing the layer they are provided by
  161. usage: show-recipes [-f] [-m] [pnspec]
  162. Lists the names of overlayed recipes and the available versions in each
  163. layer, with the preferred version first. Optionally you may specify
  164. pnspec to match a specified recipe name (supports wildcards). Note that
  165. skipped recipes will also be listed, with a " (skipped)" suffix.
  166. Options:
  167. -f instead of the default formatting, list filenames of higher priority
  168. recipes with other available recipes indented underneath
  169. -m only list where multiple recipes (in the same layer or different
  170. layers) exist for the same recipe name
  171. """
  172. self.bbhandler.prepare()
  173. show_filenames = False
  174. show_multi_provider_only = False
  175. pnspec = None
  176. title = 'Available recipes:'
  177. for arg in args.split():
  178. if arg == '-f':
  179. show_filenames = True
  180. elif arg == '-m':
  181. show_multi_provider_only = True
  182. elif not arg.startswith('-'):
  183. pnspec = arg
  184. title = 'Available recipes matching %s:' % pnspec
  185. else:
  186. sys.stderr.write("show-recipes: invalid option %s\n" % arg)
  187. self.do_help('')
  188. return
  189. self.list_recipes(title, pnspec, False, False, show_filenames, show_multi_provider_only)
  190. def list_recipes(self, title, pnspec, show_overlayed_only, show_same_ver_only, show_filenames, show_multi_provider_only):
  191. pkg_pn = self.bbhandler.cooker.recipecache.pkg_pn
  192. (latest_versions, preferred_versions) = bb.providers.findProviders(self.bbhandler.cooker.configuration.data, self.bbhandler.cooker.recipecache, pkg_pn)
  193. allproviders = bb.providers.allProviders(self.bbhandler.cooker.recipecache)
  194. # Ensure we list skipped recipes
  195. # We are largely guessing about PN, PV and the preferred version here,
  196. # but we have no choice since skipped recipes are not fully parsed
  197. skiplist = self.bbhandler.cooker.skiplist.keys()
  198. skiplist.sort( key=lambda fileitem: self.bbhandler.cooker.calc_bbfile_priority(fileitem) )
  199. skiplist.reverse()
  200. for fn in skiplist:
  201. recipe_parts = os.path.splitext(os.path.basename(fn))[0].split('_')
  202. p = recipe_parts[0]
  203. if len(recipe_parts) > 1:
  204. ver = (None, recipe_parts[1], None)
  205. else:
  206. ver = (None, 'unknown', None)
  207. allproviders[p].append((ver, fn))
  208. if not p in pkg_pn:
  209. pkg_pn[p] = 'dummy'
  210. preferred_versions[p] = (ver, fn)
  211. def print_item(f, pn, ver, layer, ispref):
  212. if f in skiplist:
  213. skipped = ' (skipped)'
  214. else:
  215. skipped = ''
  216. if show_filenames:
  217. if ispref:
  218. logger.plain("%s%s", f, skipped)
  219. else:
  220. logger.plain(" %s%s", f, skipped)
  221. else:
  222. if ispref:
  223. logger.plain("%s:", pn)
  224. logger.plain(" %s %s%s", layer.ljust(20), ver, skipped)
  225. preffiles = []
  226. items_listed = False
  227. for p in sorted(pkg_pn):
  228. if pnspec:
  229. if not fnmatch.fnmatch(p, pnspec):
  230. continue
  231. if len(allproviders[p]) > 1 or not show_multi_provider_only:
  232. pref = preferred_versions[p]
  233. preffile = bb.cache.Cache.virtualfn2realfn(pref[1])[0]
  234. if preffile not in preffiles:
  235. preflayer = self.get_file_layer(preffile)
  236. multilayer = False
  237. same_ver = True
  238. provs = []
  239. for prov in allproviders[p]:
  240. provfile = bb.cache.Cache.virtualfn2realfn(prov[1])[0]
  241. provlayer = self.get_file_layer(provfile)
  242. provs.append((provfile, provlayer, prov[0]))
  243. if provlayer != preflayer:
  244. multilayer = True
  245. if prov[0] != pref[0]:
  246. same_ver = False
  247. if (multilayer or not show_overlayed_only) and (same_ver or not show_same_ver_only):
  248. if not items_listed:
  249. logger.plain('=== %s ===' % title)
  250. items_listed = True
  251. print_item(preffile, p, self.version_str(pref[0][0], pref[0][1]), preflayer, True)
  252. for (provfile, provlayer, provver) in provs:
  253. if provfile != preffile:
  254. print_item(provfile, p, self.version_str(provver[0], provver[1]), provlayer, False)
  255. # Ensure we don't show two entries for BBCLASSEXTENDed recipes
  256. preffiles.append(preffile)
  257. return items_listed
  258. def do_flatten(self, args):
  259. """flattens layer configuration into a separate output directory.
  260. usage: flatten [layer1 layer2 [layer3]...] <outputdir>
  261. Takes the specified layers (or all layers in the current layer
  262. configuration if none are specified) and builds a "flattened" directory
  263. containing the contents of all layers, with any overlayed recipes removed
  264. and bbappends appended to the corresponding recipes. Note that some manual
  265. cleanup may still be necessary afterwards, in particular:
  266. * where non-recipe files (such as patches) are overwritten (the flatten
  267. command will show a warning for these)
  268. * where anything beyond the normal layer setup has been added to
  269. layer.conf (only the lowest priority number layer's layer.conf is used)
  270. * overridden/appended items from bbappends will need to be tidied up
  271. * when the flattened layers do not have the same directory structure (the
  272. flatten command should show a warning when this will cause a problem)
  273. Warning: if you flatten several layers where another layer is intended to
  274. be used "inbetween" them (in layer priority order) such that recipes /
  275. bbappends in the layers interact, and then attempt to use the new output
  276. layer together with that other layer, you may no longer get the same
  277. build results (as the layer priority order has effectively changed).
  278. """
  279. arglist = args.split()
  280. if len(arglist) < 1:
  281. logger.error('Please specify an output directory')
  282. self.do_help('flatten')
  283. return
  284. if len(arglist) == 2:
  285. logger.error('If you specify layers to flatten you must specify at least two')
  286. self.do_help('flatten')
  287. return
  288. outputdir = arglist[-1]
  289. if os.path.exists(outputdir) and os.listdir(outputdir):
  290. logger.error('Directory %s exists and is non-empty, please clear it out first' % outputdir)
  291. return
  292. self.bbhandler.prepare()
  293. layers = self.bblayers
  294. if len(arglist) > 2:
  295. layernames = arglist[:-1]
  296. found_layernames = []
  297. found_layerdirs = []
  298. for layerdir in layers:
  299. layername = self.get_layer_name(layerdir)
  300. if layername in layernames:
  301. found_layerdirs.append(layerdir)
  302. found_layernames.append(layername)
  303. for layername in layernames:
  304. if not layername in found_layernames:
  305. logger.error('Unable to find layer %s in current configuration, please run "%s show-layers" to list configured layers' % (layername, os.path.basename(sys.argv[0])))
  306. return
  307. layers = found_layerdirs
  308. else:
  309. layernames = []
  310. # Ensure a specified path matches our list of layers
  311. def layer_path_match(path):
  312. for layerdir in layers:
  313. if path.startswith(os.path.join(layerdir, '')):
  314. return layerdir
  315. return None
  316. appended_recipes = []
  317. for layer in layers:
  318. overlayed = []
  319. for f in self.bbhandler.cooker.overlayed.iterkeys():
  320. for of in self.bbhandler.cooker.overlayed[f]:
  321. if of.startswith(layer):
  322. overlayed.append(of)
  323. logger.plain('Copying files from %s...' % layer )
  324. for root, dirs, files in os.walk(layer):
  325. for f1 in files:
  326. f1full = os.sep.join([root, f1])
  327. if f1full in overlayed:
  328. logger.plain(' Skipping overlayed file %s' % f1full )
  329. else:
  330. ext = os.path.splitext(f1)[1]
  331. if ext != '.bbappend':
  332. fdest = f1full[len(layer):]
  333. fdest = os.path.normpath(os.sep.join([outputdir,fdest]))
  334. bb.utils.mkdirhier(os.path.dirname(fdest))
  335. if os.path.exists(fdest):
  336. if f1 == 'layer.conf' and root.endswith('/conf'):
  337. logger.plain(' Skipping layer config file %s' % f1full )
  338. continue
  339. else:
  340. logger.warn('Overwriting file %s', fdest)
  341. bb.utils.copyfile(f1full, fdest)
  342. if ext == '.bb':
  343. if f1 in self.bbhandler.cooker.appendlist:
  344. appends = self.bbhandler.cooker.appendlist[f1]
  345. if appends:
  346. logger.plain(' Applying appends to %s' % fdest )
  347. for appendname in appends:
  348. if layer_path_match(appendname):
  349. self.apply_append(appendname, fdest)
  350. appended_recipes.append(f1)
  351. # Take care of when some layers are excluded and yet we have included bbappends for those recipes
  352. for recipename in self.bbhandler.cooker.appendlist.iterkeys():
  353. if recipename not in appended_recipes:
  354. appends = self.bbhandler.cooker.appendlist[recipename]
  355. first_append = None
  356. for appendname in appends:
  357. layer = layer_path_match(appendname)
  358. if layer:
  359. if first_append:
  360. self.apply_append(appendname, first_append)
  361. else:
  362. fdest = appendname[len(layer):]
  363. fdest = os.path.normpath(os.sep.join([outputdir,fdest]))
  364. bb.utils.mkdirhier(os.path.dirname(fdest))
  365. bb.utils.copyfile(appendname, fdest)
  366. first_append = fdest
  367. # Get the regex for the first layer in our list (which is where the conf/layer.conf file will
  368. # have come from)
  369. first_regex = None
  370. layerdir = layers[0]
  371. for layername, pattern, regex, _ in self.bbhandler.cooker.recipecache.bbfile_config_priorities:
  372. if regex.match(os.path.join(layerdir, 'test')):
  373. first_regex = regex
  374. break
  375. if first_regex:
  376. # Find the BBFILES entries that match (which will have come from this conf/layer.conf file)
  377. bbfiles = str(self.bbhandler.config_data.getVar('BBFILES', True)).split()
  378. bbfiles_layer = []
  379. for item in bbfiles:
  380. if first_regex.match(item):
  381. newpath = os.path.join(outputdir, item[len(layerdir)+1:])
  382. bbfiles_layer.append(newpath)
  383. if bbfiles_layer:
  384. # Check that all important layer files match BBFILES
  385. for root, dirs, files in os.walk(outputdir):
  386. for f1 in files:
  387. ext = os.path.splitext(f1)[1]
  388. if ext in ['.bb', '.bbappend']:
  389. f1full = os.sep.join([root, f1])
  390. entry_found = False
  391. for item in bbfiles_layer:
  392. if fnmatch.fnmatch(f1full, item):
  393. entry_found = True
  394. break
  395. if not entry_found:
  396. logger.warning("File %s does not match the flattened layer's BBFILES setting, you may need to edit conf/layer.conf or move the file elsewhere" % f1full)
  397. def get_file_layer(self, filename):
  398. for layer, _, regex, _ in self.bbhandler.cooker.recipecache.bbfile_config_priorities:
  399. if regex.match(filename):
  400. for layerdir in self.bblayers:
  401. if regex.match(os.path.join(layerdir, 'test')) and re.match(layerdir, filename):
  402. return self.get_layer_name(layerdir)
  403. return "?"
  404. def get_file_layerdir(self, filename):
  405. for layer, _, regex, _ in self.bbhandler.cooker.recipecache.bbfile_config_priorities:
  406. if regex.match(filename):
  407. for layerdir in self.bblayers:
  408. if regex.match(os.path.join(layerdir, 'test')) and re.match(layerdir, filename):
  409. return layerdir
  410. return "?"
  411. def remove_layer_prefix(self, f):
  412. """Remove the layer_dir prefix, e.g., f = /path/to/layer_dir/foo/blah, the
  413. return value will be: layer_dir/foo/blah"""
  414. f_layerdir = self.get_file_layerdir(f)
  415. prefix = os.path.join(os.path.dirname(f_layerdir), '')
  416. return f[len(prefix):] if f.startswith(prefix) else f
  417. def get_layer_name(self, layerdir):
  418. return os.path.basename(layerdir.rstrip(os.sep))
  419. def apply_append(self, appendname, recipename):
  420. appendfile = open(appendname, 'r')
  421. recipefile = open(recipename, 'a')
  422. recipefile.write('\n')
  423. recipefile.write('##### bbappended from %s #####\n' % self.get_file_layer(appendname))
  424. recipefile.writelines(appendfile.readlines())
  425. recipefile.close()
  426. appendfile.close()
  427. def do_show_appends(self, args):
  428. """list bbappend files and recipe files they apply to
  429. usage: show-appends
  430. Recipes are listed with the bbappends that apply to them as subitems.
  431. """
  432. self.bbhandler.prepare()
  433. if not self.bbhandler.cooker.appendlist:
  434. logger.plain('No append files found')
  435. return
  436. logger.plain('=== Appended recipes ===')
  437. pnlist = list(self.bbhandler.cooker_data.pkg_pn.keys())
  438. pnlist.sort()
  439. for pn in pnlist:
  440. self.show_appends_for_pn(pn)
  441. self.show_appends_for_skipped()
  442. def show_appends_for_pn(self, pn):
  443. filenames = self.bbhandler.cooker_data.pkg_pn[pn]
  444. best = bb.providers.findBestProvider(pn,
  445. self.bbhandler.cooker.configuration.data,
  446. self.bbhandler.cooker_data,
  447. self.bbhandler.cooker_data.pkg_pn)
  448. best_filename = os.path.basename(best[3])
  449. self.show_appends_output(filenames, best_filename)
  450. def show_appends_for_skipped(self):
  451. filenames = [os.path.basename(f)
  452. for f in self.bbhandler.cooker.skiplist.iterkeys()]
  453. self.show_appends_output(filenames, None, " (skipped)")
  454. def show_appends_output(self, filenames, best_filename, name_suffix = ''):
  455. appended, missing = self.get_appends_for_files(filenames)
  456. if appended:
  457. for basename, appends in appended:
  458. logger.plain('%s%s:', basename, name_suffix)
  459. for append in appends:
  460. logger.plain(' %s', append)
  461. if best_filename:
  462. if best_filename in missing:
  463. logger.warn('%s: missing append for preferred version',
  464. best_filename)
  465. self.returncode |= 1
  466. def get_appends_for_files(self, filenames):
  467. appended, notappended = [], []
  468. for filename in filenames:
  469. _, cls = bb.cache.Cache.virtualfn2realfn(filename)
  470. if cls:
  471. continue
  472. basename = os.path.basename(filename)
  473. appends = self.bbhandler.cooker.appendlist.get(basename)
  474. if appends:
  475. appended.append((basename, list(appends)))
  476. else:
  477. notappended.append(basename)
  478. return appended, notappended
  479. def do_show_cross_depends(self, args):
  480. """figure out the dependency between recipes that crosses a layer boundary.
  481. usage: show-cross-depends [-f]
  482. Figure out the dependency between recipes that crosses a layer boundary.
  483. Options:
  484. -f show full file path
  485. NOTE:
  486. The .bbappend file can impact the dependency.
  487. """
  488. self.bbhandler.prepare()
  489. show_filenames = False
  490. for arg in args.split():
  491. if arg == '-f':
  492. show_filenames = True
  493. else:
  494. sys.stderr.write("show-cross-depends: invalid option %s\n" % arg)
  495. self.do_help('')
  496. return
  497. pkg_fn = self.bbhandler.cooker_data.pkg_fn
  498. bbpath = str(self.bbhandler.config_data.getVar('BBPATH', True))
  499. self.require_re = re.compile(r"require\s+(.+)")
  500. self.include_re = re.compile(r"include\s+(.+)")
  501. self.inherit_re = re.compile(r"inherit\s+(.+)")
  502. # The bb's DEPENDS and RDEPENDS
  503. for f in pkg_fn:
  504. f = bb.cache.Cache.virtualfn2realfn(f)[0]
  505. # Get the layername that the file is in
  506. layername = self.get_file_layer(f)
  507. # The DEPENDS
  508. deps = self.bbhandler.cooker_data.deps[f]
  509. for pn in deps:
  510. if pn in self.bbhandler.cooker_data.pkg_pn:
  511. best = bb.providers.findBestProvider(pn,
  512. self.bbhandler.cooker.configuration.data,
  513. self.bbhandler.cooker_data,
  514. self.bbhandler.cooker_data.pkg_pn)
  515. self.check_cross_depends("DEPENDS", layername, f, best[3], show_filenames)
  516. # The RDPENDS
  517. all_rdeps = self.bbhandler.cooker_data.rundeps[f].values()
  518. # Remove the duplicated or null one.
  519. sorted_rdeps = {}
  520. # The all_rdeps is the list in list, so we need two for loops
  521. for k1 in all_rdeps:
  522. for k2 in k1:
  523. sorted_rdeps[k2] = 1
  524. all_rdeps = sorted_rdeps.keys()
  525. for rdep in all_rdeps:
  526. all_p = bb.providers.getRuntimeProviders(self.bbhandler.cooker_data, rdep)
  527. if all_p:
  528. best = bb.providers.filterProvidersRunTime(all_p, rdep,
  529. self.bbhandler.cooker.configuration.data,
  530. self.bbhandler.cooker_data)[0][0]
  531. self.check_cross_depends("RDEPENDS", layername, f, best, show_filenames)
  532. # The inherit class
  533. cls_re = re.compile('classes/')
  534. if f in self.bbhandler.cooker_data.inherits:
  535. inherits = self.bbhandler.cooker_data.inherits[f]
  536. for cls in inherits:
  537. # The inherits' format is [classes/cls, /path/to/classes/cls]
  538. # ignore the classes/cls.
  539. if not cls_re.match(cls):
  540. inherit_layername = self.get_file_layer(cls)
  541. if inherit_layername != layername:
  542. if not show_filenames:
  543. f_short = self.remove_layer_prefix(f)
  544. cls = self.remove_layer_prefix(cls)
  545. else:
  546. f_short = f
  547. logger.plain("%s inherits %s" % (f_short, cls))
  548. # The 'require/include xxx' in the bb file
  549. pv_re = re.compile(r"\${PV}")
  550. fnfile = open(f, 'r')
  551. line = fnfile.readline()
  552. while line:
  553. m, keyword = self.match_require_include(line)
  554. # Found the 'require/include xxxx'
  555. if m:
  556. needed_file = m.group(1)
  557. # Replace the ${PV} with the real PV
  558. if pv_re.search(needed_file) and f in self.bbhandler.cooker_data.pkg_pepvpr:
  559. pv = self.bbhandler.cooker_data.pkg_pepvpr[f][1]
  560. needed_file = re.sub(r"\${PV}", pv, needed_file)
  561. self.print_cross_files(bbpath, keyword, layername, f, needed_file, show_filenames)
  562. line = fnfile.readline()
  563. fnfile.close()
  564. # The "require/include xxx" in conf/machine/*.conf, .inc and .bbclass
  565. conf_re = re.compile(".*/conf/machine/[^\/]*\.conf$")
  566. inc_re = re.compile(".*\.inc$")
  567. # The "inherit xxx" in .bbclass
  568. bbclass_re = re.compile(".*\.bbclass$")
  569. for layerdir in self.bblayers:
  570. layername = self.get_layer_name(layerdir)
  571. for dirpath, dirnames, filenames in os.walk(layerdir):
  572. for name in filenames:
  573. f = os.path.join(dirpath, name)
  574. s = conf_re.match(f) or inc_re.match(f) or bbclass_re.match(f)
  575. if s:
  576. ffile = open(f, 'r')
  577. line = ffile.readline()
  578. while line:
  579. m, keyword = self.match_require_include(line)
  580. # Only bbclass has the "inherit xxx" here.
  581. bbclass=""
  582. if not m and f.endswith(".bbclass"):
  583. m, keyword = self.match_inherit(line)
  584. bbclass=".bbclass"
  585. # Find a 'require/include xxxx'
  586. if m:
  587. self.print_cross_files(bbpath, keyword, layername, f, m.group(1) + bbclass, show_filenames)
  588. line = ffile.readline()
  589. ffile.close()
  590. def print_cross_files(self, bbpath, keyword, layername, f, needed_filename, show_filenames):
  591. """Print the depends that crosses a layer boundary"""
  592. needed_file = bb.utils.which(bbpath, needed_filename)
  593. if needed_file:
  594. # Which layer is this file from
  595. needed_layername = self.get_file_layer(needed_file)
  596. if needed_layername != layername:
  597. if not show_filenames:
  598. f = self.remove_layer_prefix(f)
  599. needed_file = self.remove_layer_prefix(needed_file)
  600. logger.plain("%s %s %s" %(f, keyword, needed_file))
  601. def match_inherit(self, line):
  602. """Match the inherit xxx line"""
  603. return (self.inherit_re.match(line), "inherits")
  604. def match_require_include(self, line):
  605. """Match the require/include xxx line"""
  606. m = self.require_re.match(line)
  607. keyword = "requires"
  608. if not m:
  609. m = self.include_re.match(line)
  610. keyword = "includes"
  611. return (m, keyword)
  612. def check_cross_depends(self, keyword, layername, f, needed_file, show_filenames):
  613. """Print the DEPENDS/RDEPENDS file that crosses a layer boundary"""
  614. best_realfn = bb.cache.Cache.virtualfn2realfn(needed_file)[0]
  615. needed_layername = self.get_file_layer(best_realfn)
  616. if needed_layername != layername:
  617. if not show_filenames:
  618. f = self.remove_layer_prefix(f)
  619. best_realfn = self.remove_layer_prefix(best_realfn)
  620. logger.plain("%s %s %s" % (f, keyword, best_realfn))
  621. if __name__ == '__main__':
  622. sys.exit(main(sys.argv[1:]) or 0)