Skip to content

Commit

Permalink
clippy: make the wrapper work if build is not the 1st arg
Browse files Browse the repository at this point in the history
... 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: #170
  • Loading branch information
kdudka committed May 29, 2024
1 parent 76a7d65 commit b037156
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions scripts/inject-clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ ORIGINAL_LOCATION="/usr/bin/cargo"
NEW_LOCATION="/usr/bin/cargo_original"

if [ -f "$NEW_LOCATION" ]; then
rm "/builddir/clippy-output.txt"
# remove capture file created by previous runs if --skip-init is in effect
rm -fv "/builddir/clippy-output.txt"
exit 0
fi

Expand All @@ -13,16 +14,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 ((i=0; i<$#; i++)); do
if [[ "${@[i]}" == "build" ]]; then
# found! --> execute the command with "build" substituted by "clippy"
set -x
REPLACE_ME "${@::i}" clippy "${@:i+1}" --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

0 comments on commit b037156

Please sign in to comment.