diff mbox series

[PATCH/master,2/7] g-ir-scanner-qemuwrapper.in: Fix shellcheck warnings, switch to sh

Message ID 20210903162027.1935040-3-aduskett@gmail.com
State Accepted
Headers show
Series Qemu and gobject-introspection fixes | expand

Commit Message

Adam Duskett Sept. 3, 2021, 4:20 p.m. UTC
- Add double quotes to prevent globbing and word splitting.
  - Add indentations of continuation lines.
  - Disable SC2181 and SC2016 as we explicitly do not want the variables
    expanded in the echo.

Signed-off-by: Adam Duskett <aduskett@gmail.com>
---
 .../g-ir-scanner-qemuwrapper.in                  | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

Arnout Vandecappelle Sept. 11, 2021, 6:57 p.m. UTC | #1
On 03/09/2021 18:20, Adam Duskett wrote:
>   - Add double quotes to prevent globbing and word splitting.
>   - Add indentations of continuation lines.
>   - Disable SC2181 and SC2016 as we explicitly do not want the variables
>     expanded in the echo.
> 
> Signed-off-by: Adam Duskett <aduskett@gmail.com>
> ---
>  .../g-ir-scanner-qemuwrapper.in                  | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/package/gobject-introspection/g-ir-scanner-qemuwrapper.in b/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
> index ec066062e2..5ece75d0a4 100644
> --- a/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
> +++ b/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
> @@ -1,18 +1,20 @@
> -#!/usr/bin/env bash
> +#!/usr/bin/env sh
>  
> -# Pass -r to qemu-user as to trick glibc into not errorings out if the host kernel
> +# Pass -r to qemu-user as to trick glibc into not erroring out if the host kernel
>  # is older than the target kernel.
>  # Use a modules directory which does not exist so we don't load random things
>  # which may then get deleted (or their dependencies) and potentially segfault
>  GOI_LIBRARY_PATH="${GIR_EXTRA_LIBS_PATH:+${GIR_EXTRA_LIBS_PATH}:}.libs:$(dirname "$0")/../lib:$(dirname "$0")/../../lib"
> -GIO_MODULE_DIR=$(dirname $0)/../lib/gio/modules-dummy \
> +GIO_MODULE_DIR="$(dirname "$0")/../lib/gio/modules-dummy" \
>  @QEMU_USER@ -r @TOOLCHAIN_HEADERS_VERSION@ \
> --L $(dirname $0)/../../ \
> --E LD_LIBRARY_PATH="${GOI_LIBRARY_PATH}" \
> -"$@"
> +    -L "$(dirname "$0")/../../" \
> +    -E LD_LIBRARY_PATH="${GOI_LIBRARY_PATH}" \
> +    "$@"
>  
> -if [[ $? -ne 0 ]]; then
> +# shellcheck disable=SC2181

 Instead of adding an exception, we could just do the right thing:

if ! @QEMU_USER@ -r ... \
    ... \
then
    ...

 But since I wasn't going to test this change, I left it as is.

 Regards,
 Arnout

> +if [ $? -ne 0 ]; then
>      echo "If the above error message is about missing .so libraries, then setting up GIR_EXTRA_LIBS_PATH in the .mk file should help."
> +    # shellcheck disable=SC2016
>      echo 'Typically like this: PKG_MAKE_ENV += GIR_EXTRA_LIBS_PATH="$(@D)/.libs"'
>      exit 1
>  fi
>
Yann E. MORIN Sept. 11, 2021, 7:49 p.m. UTC | #2
Arnout, All,

On 2021-09-11 20:57 +0200, Arnout Vandecappelle spake thusly:
> On 03/09/2021 18:20, Adam Duskett wrote:
> >   - Add double quotes to prevent globbing and word splitting.
> >   - Add indentations of continuation lines.
> >   - Disable SC2181 and SC2016 as we explicitly do not want the variables
> >     expanded in the echo.
> > 
> > Signed-off-by: Adam Duskett <aduskett@gmail.com>
> > ---
> >  .../g-ir-scanner-qemuwrapper.in                  | 16 +++++++++-------
> >  1 file changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/package/gobject-introspection/g-ir-scanner-qemuwrapper.in b/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
> > index ec066062e2..5ece75d0a4 100644
> > --- a/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
> > +++ b/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
> > @@ -1,18 +1,20 @@
> > -#!/usr/bin/env bash
> > +#!/usr/bin/env sh
> >  
> > -# Pass -r to qemu-user as to trick glibc into not errorings out if the host kernel
> > +# Pass -r to qemu-user as to trick glibc into not erroring out if the host kernel
> >  # is older than the target kernel.
> >  # Use a modules directory which does not exist so we don't load random things
> >  # which may then get deleted (or their dependencies) and potentially segfault
> >  GOI_LIBRARY_PATH="${GIR_EXTRA_LIBS_PATH:+${GIR_EXTRA_LIBS_PATH}:}.libs:$(dirname "$0")/../lib:$(dirname "$0")/../../lib"
> > -GIO_MODULE_DIR=$(dirname $0)/../lib/gio/modules-dummy \
> > +GIO_MODULE_DIR="$(dirname "$0")/../lib/gio/modules-dummy" \
> >  @QEMU_USER@ -r @TOOLCHAIN_HEADERS_VERSION@ \
> > --L $(dirname $0)/../../ \
> > --E LD_LIBRARY_PATH="${GOI_LIBRARY_PATH}" \
> > -"$@"
> > +    -L "$(dirname "$0")/../../" \
> > +    -E LD_LIBRARY_PATH="${GOI_LIBRARY_PATH}" \
> > +    "$@"
> >  
> > -if [[ $? -ne 0 ]]; then
> > +# shellcheck disable=SC2181
> 
>  Instead of adding an exception, we could just do the right thing:
> 
> if ! @QEMU_USER@ -r ... \
>     ... \
> then
>     ...
> 
>  But since I wasn't going to test this change, I left it as is.

I also considered it when Adam and I discussed this patch on IRC, but I
side with him to keep the code as-is, but forgot to explain why so that
he could add that to the commit log.

So for the posterity, here is my reasonning:

    Continuation lines in a condition are ugly and make an if-then-else
    condition harder to grok, so we prefer adding an SC2181 exception as
    it leaves the code more readable.

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/package/gobject-introspection/g-ir-scanner-qemuwrapper.in b/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
index ec066062e2..5ece75d0a4 100644
--- a/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
+++ b/package/gobject-introspection/g-ir-scanner-qemuwrapper.in
@@ -1,18 +1,20 @@ 
-#!/usr/bin/env bash
+#!/usr/bin/env sh
 
-# Pass -r to qemu-user as to trick glibc into not errorings out if the host kernel
+# Pass -r to qemu-user as to trick glibc into not erroring out if the host kernel
 # is older than the target kernel.
 # Use a modules directory which does not exist so we don't load random things
 # which may then get deleted (or their dependencies) and potentially segfault
 GOI_LIBRARY_PATH="${GIR_EXTRA_LIBS_PATH:+${GIR_EXTRA_LIBS_PATH}:}.libs:$(dirname "$0")/../lib:$(dirname "$0")/../../lib"
-GIO_MODULE_DIR=$(dirname $0)/../lib/gio/modules-dummy \
+GIO_MODULE_DIR="$(dirname "$0")/../lib/gio/modules-dummy" \
 @QEMU_USER@ -r @TOOLCHAIN_HEADERS_VERSION@ \
--L $(dirname $0)/../../ \
--E LD_LIBRARY_PATH="${GOI_LIBRARY_PATH}" \
-"$@"
+    -L "$(dirname "$0")/../../" \
+    -E LD_LIBRARY_PATH="${GOI_LIBRARY_PATH}" \
+    "$@"
 
-if [[ $? -ne 0 ]]; then
+# shellcheck disable=SC2181
+if [ $? -ne 0 ]; then
     echo "If the above error message is about missing .so libraries, then setting up GIR_EXTRA_LIBS_PATH in the .mk file should help."
+    # shellcheck disable=SC2016
     echo 'Typically like this: PKG_MAKE_ENV += GIR_EXTRA_LIBS_PATH="$(@D)/.libs"'
     exit 1
 fi