diff mbox series

meta/classes/create-spdx.bbclass: support to inherit SPDX class conditionally

Message ID 20241227061111.2086879-1-hongxu.jia@windriver.com
State New
Headers show
Series meta/classes/create-spdx.bbclass: support to inherit SPDX class conditionally | expand

Commit Message

Hongxu Jia Dec. 27, 2024, 6:11 a.m. UTC
In order to inherit SPDX class conditionally, using variable ${SPDX_CLASS}
to inherit SPDX class other than original 'INHERIT:remove = "create-spdx"'
and INHERIT += "create-spdx-2.2"

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/classes/create-spdx.bbclass     | 3 ++-
 meta/lib/oeqa/selftest/cases/spdx.py | 8 ++------
 2 files changed, 4 insertions(+), 7 deletions(-)

Comments

Joshua Watt Jan. 7, 2025, 4:44 p.m. UTC | #1
Reviewed-by: Joshua Watt <JPEWhacker@gmail.com>

On Thu, Dec 26, 2024 at 11:11 PM Hongxu Jia <hongxu.jia@windriver.com> wrote:
>
> In order to inherit SPDX class conditionally, using variable ${SPDX_CLASS}
> to inherit SPDX class other than original 'INHERIT:remove = "create-spdx"'
> and INHERIT += "create-spdx-2.2"
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/classes/create-spdx.bbclass     | 3 ++-
>  meta/lib/oeqa/selftest/cases/spdx.py | 8 ++------
>  2 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
> index b604973ae0..35cd63f31e 100644
> --- a/meta/classes/create-spdx.bbclass
> +++ b/meta/classes/create-spdx.bbclass
> @@ -5,4 +5,5 @@
>  #
>  # Include this class when you don't care what version of SPDX you get; it will
>  # be updated to the latest stable version that is supported
> -inherit create-spdx-3.0
> +SPDX_CLASS ??= "create-spdx-3.0"
> +inherit ${SPDX_CLASS}
> diff --git a/meta/lib/oeqa/selftest/cases/spdx.py b/meta/lib/oeqa/selftest/cases/spdx.py
> index f3b955ed2b..4789041a6a 100644
> --- a/meta/lib/oeqa/selftest/cases/spdx.py
> +++ b/meta/lib/oeqa/selftest/cases/spdx.py
> @@ -24,8 +24,7 @@ class SPDX22Check(OESelftestTestCase):
>      def check_recipe_spdx(self, high_level_dir, spdx_file, target_name):
>          config = textwrap.dedent(
>              """\
> -            INHERIT:remove = "create-spdx"
> -            INHERIT += "create-spdx-2.2"
> +            SPDX_CLASS = "create-spdx-2.2"
>              """
>          )
>          self.write_config(config)
> @@ -89,8 +88,7 @@ class SPDX3CheckBase(object):
>          config = (
>              textwrap.dedent(
>                  f"""\
> -                INHERIT:remove = "create-spdx"
> -                INHERIT += "{self.SPDX_CLASS}"
> +                SPDX_CLASS = "create-spdx-3.0"
>                  """
>              )
>              + textwrap.dedent(extraconf)
> @@ -138,8 +136,6 @@ class SPDX3CheckBase(object):
>
>
>  class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
> -    SPDX_CLASS = "create-spdx-3.0"
> -
>      def test_base_files(self):
>          self.check_recipe_spdx(
>              "base-files",
> --
> 2.25.1
>
Richard Purdie Jan. 8, 2025, 12:48 p.m. UTC | #2
On Thu, 2024-12-26 at 22:11 -0800, hongxu via lists.openembedded.org wrote:
> In order to inherit SPDX class conditionally, using variable ${SPDX_CLASS}
> to inherit SPDX class other than original 'INHERIT:remove = "create-spdx"'
> and INHERIT += "create-spdx-2.2"
> 
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/classes/create-spdx.bbclass     | 3 ++-
>  meta/lib/oeqa/selftest/cases/spdx.py | 8 ++------
>  2 files changed, 4 insertions(+), 7 deletions(-)

I don't really want to add more variables to control inherits like
this, in most of these scenarios you'd be setting up your own choice of
classes in your distro anyway. We can't have a variable for every
single possible choice.

Cheers,

Richard
hongxu Jan. 8, 2025, 3:40 p.m. UTC | #3
Understood, thanks for pointing it out

//Hongxu
diff mbox series

Patch

diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index b604973ae0..35cd63f31e 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -5,4 +5,5 @@ 
 #
 # Include this class when you don't care what version of SPDX you get; it will
 # be updated to the latest stable version that is supported
-inherit create-spdx-3.0
+SPDX_CLASS ??= "create-spdx-3.0"
+inherit ${SPDX_CLASS}
diff --git a/meta/lib/oeqa/selftest/cases/spdx.py b/meta/lib/oeqa/selftest/cases/spdx.py
index f3b955ed2b..4789041a6a 100644
--- a/meta/lib/oeqa/selftest/cases/spdx.py
+++ b/meta/lib/oeqa/selftest/cases/spdx.py
@@ -24,8 +24,7 @@  class SPDX22Check(OESelftestTestCase):
     def check_recipe_spdx(self, high_level_dir, spdx_file, target_name):
         config = textwrap.dedent(
             """\
-            INHERIT:remove = "create-spdx"
-            INHERIT += "create-spdx-2.2"
+            SPDX_CLASS = "create-spdx-2.2"
             """
         )
         self.write_config(config)
@@ -89,8 +88,7 @@  class SPDX3CheckBase(object):
         config = (
             textwrap.dedent(
                 f"""\
-                INHERIT:remove = "create-spdx"
-                INHERIT += "{self.SPDX_CLASS}"
+                SPDX_CLASS = "create-spdx-3.0"
                 """
             )
             + textwrap.dedent(extraconf)
@@ -138,8 +136,6 @@  class SPDX3CheckBase(object):
 
 
 class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
-    SPDX_CLASS = "create-spdx-3.0"
-
     def test_base_files(self):
         self.check_recipe_spdx(
             "base-files",