From bcca9da2b37bbe8492ad2dd8eb2222e2b96a14d9 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Tue, 28 May 2024 13:42:05 +0200 Subject: [PATCH] clippy: make the wrapper work if `build` is not the 1st arg ... so that we can successfully scan the Rust code in `librsvg2-2.50.7-1.el9_0` where `cargo` is invoked like this: ``` cd ./librsvg && \ PKG_CONFIG_ALLOW_CROSS=1 \ PKG_CONFIG='/usr/bin/x86_64-redhat-linux-gnu-pkg-config' \ CARGO_TARGET_DIR=/builddir/build/BUILD/librsvg-2.50.7/target \ cargo --locked build --verbose --release \ && cd /builddir/build/BUILD/librsvg-2.50.7 && /bin/sh ./libtool [...] ``` Related: https://issues.redhat.com/browse/OSH-30 Closes: https://github.com/csutils/csmock/pull/170 --- scripts/inject-clippy.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/inject-clippy.sh b/scripts/inject-clippy.sh index 58a87ea..a31205d 100755 --- a/scripts/inject-clippy.sh +++ b/scripts/inject-clippy.sh @@ -13,16 +13,18 @@ mv -v $ORIGINAL_LOCATION $NEW_LOCATION sed "s|REPLACE_ME|$NEW_LOCATION|g" > $ORIGINAL_LOCATION << 'EOF' #!/bin/bash -ORIGINAL_PARAMS=("$@") - -# FIXME: "build" doesn't have to *always* be the first arg -if [[ $1 == "build" ]]; then - set -x - set -- "clippy" "${@:2}" - REPLACE_ME "$@" --message-format=json >> /builddir/clippy-output.txt -fi - -REPLACE_ME "${ORIGINAL_PARAMS[@]}" +# look for "build" in command-line args +for arg in "$@"; do + if [[ "$arg" == "build" ]]; then + # found! --> execute the command with "build" substituted by "clippy" + set -x + REPLACE_ME "${@/build/clippy}" --message-format=json >> /builddir/clippy-output.txt + break + fi +done + +# execute the original command in any case +exec REPLACE_ME "$@" EOF chmod +x $ORIGINAL_LOCATION