[master,kirkstone,3/5] lib/oe/utils: create get_current_recipe_layer function

Message ID 20220628133713.3390786-3-davide.gardenal@huawei.com
State New, archived
Headers show
Series [master,kirkstone,1/5] lib/oe/cve_check: refactor update_symlinks with safer version | expand

Commit Message

Davide Gardenal June 28, 2022, 1:37 p.m. UTC
get_current_recipe_layer returns the recipe layer given its
file path.

Signed-off-by: Davide Gardenal <davide.gardenal@huawei.com>
---
 meta/lib/oe/utils.py | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Jose Quaresma June 28, 2022, 10:16 p.m. UTC | #1
Hi Davide,

Davide Gardenal <davidegarde2000@gmail.com> escreveu no dia terça,
28/06/2022 à(s) 14:38:

> get_current_recipe_layer returns the recipe layer given its
> file path.
>
> Signed-off-by: Davide Gardenal <davide.gardenal@huawei.com>
> ---
>  meta/lib/oe/utils.py | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
> index 46fc76c261..4e17b1b40e 100644
> --- a/meta/lib/oe/utils.py
> +++ b/meta/lib/oe/utils.py
> @@ -584,3 +584,11 @@ def directory_size(root, blocksize=4096):
>          total += sum(roundup(getsize(os.path.join(root, name))) for name
> in files)
>          total += roundup(getsize(root))
>      return total
> +
> +def get_current_recipe_layer(d):
> +    """
> +    Extract the recipe layer from it's path.
> +    Returns the layer name.
> +    """
> +    fdir_name  = d.getVar("FILE_DIRNAME")
> +    return fdir_name.split("/")[-3]
>

This doesn't seem very safe as you are assuming that all layers use the
same directory structure for placing the recipes.
So for example dynamic layer will not work with this patch.

Jose


> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#167341):
> https://lists.openembedded.org/g/openembedded-core/message/167341
> Mute This Topic: https://lists.openembedded.org/mt/92043904/5052612
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> quaresma.jose@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>

Patch

diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 46fc76c261..4e17b1b40e 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -584,3 +584,11 @@  def directory_size(root, blocksize=4096):
         total += sum(roundup(getsize(os.path.join(root, name))) for name in files)
         total += roundup(getsize(root))
     return total
+
+def get_current_recipe_layer(d):
+    """
+    Extract the recipe layer from it's path.
+    Returns the layer name.
+    """
+    fdir_name  = d.getVar("FILE_DIRNAME")
+    return fdir_name.split("/")[-3]