[2/5] create_npm: reuse ensure_native_cmd from create.py

Message ID 20220506065917.1375-2-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series [1/5] recipetool-create: add ensure_native_cmd function | expand

Commit Message

Stefan Herbrechtsmeier May 6, 2022, 6:59 a.m. UTC
From: Lukas Funke <lukas.funke@weidmueller.com>

Signed-off-by: Lukas Funke <lukas.funke@weidmueller.com>
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 scripts/lib/recipetool/create_npm.py | 28 ++--------------------------
 1 file changed, 2 insertions(+), 26 deletions(-)

Patch

diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py
index 3394a89970..3aed59252c 100644
--- a/scripts/lib/recipetool/create_npm.py
+++ b/scripts/lib/recipetool/create_npm.py
@@ -18,6 +18,7 @@  from recipetool.create import RecipeHandler
 from recipetool.create import get_license_md5sums
 from recipetool.create import guess_license
 from recipetool.create import split_pkg_licenses
+from recipetool.create import ensure_native_cmd
 logger = logging.getLogger('recipetool')
 
 TINFOIL = None
@@ -54,31 +55,6 @@  class NpmRecipeHandler(RecipeHandler):
 
         return registry
 
-    @staticmethod
-    def _ensure_npm():
-        """Check if the 'npm' command is available in the recipes"""
-        if not TINFOIL.recipes_parsed:
-            TINFOIL.parse_recipes()
-
-        try:
-            d = TINFOIL.parse_recipe("nodejs-native")
-        except bb.providers.NoProvider:
-            bb.error("Nothing provides 'nodejs-native' which is required for the build")
-            bb.note("You will likely need to add a layer that provides nodejs")
-            sys.exit(14)
-
-        bindir = d.getVar("STAGING_BINDIR_NATIVE")
-        npmpath = os.path.join(bindir, "npm")
-
-        if not os.path.exists(npmpath):
-            TINFOIL.build_targets("nodejs-native", "addto_recipe_sysroot")
-
-            if not os.path.exists(npmpath):
-                bb.error("Failed to add 'npm' to sysroot")
-                sys.exit(14)
-
-        return bindir
-
     @staticmethod
     def _npm_global_configs(dev):
         """Get the npm global configuration"""
@@ -190,7 +166,7 @@  class NpmRecipeHandler(RecipeHandler):
         # npm version is high enough to ensure an efficient dependency tree
         # resolution and avoid issue with the shrinkwrap file format.
         # Moreover the native npm is mandatory for the build.
-        bindir = self._ensure_npm()
+        bindir = ensure_native_cmd(TINFOIL, "npm")
 
         d = bb.data.createCopy(TINFOIL.config_data)
         d.prependVar("PATH", bindir + ":")