[meta-oe,dunfell,1/2] nodejs_12.21.0.bb: only handle npm if configured

Message ID 20220113081301.26006-1-nishaparrakat@gmail.com
State New
Headers show
Series [meta-oe,dunfell,1/2] nodejs_12.21.0.bb: only handle npm if configured | expand

Commit Message

Nisha Parrakat Jan. 13, 2022, 8:13 a.m. UTC
npm-cli.js should be symlinked only when the file is present
the file may not be available if the configure option is --without-npm

Signed-off-by: Nisha Parrakat <nishaparrakat@gmail.com>
---
 meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Peter Kjellerstedt Jan. 14, 2022, 1:25 p.m. UTC | #1
> -----Original Message-----
> From: openembedded-devel@lists.openembedded.org <openembedded-devel@lists.openembedded.org> On Behalf Of Nisha Parrakat
> Sent: den 13 januari 2022 09:13
> To: openembedded-devel@lists.openembedded.org; raj.khem@gmail.com
> Cc: nishaparrakat@gmail.com
> Subject: [oe] [meta-oe][dunfell][PATCH 1/2] nodejs_12.21.0.bb: only handle npm if configured
> 
> npm-cli.js should be symlinked only when the file is present
> the file may not be available if the configure option is --without-npm
> 
> Signed-off-by: Nisha Parrakat <nishaparrakat@gmail.com>
> ---
>  meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb b/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
> index b9e382177..22191a157 100644
> --- a/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
> +++ b/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
> @@ -133,7 +133,9 @@ do_install_append_class-native() {
>      # /usr/bin/npm is symlink to /usr/lib/node_modules/npm/bin/npm-cli.js
>      # use sed on npm-cli.js because otherwise symlink is replaced with normal file and
>      # npm-cli.js continues to use old shebang
> -    sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> +    if [[ -f "${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js" ]]; then
> +        sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> +    fi
> 
>      # Install the native binaries to provide it within sysroot for the target compilation
>      install -d ${D}${bindir}
> @@ -147,7 +149,9 @@ do_install_append_class-native() {
>  }
> 
>  do_install_append_class-target() {
> -    sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> +    if [[ -f "${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js" ]]; then
> +        sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> +    fi
>  }
> 
>  PACKAGES =+ "${PN}-npm"
> --
> 2.17.1

This patch should not be applied because it a) contains bashisms and b) 
it is better to just remove the workaround as it is no longer needed (see 
the patches I just sent for master).

//Peter
Martin Jansa Jan. 14, 2022, 5:50 p.m. UTC | #2
On Fri, Jan 14, 2022 at 01:25:24PM +0000, Peter Kjellerstedt wrote:
> > -----Original Message-----
> > From: openembedded-devel@lists.openembedded.org <openembedded-devel@lists.openembedded.org> On Behalf Of Nisha Parrakat
> > Sent: den 13 januari 2022 09:13
> > To: openembedded-devel@lists.openembedded.org; raj.khem@gmail.com
> > Cc: nishaparrakat@gmail.com
> > Subject: [oe] [meta-oe][dunfell][PATCH 1/2] nodejs_12.21.0.bb: only handle npm if configured
> > 
> > npm-cli.js should be symlinked only when the file is present
> > the file may not be available if the configure option is --without-npm
> > 
> > Signed-off-by: Nisha Parrakat <nishaparrakat@gmail.com>
> > ---
> >  meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb b/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
> > index b9e382177..22191a157 100644
> > --- a/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
> > +++ b/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
> > @@ -133,7 +133,9 @@ do_install_append_class-native() {
> >      # /usr/bin/npm is symlink to /usr/lib/node_modules/npm/bin/npm-cli.js
> >      # use sed on npm-cli.js because otherwise symlink is replaced with normal file and
> >      # npm-cli.js continues to use old shebang
> > -    sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> > +    if [[ -f "${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js" ]]; then
> > +        sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> > +    fi
> > 
> >      # Install the native binaries to provide it within sysroot for the target compilation
> >      install -d ${D}${bindir}
> > @@ -147,7 +149,9 @@ do_install_append_class-native() {
> >  }
> > 
> >  do_install_append_class-target() {
> > -    sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> > +    if [[ -f "${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js" ]]; then
> > +        sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
> > +    fi
> >  }
> > 
> >  PACKAGES =+ "${PN}-npm"
> > --
> > 2.17.1
> 
> This patch should not be applied because it a) contains bashisms and b) 
> it is better to just remove the workaround as it is no longer needed (see 
> the patches I just sent for master).

agreed, with dash nodejs do_install fails with dash:

tmp-glibc/work/x86_64-linux/nodejs-native/16.11.1-r0/temp/run.do_install.2837733:169: [[: not found

but unfortunately it doesn't cause do_install to fail, because [[ is in
if expression.

> 
> //Peter
> 

> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#94833): https://lists.openembedded.org/g/openembedded-devel/message/94833
> Mute This Topic: https://lists.openembedded.org/mt/88392913/3617156
> Group Owner: openembedded-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [Martin.Jansa@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>

Patch

diff --git a/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb b/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
index b9e382177..22191a157 100644
--- a/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
+++ b/meta-oe/recipes-devtools/nodejs/nodejs_12.21.0.bb
@@ -133,7 +133,9 @@  do_install_append_class-native() {
     # /usr/bin/npm is symlink to /usr/lib/node_modules/npm/bin/npm-cli.js
     # use sed on npm-cli.js because otherwise symlink is replaced with normal file and
     # npm-cli.js continues to use old shebang
-    sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
+    if [[ -f "${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js" ]]; then
+        sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
+    fi
 
     # Install the native binaries to provide it within sysroot for the target compilation
     install -d ${D}${bindir}
@@ -147,7 +149,9 @@  do_install_append_class-native() {
 }
 
 do_install_append_class-target() {
-    sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
+    if [[ -f "${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js" ]]; then
+        sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
+    fi
 }
 
 PACKAGES =+ "${PN}-npm"