Message ID | 20230530222752.42503-1-m.belouarga@technologyandstrategy.com |
---|---|
State | New |
Headers | show |
Series | [master,1/6] recipetool: create: npm: Remove duplicate function to not have future conflicts | expand |
Thanks for the work on this. We have a couple of selftests that test npm functionality, unfortunately they do not run in CI because npm is not in oe-core, but can you confirm that they pass with the changes? Run: oe-selftest -r recipetool.RecipetoolCreateTests.test_recipetool_create_npm oe-selftest -r devtool.DevtoolAddTests.test_devtool_add_npm Alex On Wed, 31 May 2023 at 00:28, <belouargamohamed@gmail.com> wrote: > > From: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com> > > Npm packages do not have yocto friendly names. fore instance we can have names like > "@example/npmPackage" > > npm fetcher has a function that convert these names to yocto friendly names. > But in recipe tool we have an other function (duplicate). > > Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com> > --- > scripts/lib/recipetool/create_npm.py | 14 +++----------- > 1 file changed, 3 insertions(+), 11 deletions(-) > > diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py > index 3394a89970..e667a4d19b 100644 > --- a/scripts/lib/recipetool/create_npm.py > +++ b/scripts/lib/recipetool/create_npm.py > @@ -13,6 +13,7 @@ import sys > import tempfile > import bb > from bb.fetch2.npm import NpmEnvironment > +from bb.fetch2.npm import npm_package > from bb.fetch2.npmsw import foreach_dependencies > from recipetool.create import RecipeHandler > from recipetool.create import get_license_md5sums > @@ -30,15 +31,6 @@ def tinfoil_init(instance): > class NpmRecipeHandler(RecipeHandler): > """Class to handle the npm recipe creation""" > > - @staticmethod > - def _npm_name(name): > - """Generate a Yocto friendly npm name""" > - name = re.sub("/", "-", name) > - name = name.lower() > - name = re.sub(r"[^\-a-z0-9]", "", name) > - name = name.strip("-") > - return name > - > @staticmethod > def _get_registry(lines): > """Get the registry value from the 'npm://registry' url""" > @@ -143,7 +135,7 @@ class NpmRecipeHandler(RecipeHandler): > > # Handle the dependencies > def _handle_dependency(name, params, deptree): > - suffix = "-".join([self._npm_name(dep) for dep in deptree]) > + suffix = "-".join([npm_package(dep) for dep in deptree]) > destdirs = [os.path.join("node_modules", dep) for dep in deptree] > destdir = os.path.join(*destdirs) > packages["${PN}-" + suffix] = destdir > @@ -173,7 +165,7 @@ class NpmRecipeHandler(RecipeHandler): > if "name" not in data or "version" not in data: > return False > > - extravalues["PN"] = self._npm_name(data["name"]) > + extravalues["PN"] = npm_package(data["name"]) > extravalues["PV"] = data["version"] > > if "description" in data: > -- > 2.25.1 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#181961): https://lists.openembedded.org/g/openembedded-core/message/181961 > Mute This Topic: https://lists.openembedded.org/mt/99230551/1686489 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- >
Hey Alexander, Thanks for your answer. In order that my changes work, Some patches on bitbake should be accepted: https://lists.openembedded.org/g/bitbake-devel/message/14815?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2Cbelouarga%2C20%2C2%2C0%2C99163598 https://lists.openembedded.org/g/bitbake-devel/message/14819?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2Cbelouarga%2C20%2C2%2C0%2C99230772 https://lists.openembedded.org/g/bitbake-devel/message/14820?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2Cbelouarga%2C20%2C2%2C0%2C99248868 and one patch that I just made on open embedded-core: https://lists.openembedded.org/g/openembedded-core/message/182022?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2Cbelouarga%2C20%2C2%2C0%2C99248914 I ran the tests that you asked me to do, you can find the results below. elf@container:~/workspace$ oe-selftest -r recipetool.RecipetoolCreateTests.test_recipetool_create_npm 2023-05-31 17:31:33,552 - oe-selftest - INFO - Changing cwd to /home/elf/workspace/build 2023-05-31 17:31:33,552 - oe-selftest - WARNING - meta-selftest layer not found in BBLAYERS, adding it 2023-05-31 17:31:39,880 - oe-selftest - INFO - Adding layer libraries: 2023-05-31 17:31:39,880 - oe-selftest - INFO - /home/elf/workspace/layers/poky/meta/lib 2023-05-31 17:31:39,880 - oe-selftest - INFO - /home/elf/workspace/layers/poky/meta-yocto-bsp/lib 2023-05-31 17:31:39,880 - oe-selftest - INFO - /home/elf/workspace/layers/meta-openembedded/meta-oe/lib 2023-05-31 17:31:39,880 - oe-selftest - INFO - /home/elf/workspace/layers/poky/meta-selftest/lib 2023-05-31 17:31:39,882 - oe-selftest - INFO - Running bitbake -e to test the configuration is valid/parsable NOTE: Starting bitbake server... 2023-05-31 17:31:49,176 - oe-selftest - INFO - Adding: "include selftest.inc" in /home/elf/workspace/build-st/conf/local.conf 2023-05-31 17:31:49,178 - oe-selftest - INFO - Adding: "include bblayers.inc" in bblayers.conf 2023-05-31 17:31:49,179 - oe-selftest - INFO - test_recipetool_create_npm (recipetool.RecipetoolCreateTests) 2023-05-31 17:33:36,312 - oe-selftest - INFO - ... ok 2023-05-31 17:33:38,097 - oe-selftest - INFO - ---------------------------------------------------------------------- 2023-05-31 17:33:38,097 - oe-selftest - INFO - Ran 1 test in 115.852s 2023-05-31 17:33:38,097 - oe-selftest - INFO - OK 2023-05-31 17:33:48,971 - oe-selftest - INFO - RESULTS: 2023-05-31 17:33:48,971 - oe-selftest - INFO - RESULTS - recipetool.RecipetoolCreateTests.test_recipetool_create_npm: PASSED (107.13s) 2023-05-31 17:33:49,063 - oe-selftest - INFO - SUMMARY: 2023-05-31 17:33:49,063 - oe-selftest - INFO - oe-selftest () - Ran 1 test in 115.853s 2023-05-31 17:33:49,064 - oe-selftest - INFO - oe-selftest - OK - All required tests passed (successes=1, skipped=0, failures=0, errors=0) elf@container:~/workspace$ oe-selftest -r devtool.DevtoolAddTests.test_devtool_add_npm 2023-05-31 17:34:03,550 - oe-selftest - INFO - Changing cwd to /home/elf/workspace/build 2023-05-31 17:34:03,550 - oe-selftest - INFO - Adding layer libraries: 2023-05-31 17:34:03,550 - oe-selftest - INFO - /home/elf/workspace/layers/poky/meta/lib 2023-05-31 17:34:03,551 - oe-selftest - INFO - /home/elf/workspace/layers/poky/meta-yocto-bsp/lib 2023-05-31 17:34:03,551 - oe-selftest - INFO - /home/elf/workspace/layers/meta-openembedded/meta-oe/lib 2023-05-31 17:34:03,551 - oe-selftest - INFO - /home/elf/workspace/layers/poky/meta-selftest/lib 2023-05-31 17:34:03,552 - oe-selftest - INFO - Running bitbake -e to test the configuration is valid/parsable NOTE: Starting bitbake server... 2023-05-31 17:34:12,581 - oe-selftest - INFO - Adding: "include selftest.inc" in /home/elf/workspace/build-st/conf/local.conf 2023-05-31 17:34:12,582 - oe-selftest - INFO - Adding: "include bblayers.inc" in bblayers.conf 2023-05-31 17:34:15,320 - oe-selftest - INFO - test_devtool_add_npm (devtool.DevtoolAddTests) 2023-05-31 17:38:02,622 - oe-selftest - INFO - ... ok 2023-05-31 17:38:04,371 - oe-selftest - INFO - ---------------------------------------------------------------------- 2023-05-31 17:38:04,371 - oe-selftest - INFO - Ran 1 test in 238.516s 2023-05-31 17:38:04,371 - oe-selftest - INFO - OK 2023-05-31 17:38:21,118 - oe-selftest - INFO - RESULTS: 2023-05-31 17:38:21,118 - oe-selftest - INFO - RESULTS - devtool.DevtoolAddTests.test_devtool_add_npm: PASSED (227.30s) 2023-05-31 17:38:21,200 - oe-selftest - INFO - SUMMARY: 2023-05-31 17:38:21,200 - oe-selftest - INFO - oe-selftest () - Ran 1 test in 238.517s 2023-05-31 17:38:21,201 - oe-selftest - INFO - oe-selftest - OK - All required tests passed (successes=1, skipped=0, failures=0, errors=0)
diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py index 3394a89970..e667a4d19b 100644 --- a/scripts/lib/recipetool/create_npm.py +++ b/scripts/lib/recipetool/create_npm.py @@ -13,6 +13,7 @@ import sys import tempfile import bb from bb.fetch2.npm import NpmEnvironment +from bb.fetch2.npm import npm_package from bb.fetch2.npmsw import foreach_dependencies from recipetool.create import RecipeHandler from recipetool.create import get_license_md5sums @@ -30,15 +31,6 @@ def tinfoil_init(instance): class NpmRecipeHandler(RecipeHandler): """Class to handle the npm recipe creation""" - @staticmethod - def _npm_name(name): - """Generate a Yocto friendly npm name""" - name = re.sub("/", "-", name) - name = name.lower() - name = re.sub(r"[^\-a-z0-9]", "", name) - name = name.strip("-") - return name - @staticmethod def _get_registry(lines): """Get the registry value from the 'npm://registry' url""" @@ -143,7 +135,7 @@ class NpmRecipeHandler(RecipeHandler): # Handle the dependencies def _handle_dependency(name, params, deptree): - suffix = "-".join([self._npm_name(dep) for dep in deptree]) + suffix = "-".join([npm_package(dep) for dep in deptree]) destdirs = [os.path.join("node_modules", dep) for dep in deptree] destdir = os.path.join(*destdirs) packages["${PN}-" + suffix] = destdir @@ -173,7 +165,7 @@ class NpmRecipeHandler(RecipeHandler): if "name" not in data or "version" not in data: return False - extravalues["PN"] = self._npm_name(data["name"]) + extravalues["PN"] = npm_package(data["name"]) extravalues["PV"] = data["version"] if "description" in data: