[meta-oe,RFC,1/2] oe.lib.recipeutils: add get_layer_name method

Message ID AM9PR09MB4642028BF93F66BFD3BD68D6A8769@AM9PR09MB4642.eurprd09.prod.outlook.com
State New
Headers show
Series [meta-oe,RFC,1/2] oe.lib.recipeutils: add get_layer_name method | expand

Commit Message

Konrad Weihmann Dec. 15, 2021, 10:03 a.m. UTC
so one can get the layer name from a filepath

Signed-off-by: Konrad Weihmann <kweihmann@outlook.com>
---
 meta/lib/oe/recipeutils.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Patch

diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py
index a0c6974f04..a0e8840c8f 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,14 @@  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)
+    for k, v in dict(sorted(collection.items(), key=lambda item: 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})"""