Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csmock: support buildroot location used by new rpm #192

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions py/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,22 @@ def dirs_to_scan_by_args(parser, args, props, tool):
scan_install = (props.shell_cmd_to_build is None)

if not scan_build and not scan_install:
parser.error("either --%s-scan-build or --%s-scan-install must be enabled" %
(tool, tool))
parser.error(f"either --{tool}-scan-build or --{tool}-scan-install must be enabled")

if scan_install and (props.shell_cmd_to_build is not None):
parser.error("--shell-cmd and --%s-scan-install cannot be used together" %
tool)
parser.error(f"--shell-cmd and --{tool}-scan-install cannot be used together")

dirs_to_scan = ""
dirs_to_scan = []
if scan_build:
dirs_to_scan += "/builddir/build/BUILD"
if scan_install:
dirs_to_scan += " "
dirs_to_scan += ["/builddir/build/BUILD"]

if scan_install:
dirs_to_scan += "/builddir/build/BUILDROOT"
# the second variant was introduced by a backward-incompatible change in `rpm`
# https://github.com/rpm-software-management/rpm/commit/9d35c8df497534e1fbd806a4dc78802bcf35d7cb
dirs_to_scan += ["/builddir/build/BUILDROOT", "/builddir/build/BUILD/*/BUILDROOT"]
props.need_rpm_bi = True

return dirs_to_scan
return ' '.join(dirs_to_scan)


def require_file(parser, name):
Expand Down
5 changes: 4 additions & 1 deletion py/csmock
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ DEFAULT_RESULT_FILTERS = [

# path filter needed with `rpmbuild -bi`
# TODO: introduce a csgrep option for this
RPM_BI_FILTER = "sed 's|/builddir/build/BUILDROOT/[^/]*/|/builddir/build/BUILD//|'"
# `/builddir/build/BUILDROOT/${NVR}/...` was used by old versions of `rpm`
# `/builddir/build/BUILD/${NVR}/BUILDROOT/...` was later introduced by a backward-incompatible change in `rpm`
# https://github.com/rpm-software-management/rpm/commit/9d35c8df497534e1fbd806a4dc78802bcf35d7cb
RPM_BI_FILTER = "sed -r 's;/builddir/build/BUILD(ROOT/[^/]+|/[^/]+/BUILDROOT)/;/builddir/build/BUILD//;'"

# path to csexec-loader is hard-coded for now
CSEXEC_ENABLE_FLAG = "-Wl,--dynamic-linker,/usr/bin/csexec-loader"
Expand Down
2 changes: 1 addition & 1 deletion py/plugins/bandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def handle_args(self, parser, args, props):
props.install_pkgs += ["bandit"]

severity_filter = dict(zip(self._severity_levels, ['-l', '-ll', '-lll']))[args.bandit_severity_filter.upper()]
run_cmd = "%s %s %s > %s" % (RUN_BANDIT_SH, severity_filter, dirs_to_scan, BANDIT_CAPTURE)
run_cmd = f"shopt -s nullglob && {RUN_BANDIT_SH} {severity_filter} {dirs_to_scan} > {BANDIT_CAPTURE}"
props.post_build_chroot_cmds += [run_cmd]
props.copy_out_files += [BANDIT_CAPTURE]

Expand Down
2 changes: 1 addition & 1 deletion py/plugins/pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def handle_args(self, parser, args, props):
parser, args, props, "pylint")

props.install_pkgs += ["pylint"]
cmd = "%s %s > %s" % (RUN_PYLINT_SH, dirs_to_scan, PYLINT_CAPTURE)
cmd = f"shopt -s nullglob && {RUN_PYLINT_SH} {dirs_to_scan} > {PYLINT_CAPTURE}"
props.post_build_chroot_cmds += [cmd]
props.copy_out_files += [PYLINT_CAPTURE]

Expand Down
3 changes: 2 additions & 1 deletion py/plugins/shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def handle_args(self, parser, args, props):
dirs_to_scan = " ".join([dir + "/*" for dir in dirs_to_scan.split()])

props.install_pkgs += ["ShellCheck"]
cmd = f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} "
cmd = "shopt -s nullglob && "
cmd += f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} "
cmd += f"SC_BATCH={args.shellcheck_batch} "
cmd += f"SC_TIMEOUT={args.shellcheck_timeout} "
cmd += f"{RUN_SHELLCHECK_SH} {dirs_to_scan}"
Expand Down