diff --git a/py/common/results.py b/py/common/results.py index 05b98170..1f324cc0 100644 --- a/py/common/results.py +++ b/py/common/results.py @@ -335,6 +335,30 @@ def finalize_results(js_file, results, props): os.system("csgrep '%s'" % err_file) +def apply_result_filters(props, results, supp_filters=[]): + """apply filters, sort the list and record suppressed results""" + js_file = os.path.join(results.resdir, "scan-results.js") + all_file = os.path.join(results.dbgdir, "scan-results-all.js") + + # apply filters, sort the list and store the result as scan-results.js + cmd = f"cat '{all_file}'" + for filt in props.result_filters: + cmd += f" | {filt}" + cmd += f" | cssort --key=path > '{js_file}'" + results.exec_cmd(cmd, shell=True) + + # record suppressed results + js_supp = os.path.join(results.dbgdir, "suppressed-results.js") + cmd = f"cat '{all_file}'" + for filt in supp_filters: + cmd += f" | {filt}" + cmd += f" | csdiff --show-internal '{js_file}' -" + cmd += f" | cssort > '{js_supp}'" + results.exec_cmd(cmd, shell=True) + finalize_results(js_supp, results, props) + finalize_results(js_file, results, props) + + def handle_known_fp_list(props, results): """Update props.result_filters based on props.known_false_positives""" if not props.known_false_positives: diff --git a/py/csmock b/py/csmock index 0bc6a23a..e1f27b91 100755 --- a/py/csmock +++ b/py/csmock @@ -37,6 +37,7 @@ from csmock.common.util import shell_quote from csmock.common.util import strlist_to_shell_cmd from csmock.common.results import FatalError from csmock.common.results import ScanResults +from csmock.common.results import apply_result_filters from csmock.common.results import finalize_results from csmock.common.results import handle_known_fp_list from csmock.common.results import transform_results @@ -1236,23 +1237,10 @@ cd %%s*/ || cd *\n\ # we are done with mock - # apply filters, sort the list and store the result as scan-results.js - cmd = "cat '%s'" % all_file - for filt in props.result_filters: - cmd += " | %s" % filt - cmd += " | cssort --key=path > '%s'" % js_file - results.exec_cmd(cmd, shell=True) - - # record suppressed results - js_supp = "%s/suppressed-results.js" % results.dbgdir - cmd = "%s '%s' " % (RPM_BI_FILTER, all_file) - cmd += "| csgrep --mode=json --strip-path-prefix /builddir/build/BUILD/ " - cmd += "| csdiff --show-internal '%s' - " % js_file - cmd += "| cssort > '%s'" % js_supp - results.exec_cmd(cmd, shell=True) - finalize_results(js_supp, results, props) + # apply filters, sort the list and record suppressed results + supp_filters = [RPM_BI_FILTER, "csgrep --mode=json --strip-path-prefix /builddir/build/BUILD/"] + apply_result_filters(props, results, supp_filters=supp_filters) - finalize_results(js_file, results, props) return results.ec except FatalError as error: