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

Local compare mode added to CodeChecker cmd diff mode. #723

Merged
merged 4 commits into from
Jul 13, 2017

Conversation

dkrupp
Copy link
Member

@dkrupp dkrupp commented Jul 12, 2017

fixes #692

Copy link
Contributor

@whisperity whisperity left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import order. os > sys.

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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(
Copy link
Contributor

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:

  1. 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(...)].

Copy link
Member Author

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(
Copy link
Contributor

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.)

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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:
Copy link
Contributor

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.)

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

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:
Copy link
Contributor

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 ""
Copy link
Contributor

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]

Copy link
Member Author

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):
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import sys


Copy link
Contributor

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.

Copy link
Member Author

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(
Copy link
Contributor

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(...)]

Copy link
Member Author

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort_mode = [ttypes.SortMode(...)]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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',
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Local compare mode: compare local analysis / Preventing new bugs & checking fixes [32h]
3 participants