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
  • Loading branch information
kdudka committed May 28, 2024
1 parent d216903 commit 75405aa
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions scripts/inject-clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 75405aa

Please sign in to comment.