From 69b366f773ab6d1dd5089132ef721bd1b142bf77 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Wed, 19 Jun 2024 08:43:49 +0200 Subject: [PATCH] clippy: do not fail the scan if clippy fails to install If the `clippy` package is not available in the build repos, a warning is emitted and `clippy` is not recorded as an enabled tool in the scan properties. But the scan continues without `clippy` in this case. The approach is similar to what `--gcc-analyze` does. This is needed because `clippy` is not available for each mock config and we do not want to configure the set of enabled tools separately for each mock config. Related: https://issues.redhat.com/browse/OSH-30 Closes: https://github.com/csutils/csmock/pull/174 --- py/plugins/clippy.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/py/plugins/clippy.py b/py/plugins/clippy.py index d96721a..e4690ea 100644 --- a/py/plugins/clippy.py +++ b/py/plugins/clippy.py @@ -1,6 +1,6 @@ import os -import csmock.common.util +from csmock.common.util import write_toolver_from_rpmlist RUN_CLIPPY_CONVERT = "/usr/share/csmock/scripts/convert-clippy.py" CLIPPY_OUTPUT = "/builddir/clippy-output.txt" @@ -28,14 +28,20 @@ def handle_args(self, parser, args, props): if not self.enabled: return + # install `clippy` only if the package is available in the build repos + props.install_opt_pkgs += ["clippy"] + def inject_clippy_hook(results, mock): - return mock.exec_chroot_cmd(CLIPPY_INJECT_SCRIPT) - props.post_depinst_hooks += [inject_clippy_hook] + ec = write_toolver_from_rpmlist(results, mock, "clippy", "clippy") + if 0 != ec: + # a warning has already been emitted + return 0 - props.install_pkgs += ["clippy"] - props.copy_out_files += [CLIPPY_OUTPUT] + # clippy was found in the buildroot -> instrument the build + props.copy_out_files += [CLIPPY_OUTPUT] + return mock.exec_chroot_cmd(CLIPPY_INJECT_SCRIPT) - csmock.common.util.install_default_toolver_hook(props, "clippy") + props.post_depinst_hooks += [inject_clippy_hook] def convert_hook(results): src = f"{results.dbgdir_raw}{CLIPPY_OUTPUT}"