Message ID | AM9PR09MB4642AFAD1E3DA5F9022D3C1EA8769@AM9PR09MB4642.eurprd09.prod.outlook.com |
---|---|
State | New |
Headers | show |
Series | [meta-oe,RFC,v2,1/2] oe.lib.recipeutils: add get_layer_name method | expand |
On Wed, 2021-12-15 at 13:12 +0100, Konrad Weihmann wrote: > so one can get the layer name from a filepath > > Signed-off-by: Konrad Weihmann <kweihmann@outlook.com> > --- > v2: order by path length to correctly map nested layer > > meta/lib/oe/recipeutils.py | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py > index a0c6974f04..557e0f9bd5 100644 > --- a/meta/lib/oe/recipeutils.py > +++ b/meta/lib/oe/recipeutils.py > @@ -21,7 +21,7 @@ import glob > import bb.tinfoil > > from collections import OrderedDict, defaultdict > -from bb.utils import vercmp_string > +from bb.utils import vercmp_string, get_collection_res > > # Help us to find places to insert values > recipe_progression = ['SUMMARY', 'DESCRIPTION', 'AUTHOR', 'HOMEPAGE', 'BUGTRACKER', 'SECTION', 'LICENSE', 'LICENSE_FLAGS', 'LIC_FILES_CHKSUM', 'PROVIDES', 'DEPENDS', 'PR', 'PV', 'SRCREV', 'SRCPV', 'SRC_URI', 'S', 'do_fetch()', 'do_unpack()', 'do_patch()', 'EXTRA_OECONF', 'EXTRA_OECMAKE', 'EXTRA_OESCONS', 'do_configure()', 'EXTRA_OEMAKE', 'do_compile()', 'do_install()', 'do_populate_sysroot()', 'INITSCRIPT', 'USERADD', 'GROUPADD', 'PACKAGES', 'FILES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RPROVIDES', 'RREPLACES', 'RCONFLICTS', 'ALLOW_EMPTY', 'populate_packages()', 'do_package()', 'do_deploy()', 'BBCLASSEXTEND'] > @@ -928,6 +928,15 @@ def find_layerdir(fn): > return None > return layerdir > > +def get_layer_name(fn, d): > + """ Get the layer name from a filename """ > + pth = os.path.abspath(fn) > + collection = get_collection_res(d) > + # reverse ordering by length to catch nested layers > + for k, v in dict(sorted(collection.items(), key=lambda item: len(item[1]), reverse=True)).items(): > + if re.match(v, pth): > + return k > + return "" > > def replace_dir_vars(path, d): > """Replace common directory paths with appropriate variable references (e.g. /etc becomes ${sysconfdir})""" I suspect we should add something in bb.utils for this? I also think we should probably do this at the bitbake level entirely, i.e. set some kind of variable to the layername rather than having lots of metadata code trying to do it, potentially badly? Cheers, Richard
On 16.12.21 15:41, Richard Purdie wrote: > On Wed, 2021-12-15 at 13:12 +0100, Konrad Weihmann wrote: >> so one can get the layer name from a filepath >> >> Signed-off-by: Konrad Weihmann <kweihmann@outlook.com> >> --- >> v2: order by path length to correctly map nested layer >> >> meta/lib/oe/recipeutils.py | 11 ++++++++++- >> 1 file changed, 10 insertions(+), 1 deletion(-) >> >> diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py >> index a0c6974f04..557e0f9bd5 100644 >> --- a/meta/lib/oe/recipeutils.py >> +++ b/meta/lib/oe/recipeutils.py >> @@ -21,7 +21,7 @@ import glob >> import bb.tinfoil >> >> from collections import OrderedDict, defaultdict >> -from bb.utils import vercmp_string >> +from bb.utils import vercmp_string, get_collection_res >> >> # Help us to find places to insert values >> recipe_progression = ['SUMMARY', 'DESCRIPTION', 'AUTHOR', 'HOMEPAGE', 'BUGTRACKER', 'SECTION', 'LICENSE', 'LICENSE_FLAGS', 'LIC_FILES_CHKSUM', 'PROVIDES', 'DEPENDS', 'PR', 'PV', 'SRCREV', 'SRCPV', 'SRC_URI', 'S', 'do_fetch()', 'do_unpack()', 'do_patch()', 'EXTRA_OECONF', 'EXTRA_OECMAKE', 'EXTRA_OESCONS', 'do_configure()', 'EXTRA_OEMAKE', 'do_compile()', 'do_install()', 'do_populate_sysroot()', 'INITSCRIPT', 'USERADD', 'GROUPADD', 'PACKAGES', 'FILES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RPROVIDES', 'RREPLACES', 'RCONFLICTS', 'ALLOW_EMPTY', 'populate_packages()', 'do_package()', 'do_deploy()', 'BBCLASSEXTEND'] >> @@ -928,6 +928,15 @@ def find_layerdir(fn): >> return None >> return layerdir >> >> +def get_layer_name(fn, d): >> + """ Get the layer name from a filename """ >> + pth = os.path.abspath(fn) >> + collection = get_collection_res(d) >> + # reverse ordering by length to catch nested layers >> + for k, v in dict(sorted(collection.items(), key=lambda item: len(item[1]), reverse=True)).items(): >> + if re.match(v, pth): >> + return k >> + return "" >> >> def replace_dir_vars(path, d): >> """Replace common directory paths with appropriate variable references (e.g. /etc becomes ${sysconfdir})""" > > > I suspect we should add something in bb.utils for this? I also think we should > probably do this at the bitbake level entirely, i.e. set some kind of variable > to the layername rather than having lots of metadata code trying to do it, > potentially badly? That would indeed make sense, in the end the could be easily moved to bitbake - not sure about the variable per layer as we have already BBFILE_PATTERN and BBCOLLECTION (both used here indirectly) and what I wanted to have is a way to ask from what layer a particular file originates. In the current form it's pretty straight forward as it doesn't mind overloads from layers (and therefore no layer priority or order from bblayers.conf) - I'm not sure how complicated we would like something like this to be - so for now I would be fine if we take this piece, add something fully featured in bitbake and then removed this one here > > Cheers, > > Richard > >
diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py index a0c6974f04..557e0f9bd5 100644 --- a/meta/lib/oe/recipeutils.py +++ b/meta/lib/oe/recipeutils.py @@ -21,7 +21,7 @@ import glob import bb.tinfoil from collections import OrderedDict, defaultdict -from bb.utils import vercmp_string +from bb.utils import vercmp_string, get_collection_res # Help us to find places to insert values recipe_progression = ['SUMMARY', 'DESCRIPTION', 'AUTHOR', 'HOMEPAGE', 'BUGTRACKER', 'SECTION', 'LICENSE', 'LICENSE_FLAGS', 'LIC_FILES_CHKSUM', 'PROVIDES', 'DEPENDS', 'PR', 'PV', 'SRCREV', 'SRCPV', 'SRC_URI', 'S', 'do_fetch()', 'do_unpack()', 'do_patch()', 'EXTRA_OECONF', 'EXTRA_OECMAKE', 'EXTRA_OESCONS', 'do_configure()', 'EXTRA_OEMAKE', 'do_compile()', 'do_install()', 'do_populate_sysroot()', 'INITSCRIPT', 'USERADD', 'GROUPADD', 'PACKAGES', 'FILES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RPROVIDES', 'RREPLACES', 'RCONFLICTS', 'ALLOW_EMPTY', 'populate_packages()', 'do_package()', 'do_deploy()', 'BBCLASSEXTEND'] @@ -928,6 +928,15 @@ def find_layerdir(fn): return None return layerdir +def get_layer_name(fn, d): + """ Get the layer name from a filename """ + pth = os.path.abspath(fn) + collection = get_collection_res(d) + # reverse ordering by length to catch nested layers + for k, v in dict(sorted(collection.items(), key=lambda item: len(item[1]), reverse=True)).items(): + if re.match(v, pth): + return k + return "" def replace_dir_vars(path, d): """Replace common directory paths with appropriate variable references (e.g. /etc becomes ${sysconfdir})"""
so one can get the layer name from a filepath Signed-off-by: Konrad Weihmann <kweihmann@outlook.com> --- v2: order by path length to correctly map nested layer meta/lib/oe/recipeutils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)