From ca6ef30c7a33b3860d9b0d0da51d9b8786073170 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Fri, 22 May 2015 16:42:21 +0100 Subject: bitbake: lib/bb/utils: add function to get layer containing a file In certain contexts it can be useful to find the layer that a file (e.g. a recipe) appears in. Implements [YOCTO #7723]. (Bitbake master rev: 3bf9c8830c5d5eea5502230d5af84ebd87ad5849) (Bitbake rev: 8dcd83e5edb1cf3307b610d3bb8d54733ea7356d) Signed-off-by: Paul Eggleton Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'bitbake') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index c97f3ef81f..1681efd7e5 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -1097,3 +1097,19 @@ def edit_bblayers_conf(bblayers_conf, add, remove): return (notadded, notremoved) + +def get_file_layer(filename, d): + """Determine the collection (as defined by a layer's layer.conf file) containing the specified file""" + collections = (d.getVar('BBFILE_COLLECTIONS', True) or '').split() + collection_res = {} + for collection in collections: + collection_res[collection] = d.getVar('BBFILE_PATTERN_%s' % collection, True) or '' + + # Use longest path so we handle nested layers + matchlen = 0 + match = None + for collection, regex in collection_res.iteritems(): + if len(regex) > matchlen and re.match(regex, filename): + matchlen = len(regex) + match = collection + return match -- cgit v1.2.3-54-g00ecf