-
Notifications
You must be signed in to change notification settings - Fork 385
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
Local compare mode added to CodeChecker cmd diff mode. #723
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, seems to work well, thank you.
Only minor formatting issues. Also, please update docs/user_guide.md
with the new help of cmd diff
(that includes --reportdir
), and maybe with an example of this use case.
@@ -8,6 +8,7 @@ | |||
import getpass | |||
import json | |||
import sys | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import order. os
> sys
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -19,6 +20,8 @@ | |||
from libcodechecker import suppress_file_handler | |||
from libcodechecker.logger import LoggerFactory | |||
from libcodechecker.output_formatters import twodim_to_str | |||
from libcodechecker.analyze import plist_parser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import order here too. Alphabetical on module name: libcodechecker
, libcodechecker.analyze
, libcodechecker.logger
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
sort_type = None | ||
sort_mode = [] | ||
sort_mode.append(codeCheckerDBAccess.ttypes.SortMode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I agree that this long line is very ugly here. Also, expression can be simplified. Let's do this:
- Introduce a new import at the top:
import codeCheckerDBAccess
import shared
from Authentication import ttypes as AuthTypes
+ from codeCheckerDBAccess import ttypes
Then rewrite this statement so the qualified name is only ttypes.SortMode
and such.
Empty list and append can be simplified into a single list constructor: sort_mode = [ttypes.SortMode(...)]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
add_filter_conditions(report_filter[0], args.filter) | ||
|
||
sort_mode = [] | ||
sort_mode.append(codeCheckerDBAccess.ttypes.SortMode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same simplification as in the other function.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
return "" | ||
|
||
def getLineFromRemoteFile(client, fid, lineno): | ||
# FIXME: large special file content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should mention that "special" file content in this case is the UTF-8 encoding problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
def getLineFromRemoteFile(client, fid, lineno): | ||
# FIXME: large special file content | ||
# cause connection abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this comment is not formatted as a full sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
return all_reports | ||
|
||
def getLineFromFile(filename, lineno): | ||
with open(filename, 'r') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should introduce a comment here that due to potentially big files, this verbose algorithm is much more efficient than return f.readlines()[lineno]
. (I have checked some posts on the Internet about this, and yes, it's more efficient this way, even if it looks more down-to-Earth.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wouldnt spoil the code with such comments.
for rep in new_results: | ||
bughash = rep.main['issue_hash_content_of_line_in_context'] | ||
new_hashes[bughash] = rep | ||
# show new reports from the report dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the comments into the branch's body, and format them as full sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if not (result.bugHash in new_hashes): | ||
filtered_reports.append(result) | ||
# show bugs in the report dir | ||
# which is not suppressed in the baseline (server) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"unresolved"
no longer "overrides" behaviour on whether or not suppressed results are grabbed, as we reviewed it earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
args.output_format) | ||
results = [] | ||
if 'reportdir' in args: | ||
if 'newname' in args: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argparse
can handle mutually exclusive argument groups.
if i == lineno: | ||
return line | ||
i += 1 | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a loop here:
return "" if len(lines) < lineno else lines[lineno - 1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
i += 1 | ||
return "" | ||
|
||
def getDiffReportDir(getterFn, baseid, report_dir, suppr, diff_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first parameter of this function doesn't seem necessary. This function is called once in the project where it gets client.getRunResults
, but anyway this will always be used for getting the reports. The client object definition in line 425 could be replaced above this function (e.g. as the first statement of handle_diff_results()
in line 266) which is used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the calling style of other functions in this file, so I think i will leave it like this.
except CalledProcessError as cerr: | ||
print("Failed to call:\n" + ' '.join(cerr.cmd)) | ||
return cerr.returncode | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There needs to be 2 linebreaks here instead of 1, this breaks pep8
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
import sys | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line-break, please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
sort_type = None | ||
sort_mode = [] | ||
sort_mode.append(ttypes.SortMode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Statement can be simplified:
sort_mode = [ttypes.SortMode(...)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
add_filter_conditions(report_filter[0], args.filter) | ||
|
||
sort_mode = [] | ||
sort_mode.append(ttypes.SortMode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort_mode = [ttypes.SortMode(...)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tests/functional/diff/__init__.py
Outdated
@@ -99,13 +101,30 @@ def setup_package(): | |||
|
|||
test_project_name_new = project_info['name'] + '_' + uuid.uuid4().hex | |||
|
|||
# Let's run the second analysis with different | |||
# checkers to have some real difference. | |||
codechecker_cfg['checkers'] = ['-d', 'core.StackAddressEscape', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This here looks tricky on first glance, as -d
,-e
order is kept instead of the checker order. We should change this to:
['-e', 'core.CallAndMessage', '-d', 'core.StackAddressEscape']
so the checker order is kept with the previous code in line 73.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fixes #692