Skip to content

Commit

Permalink
[cli] Add file filter option for CodeChecker parse
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Nov 24, 2021
1 parent 153b0e0 commit 3969742
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 10 deletions.
41 changes: 31 additions & 10 deletions analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ def add_arguments_to_parser(parser):
help="Print the steps the analyzers took in finding "
"the reported defect.")

parser.add_argument('-i', '--ignore', '--skip',
dest="skipfile",
required=False,
default=argparse.SUPPRESS,
help="Path to the Skipfile dictating which project "
"files should be omitted from analysis. Please "
"consult the User guide on how a Skipfile "
"should be laid out.")

parser.add_argument('--trim-path-prefix',
type=str,
nargs='*',
Expand All @@ -224,6 +215,31 @@ def add_arguments_to_parser(parser):
"values are: {0}".format(
', '.join(REVIEW_STATUS_VALUES)))

group = parser.add_argument_group("file filter arguments")
group = group.add_mutually_exclusive_group()

group.add_argument('-i', '--ignore', '--skip',
dest="skipfile",
required=False,
default=argparse.SUPPRESS,
help="Path to the Skipfile dictating which project "
"files should be omitted from analysis. Please "
"consult the User guide on how a Skipfile "
"should be laid out.")

group.add_argument('--file',
nargs='+',
dest="files",
metavar='FILE',
required=False,
default=argparse.SUPPRESS,
help="Filter results by file path. "
"The file path can contain multiple * "
"quantifiers which matches any number of "
"characters (zero or more). So if you have "
"/a/x.cpp and /a/y.cpp then \"/a/*.cpp\" "
"selects both.")

logger.add_verbose_arguments(parser)
parser.set_defaults(
func=main, func_process_config_file=cmd_config.process_config_file)
Expand Down Expand Up @@ -358,7 +374,12 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:
return os.path.join(output_dir_path, default_file_name)

skip_file_content = ""
if 'skipfile' in args:
if 'files' in args:
items = [f"+{file_path}" for file_path in args.files]
items.append("-*")

skip_file_content = "\n".join(items)
elif 'skipfile' in args:
with open(args.skipfile, 'r',
encoding='utf-8', errors='ignore') as skip_file:
skip_file_content = skip_file.read()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
NORMAL#CodeChecker parse $WORKSPACE$/test_files/macros/macros.plist $WORKSPACE$/test_files/notes/notes.plist --file "*macros.cpp"
--------------------------------------------------------------------------------
[HIGH] macros.cpp:7:8: Dereference of null pointer (loaded from variable 'ptr') [core.NullDereference]
*ptr = 5; // expected-warning{{Dereference of null pointer}}
^

Found 1 defect(s) in macros.cpp


----==== Severity Statistics ====----
----------------------------
Severity | Number of reports
----------------------------
HIGH | 1
----------------------------
----=================----

----==== Checker Statistics ====----
---------------------------------------------------
Checker name | Severity | Number of reports
---------------------------------------------------
core.NullDereference | HIGH | 1
---------------------------------------------------
----=================----

----==== File Statistics ====----
------------------------------
File name | Number of reports
------------------------------
macros.cpp | 1
------------------------------
----=================----

----======== Summary ========----
---------------------------------------------
Number of processed analyzer result files | 2
Number of analyzer reports | 1
---------------------------------------------
----=================----
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
NORMAL#CodeChecker parse $WORKSPACE$/test_files/macros/macros.plist $WORKSPACE$/test_files/notes/notes.plist --file "*.cpp"
--------------------------------------------------------------------------------
[HIGH] macros.cpp:7:8: Dereference of null pointer (loaded from variable 'ptr') [core.NullDereference]
*ptr = 5; // expected-warning{{Dereference of null pointer}}
^

Found 1 defect(s) in macros.cpp

[LOW] notes.cpp:3:23: Duplicate code detected [alpha.clone.CloneChecker]
int max(int a, int b) { // expected-warning{{Duplicate code detected}}
^

Found 1 defect(s) in notes.cpp


----==== Severity Statistics ====----
----------------------------
Severity | Number of reports
----------------------------
HIGH | 1
LOW | 1
----------------------------
----=================----

----==== Checker Statistics ====----
-------------------------------------------------------
Checker name | Severity | Number of reports
-------------------------------------------------------
core.NullDereference | HIGH | 1
alpha.clone.CloneChecker | LOW | 1
-------------------------------------------------------
----=================----

----==== File Statistics ====----
------------------------------
File name | Number of reports
------------------------------
macros.cpp | 1
notes.cpp | 1
------------------------------
----=================----

----======== Summary ========----
---------------------------------------------
Number of processed analyzer result files | 2
Number of analyzer reports | 2
---------------------------------------------
----=================----

0 comments on commit 3969742

Please sign in to comment.