summaryrefslogtreecommitdiff
path: root/tools/scan-build-py/libscanbuild/analyze.py
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
commit2b6b257f4e5503a7a2675bdb8735693db769f75c (patch)
treee85e046ae7003fe3bcc8b5454cd0fa3f7407b470 /tools/scan-build-py/libscanbuild/analyze.py
parentb4348ed0b7e90c0831b925fbee00b5f179a99796 (diff)
Notes
Diffstat (limited to 'tools/scan-build-py/libscanbuild/analyze.py')
-rw-r--r--tools/scan-build-py/libscanbuild/analyze.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/tools/scan-build-py/libscanbuild/analyze.py b/tools/scan-build-py/libscanbuild/analyze.py
index 0d3547befeef..0ed0aef83873 100644
--- a/tools/scan-build-py/libscanbuild/analyze.py
+++ b/tools/scan-build-py/libscanbuild/analyze.py
@@ -25,8 +25,7 @@ from libscanbuild.runner import run
from libscanbuild.intercept import capture
from libscanbuild.report import report_directory, document
from libscanbuild.clang import get_checkers
-from libscanbuild.runner import action_check
-from libscanbuild.command import classify_parameters, classify_source
+from libscanbuild.compilation import split_command
__all__ = ['analyze_build_main', 'analyze_build_wrapper']
@@ -106,7 +105,8 @@ def run_analyzer(args, output_dir):
'output_dir': output_dir,
'output_format': args.output_format,
'output_failures': args.output_failures,
- 'direct_args': analyzer_params(args)
+ 'direct_args': analyzer_params(args),
+ 'force_debug': args.force_debug
}
logging.debug('run analyzer against compilation database')
@@ -138,7 +138,8 @@ def setup_environment(args, destination, bin_dir):
'ANALYZE_BUILD_REPORT_DIR': destination,
'ANALYZE_BUILD_REPORT_FORMAT': args.output_format,
'ANALYZE_BUILD_REPORT_FAILURES': 'yes' if args.output_failures else '',
- 'ANALYZE_BUILD_PARAMETERS': ' '.join(analyzer_params(args))
+ 'ANALYZE_BUILD_PARAMETERS': ' '.join(analyzer_params(args)),
+ 'ANALYZE_BUILD_FORCE_DEBUG': 'yes' if args.force_debug else ''
})
return environment
@@ -160,30 +161,34 @@ def analyze_build_wrapper(cplusplus):
return result
# ... and run the analyzer if all went well.
try:
+ # check is it a compilation
+ compilation = split_command(sys.argv)
+ if compilation is None:
+ return result
# collect the needed parameters from environment, crash when missing
- consts = {
+ parameters = {
'clang': os.getenv('ANALYZE_BUILD_CLANG'),
'output_dir': os.getenv('ANALYZE_BUILD_REPORT_DIR'),
'output_format': os.getenv('ANALYZE_BUILD_REPORT_FORMAT'),
'output_failures': os.getenv('ANALYZE_BUILD_REPORT_FAILURES'),
'direct_args': os.getenv('ANALYZE_BUILD_PARAMETERS',
'').split(' '),
+ 'force_debug': os.getenv('ANALYZE_BUILD_FORCE_DEBUG'),
'directory': os.getcwd(),
+ 'command': [sys.argv[0], '-c'] + compilation.flags
}
- # get relevant parameters from command line arguments
- args = classify_parameters(sys.argv)
- filenames = args.pop('files', [])
- for filename in (name for name in filenames if classify_source(name)):
- parameters = dict(args, file=filename, **consts)
+ # call static analyzer against the compilation
+ for source in compilation.files:
+ parameters.update({'file': source})
logging.debug('analyzer parameters %s', parameters)
- current = action_check(parameters)
+ current = run(parameters)
# display error message from the static analyzer
if current is not None:
for line in current['error_output']:
logging.info(line.rstrip())
except Exception:
logging.exception("run analyzer inside compiler wrapper failed.")
- return 0
+ return result
def analyzer_params(args):
@@ -203,8 +208,8 @@ def analyzer_params(args):
if args.store_model:
result.append('-analyzer-store={0}'.format(args.store_model))
if args.constraints_model:
- result.append(
- '-analyzer-constraints={0}'.format(args.constraints_model))
+ result.append('-analyzer-constraints={0}'.format(
+ args.constraints_model))
if args.internal_stats:
result.append('-analyzer-stats')
if args.analyze_headers:
@@ -450,6 +455,12 @@ def create_parser(from_build_command):
Could be usefull when project contains 3rd party libraries.
The directory path shall be absolute path as file names in
the compilation database.""")
+ advanced.add_argument(
+ '--force-analyze-debug-code',
+ dest='force_debug',
+ action='store_true',
+ help="""Tells analyzer to enable assertions in code even if they were
+ disabled during compilation, enabling more precise results.""")
plugins = parser.add_argument_group('checker options')
plugins.add_argument(