diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-08-19 14:20:10 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-19 18:05:49 +0100 |
commit | a3967e2ba531fbc4880c5efe8f9d1683428297e2 (patch) | |
tree | 221dcab2fe9a58efa4b46d1f3ce515e50e1825bc /bitbake | |
parent | 22e8c6cbd3070d65741a1fd7f05a40373c236a50 (diff) | |
download | poky-a3967e2ba531fbc4880c5efe8f9d1683428297e2.tar.gz |
bitbake: bitbake-layers: fix mapping files to layers
bitbake-layers needs to map recipe and class files to the layer they
came from within the show-recipes and show-overlayed commands. However,
it turns out that mapping a file to the layer it came from is not as
trivial as it might seem. To do it properly we need to match the path to
an entry in BBFILES then map that to the collection name using
BBFILE_PATTERN, then map that to the actual layer using variable
history. If it doesn't match any entry in BBFILES, then we can fall back
to BBFILE_PATTERN (to handle classes and conf files).
This fixes the layer name not showing up properly in the output of the
show-recipes and show-overlayed commands for recipes in layers such as
meta-intel that have subdirectories in BBFILE_PATTERN. It also fixes the
priority not showing up in show-layers for such layers.
As part of this I've added a function to VariableHistory which for a
space-separated list variable gives you a dict mapping the items added
to the files in which they were added. I've also fixed
bb.utils.get_file_layer() and reduced some of the duplication by using
this function in bitbake-layers. Also fixes the priority not showing up
for layers such as meta-intel
Fixes [YOCTO #8160].
(Bitbake rev: e852f6cabd7489585477ab567a1afeb2252377ac)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rwxr-xr-x | bitbake/bin/bitbake-layers | 37 | ||||
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 25 | ||||
-rw-r--r-- | bitbake/lib/bb/utils.py | 32 |
3 files changed, 65 insertions, 29 deletions
diff --git a/bitbake/bin/bitbake-layers b/bitbake/bin/bitbake-layers index bd05c5f69e..d6db859c3b 100755 --- a/bitbake/bin/bitbake-layers +++ b/bitbake/bin/bitbake-layers | |||
@@ -62,24 +62,22 @@ class Commands(): | |||
62 | 62 | ||
63 | def init_bbhandler(self, config_only = False): | 63 | def init_bbhandler(self, config_only = False): |
64 | if not self.bbhandler: | 64 | if not self.bbhandler: |
65 | self.bbhandler = bb.tinfoil.Tinfoil() | 65 | self.bbhandler = bb.tinfoil.Tinfoil(tracking=True) |
66 | self.bblayers = (self.bbhandler.config_data.getVar('BBLAYERS', True) or "").split() | 66 | self.bblayers = (self.bbhandler.config_data.getVar('BBLAYERS', True) or "").split() |
67 | self.bbhandler.prepare(config_only) | 67 | self.bbhandler.prepare(config_only) |
68 | layerconfs = self.bbhandler.config_data.varhistory.get_variable_items_files('BBFILE_COLLECTIONS', self.bbhandler.config_data) | ||
69 | self.bbfile_collections = {layer: os.path.dirname(os.path.dirname(path)) for layer, path in layerconfs.iteritems()} | ||
70 | |||
68 | 71 | ||
69 | def do_show_layers(self, args): | 72 | def do_show_layers(self, args): |
70 | """show current configured layers""" | 73 | """show current configured layers""" |
71 | self.init_bbhandler(config_only = True) | 74 | self.init_bbhandler(config_only = True) |
72 | logger.plain("%s %s %s" % ("layer".ljust(20), "path".ljust(40), "priority")) | 75 | logger.plain("%s %s %s" % ("layer".ljust(20), "path".ljust(40), "priority")) |
73 | logger.plain('=' * 74) | 76 | logger.plain('=' * 74) |
74 | for layerdir in self.bblayers: | 77 | for layer, _, regex, pri in self.bbhandler.cooker.recipecache.bbfile_config_priorities: |
78 | layerdir = self.bbfile_collections.get(layer, None) | ||
75 | layername = self.get_layer_name(layerdir) | 79 | layername = self.get_layer_name(layerdir) |
76 | layerpri = 0 | 80 | logger.plain("%s %s %d" % (layername.ljust(20), layerdir.ljust(40), pri)) |
77 | for layer, _, regex, pri in self.bbhandler.cooker.recipecache.bbfile_config_priorities: | ||
78 | if regex.match(os.path.join(layerdir, 'test')): | ||
79 | layerpri = pri | ||
80 | break | ||
81 | |||
82 | logger.plain("%s %s %d" % (layername.ljust(20), layerdir.ljust(40), layerpri)) | ||
83 | 81 | ||
84 | 82 | ||
85 | def do_add_layer(self, args): | 83 | def do_add_layer(self, args): |
@@ -682,25 +680,22 @@ build results (as the layer priority order has effectively changed). | |||
682 | 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) | 680 | 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) |
683 | 681 | ||
684 | def get_file_layer(self, filename): | 682 | def get_file_layer(self, filename): |
685 | for layer, _, regex, _ in self.bbhandler.cooker.recipecache.bbfile_config_priorities: | 683 | layerdir = self.get_file_layerdir(filename) |
686 | if regex.match(filename): | 684 | if layerdir: |
687 | for layerdir in self.bblayers: | 685 | return self.get_layer_name(layerdir) |
688 | if regex.match(os.path.join(layerdir, 'test')) and re.match(layerdir, filename): | 686 | else: |
689 | return self.get_layer_name(layerdir) | 687 | return '?' |
690 | return "?" | ||
691 | 688 | ||
692 | def get_file_layerdir(self, filename): | 689 | def get_file_layerdir(self, filename): |
693 | for layer, _, regex, _ in self.bbhandler.cooker.recipecache.bbfile_config_priorities: | 690 | layer = bb.utils.get_file_layer(filename, self.bbhandler.config_data) |
694 | if regex.match(filename): | 691 | return self.bbfile_collections.get(layer, None) |
695 | for layerdir in self.bblayers: | ||
696 | if regex.match(os.path.join(layerdir, 'test')) and re.match(layerdir, filename): | ||
697 | return layerdir | ||
698 | return "?" | ||
699 | 692 | ||
700 | def remove_layer_prefix(self, f): | 693 | def remove_layer_prefix(self, f): |
701 | """Remove the layer_dir prefix, e.g., f = /path/to/layer_dir/foo/blah, the | 694 | """Remove the layer_dir prefix, e.g., f = /path/to/layer_dir/foo/blah, the |
702 | return value will be: layer_dir/foo/blah""" | 695 | return value will be: layer_dir/foo/blah""" |
703 | f_layerdir = self.get_file_layerdir(f) | 696 | f_layerdir = self.get_file_layerdir(f) |
697 | if not f_layerdir: | ||
698 | return f | ||
704 | prefix = os.path.join(os.path.dirname(f_layerdir), '') | 699 | prefix = os.path.join(os.path.dirname(f_layerdir), '') |
705 | return f[len(prefix):] if f.startswith(prefix) else f | 700 | return f[len(prefix):] if f.startswith(prefix) else f |
706 | 701 | ||
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index 26f69d105a..75e22f9c45 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -312,6 +312,31 @@ class VariableHistory(object): | |||
312 | lines.append(line) | 312 | lines.append(line) |
313 | return lines | 313 | return lines |
314 | 314 | ||
315 | def get_variable_items_files(self, var, d): | ||
316 | """ | ||
317 | Use variable history to map items added to a list variable and | ||
318 | the files in which they were added. | ||
319 | """ | ||
320 | history = self.variable(var) | ||
321 | finalitems = (d.getVar(var, True) or '').split() | ||
322 | filemap = {} | ||
323 | isset = False | ||
324 | for event in history: | ||
325 | if 'flag' in event: | ||
326 | continue | ||
327 | if event['op'] == '_remove': | ||
328 | continue | ||
329 | if isset and event['op'] == 'set?': | ||
330 | continue | ||
331 | isset = True | ||
332 | items = d.expand(event['detail']).split() | ||
333 | for item in items: | ||
334 | # This is a little crude but is belt-and-braces to avoid us | ||
335 | # having to handle every possible operation type specifically | ||
336 | if item in finalitems and not item in filemap: | ||
337 | filemap[item] = event['file'] | ||
338 | return filemap | ||
339 | |||
315 | def del_var_history(self, var, f=None, line=None): | 340 | def del_var_history(self, var, f=None, line=None): |
316 | """If file f and line are not given, the entire history of var is deleted""" | 341 | """If file f and line are not given, the entire history of var is deleted""" |
317 | if var in self.variables: | 342 | if var in self.variables: |
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 607ffc5065..5b94432b37 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -29,6 +29,7 @@ import multiprocessing | |||
29 | import fcntl | 29 | import fcntl |
30 | import subprocess | 30 | import subprocess |
31 | import glob | 31 | import glob |
32 | import fnmatch | ||
32 | import traceback | 33 | import traceback |
33 | import errno | 34 | import errno |
34 | import signal | 35 | import signal |
@@ -1262,11 +1263,26 @@ def get_file_layer(filename, d): | |||
1262 | for collection in collections: | 1263 | for collection in collections: |
1263 | collection_res[collection] = d.getVar('BBFILE_PATTERN_%s' % collection, True) or '' | 1264 | collection_res[collection] = d.getVar('BBFILE_PATTERN_%s' % collection, True) or '' |
1264 | 1265 | ||
1265 | # Use longest path so we handle nested layers | 1266 | def path_to_layer(path): |
1266 | matchlen = 0 | 1267 | # Use longest path so we handle nested layers |
1267 | match = None | 1268 | matchlen = 0 |
1268 | for collection, regex in collection_res.iteritems(): | 1269 | match = None |
1269 | if len(regex) > matchlen and re.match(regex, filename): | 1270 | for collection, regex in collection_res.iteritems(): |
1270 | matchlen = len(regex) | 1271 | if len(regex) > matchlen and re.match(regex, path): |
1271 | match = collection | 1272 | matchlen = len(regex) |
1272 | return match | 1273 | match = collection |
1274 | return match | ||
1275 | |||
1276 | result = None | ||
1277 | bbfiles = (d.getVar('BBFILES', True) or '').split() | ||
1278 | bbfilesmatch = False | ||
1279 | for bbfilesentry in bbfiles: | ||
1280 | if fnmatch.fnmatch(filename, bbfilesentry): | ||
1281 | bbfilesmatch = True | ||
1282 | result = path_to_layer(bbfilesentry) | ||
1283 | |||
1284 | if not bbfilesmatch: | ||
1285 | # Probably a bbclass | ||
1286 | result = path_to_layer(filename) | ||
1287 | |||
1288 | return result | ||