[v2,10/26] sdk.py: Dynamic load of sdk

Submitted by Fredrik Gustafsson on June 25, 2020, 10:21 a.m. | Patch ID: 173893

Details

Message ID 20200625102145.7139-11-fredrigu@axis.com
State New
Headers show

Commit Message

Fredrik Gustafsson June 25, 2020, 10:21 a.m.
Decide which sdk we should load in run time without any hard coded
values but look at which package type that is used.

Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
---
 meta/lib/oe/package_managers/deb/sdk.py |  4 ++--
 meta/lib/oe/package_managers/ipk/sdk.py |  4 ++--
 meta/lib/oe/package_managers/rpm/sdk.py |  4 ++--
 meta/lib/oe/sdk.py                      | 13 ++-----------
 4 files changed, 8 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/lib/oe/package_managers/deb/sdk.py b/meta/lib/oe/package_managers/deb/sdk.py
index 154ec5ab17..950455988a 100644
--- a/meta/lib/oe/package_managers/deb/sdk.py
+++ b/meta/lib/oe/package_managers/deb/sdk.py
@@ -5,9 +5,9 @@ 
 from oe.sdk import *
 from oe.package_managers.deb.manifest import *
 
-class DpkgSdk(Sdk):
+class PkgSdk(Sdk):
     def __init__(self, d, manifest_dir=None):
-        super(DpkgSdk, self).__init__(d, manifest_dir)
+        super(PkgSdk, self).__init__(d, manifest_dir)
 
         self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
         self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
diff --git a/meta/lib/oe/package_managers/ipk/sdk.py b/meta/lib/oe/package_managers/ipk/sdk.py
index 4862616c08..bd7bab6ebe 100644
--- a/meta/lib/oe/package_managers/ipk/sdk.py
+++ b/meta/lib/oe/package_managers/ipk/sdk.py
@@ -5,9 +5,9 @@ 
 from oe.sdk import *
 from oe.package_managers.ipk.manifest import *
 
-class OpkgSdk(Sdk):
+class PkgSdk(Sdk):
     def __init__(self, d, manifest_dir=None):
-        super(OpkgSdk, self).__init__(d, manifest_dir)
+        super(PkgSdk, self).__init__(d, manifest_dir)
 
         self.target_conf = self.d.getVar("IPKGCONF_TARGET")
         self.host_conf = self.d.getVar("IPKGCONF_SDK")
diff --git a/meta/lib/oe/package_managers/rpm/sdk.py b/meta/lib/oe/package_managers/rpm/sdk.py
index fc120b6171..d2f7447657 100644
--- a/meta/lib/oe/package_managers/rpm/sdk.py
+++ b/meta/lib/oe/package_managers/rpm/sdk.py
@@ -5,9 +5,9 @@ 
 from oe.sdk import *
 from oe.package_managers.rpm.manifest import *
 
-class RpmSdk(Sdk):
+class PkgSdk(Sdk):
     def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"):
-        super(RpmSdk, self).__init__(d, manifest_dir)
+        super(PkgSdk, self).__init__(d, manifest_dir)
 
         self.target_manifest = PkgManifest(d, self.manifest_dir,
                                            Manifest.MANIFEST_TYPE_SDK_TARGET)
diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py
index d8a00c04d1..3b7869f071 100644
--- a/meta/lib/oe/sdk.py
+++ b/meta/lib/oe/sdk.py
@@ -130,17 +130,8 @@  def sdk_list_installed_packages(d, target, rootfs_dir=None):
 def populate_sdk(d, manifest_dir=None):
     env_bkp = os.environ.copy()
 
-    img_type = d.getVar('IMAGE_PKGTYPE')
-
-    from oe.package_managers.rpm.sdk import RpmSdk
-    from oe.package_managers.ipk.sdk import OpkgSdk
-    from oe.package_managers.deb.sdk import DpkgSdk
-    if img_type == "rpm":
-        RpmSdk(d, manifest_dir).populate()
-    elif img_type == "ipk":
-        OpkgSdk(d, manifest_dir).populate()
-    elif img_type == "deb":
-        DpkgSdk(d, manifest_dir).populate()
+    import importlib
+    importlib.import_module('oe.package_managers.' + d.getVar('IMAGE_PKGTYPE') + '.sdk').PkgSdk(d, manifest_dir).populate()
 
     os.environ.clear()
     os.environ.update(env_bkp)

Comments

Paul Barker June 25, 2020, 10:41 a.m.
On Thu, 25 Jun 2020 at 11:22, Fredrik Gustafsson
<fredrik.gustafsson@axis.com> wrote:
>
> Decide which sdk we should load in run time without any hard coded
> values but look at which package type that is used.
>
> Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
> ---
>  meta/lib/oe/package_managers/deb/sdk.py |  4 ++--
>  meta/lib/oe/package_managers/ipk/sdk.py |  4 ++--
>  meta/lib/oe/package_managers/rpm/sdk.py |  4 ++--
>  meta/lib/oe/sdk.py                      | 13 ++-----------
>  4 files changed, 8 insertions(+), 17 deletions(-)
>
> diff --git a/meta/lib/oe/package_managers/deb/sdk.py b/meta/lib/oe/package_managers/deb/sdk.py
> index 154ec5ab17..950455988a 100644
> --- a/meta/lib/oe/package_managers/deb/sdk.py
> +++ b/meta/lib/oe/package_managers/deb/sdk.py
> @@ -5,9 +5,9 @@
>  from oe.sdk import *
>  from oe.package_managers.deb.manifest import *
>
> -class DpkgSdk(Sdk):
> +class PkgSdk(Sdk):
>      def __init__(self, d, manifest_dir=None):
> -        super(DpkgSdk, self).__init__(d, manifest_dir)
> +        super(PkgSdk, self).__init__(d, manifest_dir)
>
>          self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
>          self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
> diff --git a/meta/lib/oe/package_managers/ipk/sdk.py b/meta/lib/oe/package_managers/ipk/sdk.py
> index 4862616c08..bd7bab6ebe 100644
> --- a/meta/lib/oe/package_managers/ipk/sdk.py
> +++ b/meta/lib/oe/package_managers/ipk/sdk.py
> @@ -5,9 +5,9 @@
>  from oe.sdk import *
>  from oe.package_managers.ipk.manifest import *
>
> -class OpkgSdk(Sdk):
> +class PkgSdk(Sdk):
>      def __init__(self, d, manifest_dir=None):
> -        super(OpkgSdk, self).__init__(d, manifest_dir)
> +        super(PkgSdk, self).__init__(d, manifest_dir)
>
>          self.target_conf = self.d.getVar("IPKGCONF_TARGET")
>          self.host_conf = self.d.getVar("IPKGCONF_SDK")
> diff --git a/meta/lib/oe/package_managers/rpm/sdk.py b/meta/lib/oe/package_managers/rpm/sdk.py
> index fc120b6171..d2f7447657 100644
> --- a/meta/lib/oe/package_managers/rpm/sdk.py
> +++ b/meta/lib/oe/package_managers/rpm/sdk.py
> @@ -5,9 +5,9 @@
>  from oe.sdk import *
>  from oe.package_managers.rpm.manifest import *
>
> -class RpmSdk(Sdk):
> +class PkgSdk(Sdk):
>      def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"):
> -        super(RpmSdk, self).__init__(d, manifest_dir)
> +        super(PkgSdk, self).__init__(d, manifest_dir)
>
>          self.target_manifest = PkgManifest(d, self.manifest_dir,
>                                             Manifest.MANIFEST_TYPE_SDK_TARGET)
> diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py
> index d8a00c04d1..3b7869f071 100644
> --- a/meta/lib/oe/sdk.py
> +++ b/meta/lib/oe/sdk.py
> @@ -130,17 +130,8 @@ def sdk_list_installed_packages(d, target, rootfs_dir=None):
>  def populate_sdk(d, manifest_dir=None):
>      env_bkp = os.environ.copy()
>
> -    img_type = d.getVar('IMAGE_PKGTYPE')
> -
> -    from oe.package_managers.rpm.sdk import RpmSdk
> -    from oe.package_managers.ipk.sdk import OpkgSdk
> -    from oe.package_managers.deb.sdk import DpkgSdk
> -    if img_type == "rpm":
> -        RpmSdk(d, manifest_dir).populate()
> -    elif img_type == "ipk":
> -        OpkgSdk(d, manifest_dir).populate()
> -    elif img_type == "deb":
> -        DpkgSdk(d, manifest_dir).populate()
> +    import importlib
> +    importlib.import_module('oe.package_managers.' + d.getVar('IMAGE_PKGTYPE') + '.sdk').PkgSdk(d, manifest_dir).populate()
>
>      os.environ.clear()
>      os.environ.update(env_bkp)

See my comments on the patch to add dynamic loading of the manifest
class - the same comments apply here.


--
Paul Barker
Konsulko Group
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#139942): https://lists.openembedded.org/g/openembedded-core/message/139942
Mute This Topic: https://lists.openembedded.org/mt/75100001/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-