Skip to content

Commit

Permalink
clippy: do not fail scan of packages without Rust code
Browse files Browse the repository at this point in the history
We want to enable `clippy` in the default scanning profile in a way that
it takes an effect for packages that build Rust code.  For packages that
do not build any Rust code, the plug-in should do nothing rather than
failing the whole scan:
```
% csmock -at clippy -r rhel-7-x86_64 -f units-2.01-5.el7_9.src.rpm
[...]
>>> 2024-05-28 12:24:21 "set -o pipefail; /usr/share/csmock/scripts/convert-clippy.py < /tmp/csmocknsbuwvil/units-2.01-5.el7_9/debug/raw-results/builddir/clippy-output.txt | csgrep --remove-duplicates > /tmp/csmocknsbuwvil/units-2.01-5.el7_9/debug/uni-results/clippy-capture.err"
/bin/sh: line 1: /tmp/csmocknsbuwvil/units-2.01-5.el7_9/debug/raw-results/builddir/clippy-output.txt: No such file or directory

!!! 2024-05-28 12:24:21 error: post-process hook failed
```

Fixes: commit d216903
Related: https://issues.redhat.com/browse/OSH-30
  • Loading branch information
kdudka committed May 28, 2024
1 parent d216903 commit 46ccea0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions py/plugins/clippy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import csmock.common.util

import os

RUN_CLIPPY_CONVERT = "/usr/share/csmock/scripts/convert-clippy.py"
CLIPPY_OUTPUT = "/builddir/clippy-output.txt"
CLIPPY_INSTALL = "/usr/share/csmock/scripts/inject-clippy.sh"
Expand Down Expand Up @@ -37,6 +39,10 @@ def install_clippy_hook(results, mock):

def convert_hook(results):
src = f"{results.dbgdir_raw}{CLIPPY_OUTPUT}"
if not os.path.exists(src):
# if `cargo build` was not executed during the scan, there are no results to process
return 0

dst = f"{results.dbgdir_uni}/clippy-capture.err"
cmd = f'set -o pipefail; {RUN_CLIPPY_CONVERT} < {src} | csgrep --remove-duplicates > {dst}'
return results.exec_cmd(cmd, shell=True)
Expand Down

0 comments on commit 46ccea0

Please sign in to comment.