r299759 - [scan-build-py] merge runner module to analyzer

2017-04-07 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Fri Apr  7 06:04:49 2017
New Revision: 299759

URL: http://llvm.org/viewvc/llvm-project?rev=299759=rev
Log:
[scan-build-py] merge runner module to analyzer

Differential Revision: https://reviews.llvm.org/D31237

Removed:
cfe/trunk/tools/scan-build-py/libscanbuild/runner.py
cfe/trunk/tools/scan-build-py/tests/unit/test_runner.py
Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/__init__.py
cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/test_report.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=299759=299758=299759=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Fri Apr  7 06:04:49 
2017
@@ -16,18 +16,23 @@ import os
 import os.path
 import json
 import logging
-import tempfile
 import multiprocessing
+import tempfile
+import functools
+import subprocess
 import contextlib
 import datetime
+
 from libscanbuild import command_entry_point, compiler_wrapper, \
-wrapper_environment, run_build
+wrapper_environment, run_build, run_command
 from libscanbuild.arguments import parse_args_for_scan_build, \
 parse_args_for_analyze_build
-from libscanbuild.runner import run
 from libscanbuild.intercept import capture
 from libscanbuild.report import document
-from libscanbuild.compilation import split_command
+from libscanbuild.compilation import split_command, classify_source, \
+compiler_language
+from libscanbuild.clang import get_version, get_arguments
+from libscanbuild.shell import decode
 
 __all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
 
@@ -51,7 +56,7 @@ def scan_build():
 exit_code = capture(args)
 # Run the analyzer against the captured commands.
 if need_analyzer(args.build):
-run_analyzer(args)
+run_analyzer_parallel(args)
 else:
 # Run build command and analyzer with compiler wrappers.
 environment = setup_environment(args)
@@ -70,7 +75,7 @@ def analyze_build():
 # will re-assign the report directory as new output
 with report_directory(args.output, args.keep_empty) as args.output:
 # Run the analyzer against a compilation db.
-run_analyzer(args)
+run_analyzer_parallel(args)
 # Cover report generation and bug counting.
 number_of_bugs = document(args)
 # Set exit status as it was requested.
@@ -90,7 +95,7 @@ def need_analyzer(args):
 return len(args) and not re.search('configure|autogen', args[0])
 
 
-def run_analyzer(args):
+def run_analyzer_parallel(args):
 """ Runs the analyzer against the given compilation database. """
 
 def exclude(filename):
@@ -259,3 +264,277 @@ def analyzer_params(args):
 result.append('-analyzer-viz-egraph-ubigraph')
 
 return prefix_with('-Xclang', result)
+
+
+def require(required):
+""" Decorator for checking the required values in state.
+
+It checks the required attributes in the passed state and stop when
+any of those is missing. """
+
+def decorator(function):
+@functools.wraps(function)
+def wrapper(*args, **kwargs):
+for key in required:
+if key not in args[0]:
+raise KeyError('{0} not passed to {1}'.format(
+key, function.__name__))
+
+return function(*args, **kwargs)
+
+return wrapper
+
+return decorator
+
+
+@require(['command',  # entry from compilation database
+  'directory',  # entry from compilation database
+  'file',  # entry from compilation database
+  'clang',  # clang executable name (and path)
+  'direct_args',  # arguments from command line
+  'force_debug',  # kill non debug macros
+  'output_dir',  # where generated report files shall go
+  'output_format',  # it's 'plist' or 'html' or both
+  'output_failures'])  # generate crash reports or not
+def run(opts):
+""" Entry point to run (or not) static analyzer against a single entry
+of the compilation database.
+
+This complex task is decomposed into smaller methods which are calling
+each other in chain. If the analyzis is not possibe the given method
+just return and break the chain.
+
+The passed parameter is a python dictionary. Each method first check
+that the needed parameters received. (This is done by the 'require'
+decorator. It's like an 'assert' to check the contract between the
+caller and the called method.) """
+
+try:
+command = opts.pop('command')
+command = command if isinstance(command, list) 

r298355 - [scan-build-py] reuse command line output parameter for report directory

2017-03-21 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Tue Mar 21 05:15:18 2017
New Revision: 298355

URL: http://llvm.org/viewvc/llvm-project?rev=298355=rev
Log:
[scan-build-py] reuse command line output parameter for report directory

Differential Revision: https://reviews.llvm.org/D30861

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/report.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=298355=298354=298355=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Tue Mar 21 05:15:18 
2017
@@ -40,7 +40,8 @@ def scan_build():
 """ Entry point for scan-build command. """
 
 args = parse_args_for_scan_build()
-with report_directory(args.output, args.keep_empty) as target_dir:
+# will re-assign the report directory as new output
+with report_directory(args.output, args.keep_empty) as args.output:
 # Run against a build command. there are cases, when analyzer run
 # is not required. But we need to set up everything for the
 # wrappers, because 'configure' needs to capture the CC/CXX values
@@ -50,13 +51,13 @@ def scan_build():
 exit_code = capture(args)
 # Run the analyzer against the captured commands.
 if need_analyzer(args.build):
-run_analyzer(args, target_dir)
+run_analyzer(args)
 else:
 # Run build command and analyzer with compiler wrappers.
-environment = setup_environment(args, target_dir)
+environment = setup_environment(args)
 exit_code = run_build(args.build, env=environment)
 # Cover report generation and bug counting.
-number_of_bugs = document(args, target_dir, False)
+number_of_bugs = document(args)
 # Set exit status as it was requested.
 return number_of_bugs if args.status_bugs else exit_code
 
@@ -66,11 +67,12 @@ def analyze_build():
 """ Entry point for analyze-build command. """
 
 args = parse_args_for_analyze_build()
-with report_directory(args.output, args.keep_empty) as target_dir:
+# will re-assign the report directory as new output
+with report_directory(args.output, args.keep_empty) as args.output:
 # Run the analyzer against a compilation db.
-run_analyzer(args, target_dir)
+run_analyzer(args)
 # Cover report generation and bug counting.
-number_of_bugs = document(args, target_dir, True)
+number_of_bugs = document(args)
 # Set exit status as it was requested.
 return number_of_bugs if args.status_bugs else 0
 
@@ -88,7 +90,7 @@ def need_analyzer(args):
 return len(args) and not re.search('configure|autogen', args[0])
 
 
-def run_analyzer(args, output_dir):
+def run_analyzer(args):
 """ Runs the analyzer against the given compilation database. """
 
 def exclude(filename):
@@ -98,7 +100,7 @@ def run_analyzer(args, output_dir):
 
 consts = {
 'clang': args.clang,
-'output_dir': output_dir,
+'output_dir': args.output,
 'output_format': args.output_format,
 'output_failures': args.output_failures,
 'direct_args': analyzer_params(args),
@@ -120,7 +122,7 @@ def run_analyzer(args, output_dir):
 pool.join()
 
 
-def setup_environment(args, destination):
+def setup_environment(args):
 """ Set up environment for build command to interpose compiler wrapper. """
 
 environment = dict(os.environ)
@@ -129,7 +131,7 @@ def setup_environment(args, destination)
 'CC': COMPILER_WRAPPER_CC,
 'CXX': COMPILER_WRAPPER_CXX,
 'ANALYZE_BUILD_CLANG': args.clang if need_analyzer(args.build) else '',
-'ANALYZE_BUILD_REPORT_DIR': destination,
+'ANALYZE_BUILD_REPORT_DIR': args.output,
 'ANALYZE_BUILD_REPORT_FORMAT': args.output_format,
 'ANALYZE_BUILD_REPORT_FAILURES': 'yes' if args.output_failures else '',
 'ANALYZE_BUILD_PARAMETERS': ' '.join(analyzer_params(args)),

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/report.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/report.py?rev=298355=298354=298355=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/report.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/report.py Tue Mar 21 05:15:18 
2017
@@ -18,58 +18,60 @@ import plistlib
 import glob
 import json
 import logging
+import datetime
 from libscanbuild import duplicate_check
 from libscanbuild.clang import get_version
 
 __all__ = ['document']
 
 
-def document(args, output_dir, use_cdb):
+def document(args):
 """ Generates cover 

r298238 - [scan-build-py] use python tempfile for tempdir

2017-03-20 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Mon Mar 20 04:03:24 2017
New Revision: 298238

URL: http://llvm.org/viewvc/llvm-project?rev=298238=rev
Log:
[scan-build-py] use python tempfile for tempdir

Differential Revision: https://reviews.llvm.org/D30862

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py?rev=298238=298237=298238=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py Mon Mar 20 04:03:24 
2017
@@ -41,12 +41,6 @@ def duplicate_check(method):
 return predicate
 
 
-def tempdir():
-""" Return the default temorary directory. """
-
-return os.getenv('TMPDIR', os.getenv('TEMP', os.getenv('TMP', '/tmp')))
-
-
 def run_build(command, *args, **kwargs):
 """ Run and report build command execution
 

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py?rev=298238=298237=298238=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py Mon Mar 20 04:03:24 
2017
@@ -17,7 +17,8 @@ import os
 import sys
 import argparse
 import logging
-from libscanbuild import reconfigure_logging, tempdir
+import tempfile
+from libscanbuild import reconfigure_logging
 from libscanbuild.clang import get_checkers
 
 __all__ = ['parse_args_for_intercept_build', 'parse_args_for_analyze_build',
@@ -187,7 +188,7 @@ def create_analyze_parser(from_build_com
 '--output',
 '-o',
 metavar='',
-default=tempdir(),
+default=tempfile.gettempdir(),
 help="""Specifies the output directory for analyzer reports.
 Subdirectory will be created if default directory is targeted.""")
 output.add_argument(

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py?rev=298238=298237=298238=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py Mon Mar 20 04:03:24 
2017
@@ -31,7 +31,7 @@ import logging
 from libear import build_libear, TemporaryDirectory
 from libscanbuild import command_entry_point, compiler_wrapper, \
 wrapper_environment, run_command, run_build
-from libscanbuild import duplicate_check, tempdir
+from libscanbuild import duplicate_check
 from libscanbuild.compilation import split_command
 from libscanbuild.arguments import parse_args_for_intercept_build
 from libscanbuild.shell import encode, decode
@@ -84,7 +84,7 @@ def capture(args):
 for entry in itertools.chain(previous, current)
 if os.path.exists(entry['file']) and not duplicate(entry))
 
-with TemporaryDirectory(prefix='intercept-', dir=tempdir()) as tmp_dir:
+with TemporaryDirectory(prefix='intercept-') as tmp_dir:
 # run the build command
 environment = setup_environment(args, tmp_dir)
 exit_code = run_build(args.build, env=environment)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r297308 - [scan-build-py] move argument parsing into separate module

2017-03-08 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Wed Mar  8 15:22:32 2017
New Revision: 297308

URL: http://llvm.org/viewvc/llvm-project?rev=297308=rev
Log:
[scan-build-py] move argument parsing into separate module

Forgot to add the new module.

Added:
cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py

Added: cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py?rev=297308=auto
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py (added)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/arguments.py Wed Mar  8 15:22:32 
2017
@@ -0,0 +1,430 @@
+# -*- coding: utf-8 -*-
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+""" This module parses and validates arguments for command-line interfaces.
+
+It uses argparse module to create the command line parser. (This library is
+in the standard python library since 3.2 and backported to 2.7, but not
+earlier.)
+
+It also implements basic validation methods, related to the command.
+Validations are mostly calling specific help methods, or mangling values.
+"""
+
+import os
+import sys
+import argparse
+import logging
+from libscanbuild import reconfigure_logging, tempdir
+from libscanbuild.clang import get_checkers
+
+__all__ = ['parse_args_for_intercept_build', 'parse_args_for_analyze_build',
+   'parse_args_for_scan_build']
+
+
+def parse_args_for_intercept_build():
+""" Parse and validate command-line arguments for intercept-build. """
+
+parser = create_intercept_parser()
+args = parser.parse_args()
+
+reconfigure_logging(args.verbose)
+logging.debug('Raw arguments %s', sys.argv)
+
+# short validation logic
+if not args.build:
+parser.error(message='missing build command')
+
+logging.debug('Parsed arguments: %s', args)
+return args
+
+
+def parse_args_for_analyze_build():
+""" Parse and validate command-line arguments for analyze-build. """
+
+from_build_command = False
+parser = create_analyze_parser(from_build_command)
+args = parser.parse_args()
+
+reconfigure_logging(args.verbose)
+logging.debug('Raw arguments %s', sys.argv)
+
+normalize_args_for_analyze(args, from_build_command)
+validate_args_for_analyze(parser, args, from_build_command)
+logging.debug('Parsed arguments: %s', args)
+return args
+
+
+def parse_args_for_scan_build():
+""" Parse and validate command-line arguments for scan-build. """
+
+from_build_command = True
+parser = create_analyze_parser(from_build_command)
+args = parser.parse_args()
+
+reconfigure_logging(args.verbose)
+logging.debug('Raw arguments %s', sys.argv)
+
+normalize_args_for_analyze(args, from_build_command)
+validate_args_for_analyze(parser, args, from_build_command)
+logging.debug('Parsed arguments: %s', args)
+return args
+
+
+def normalize_args_for_analyze(args, from_build_command):
+""" Normalize parsed arguments for analyze-build and scan-build.
+
+:param args: Parsed argument object. (Will be mutated.)
+:param from_build_command: Boolean value tells is the command suppose
+to run the analyzer against a build command or a compilation db. """
+
+# make plugins always a list. (it might be None when not specified.)
+if args.plugins is None:
+args.plugins = []
+
+# make exclude directory list unique and absolute.
+uniq_excludes = set(os.path.abspath(entry) for entry in args.excludes)
+args.excludes = list(uniq_excludes)
+
+# because shared codes for all tools, some common used methods are
+# expecting some argument to be present. so, instead of query the args
+# object about the presence of the flag, we fake it here. to make those
+# methods more readable. (it's an arguable choice, took it only for those
+# which have good default value.)
+if from_build_command:
+# add cdb parameter invisibly to make report module working.
+args.cdb = 'compile_commands.json'
+
+
+def validate_args_for_analyze(parser, args, from_build_command):
+""" Command line parsing is done by the argparse module, but semantic
+validation still needs to be done. This method is doing it for
+analyze-build and scan-build commands.
+
+:param parser: The command line parser object.
+:param args: Parsed argument object.
+:param from_build_command: Boolean value tells is the command suppose
+to run the analyzer against a build command or a compilation db.
+:return: No return value, but this call might throw when validation
+fails. """
+
+if args.help_checkers_verbose:
+print_checkers(get_checkers(args.clang, args.plugins))
+parser.exit(status=0)
+elif args.help_checkers:
+

r297307 - [scan-build-py] move argument parsing into separate module

2017-03-08 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Wed Mar  8 15:18:51 2017
New Revision: 297307

URL: http://llvm.org/viewvc/llvm-project?rev=297307=rev
Log:
[scan-build-py] move argument parsing into separate module

Differential Revision: https://reviews.llvm.org/D30601

Modified:
cfe/trunk/tools/scan-build-py/bin/analyze-build
cfe/trunk/tools/scan-build-py/bin/intercept-build
cfe/trunk/tools/scan-build-py/bin/scan-build
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py

Modified: cfe/trunk/tools/scan-build-py/bin/analyze-build
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-build?rev=297307=297306=297307=diff
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-build (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-build Wed Mar  8 15:18:51 2017
@@ -13,5 +13,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.analyze import analyze_build_main
-sys.exit(analyze_build_main(this_dir, False))
+from libscanbuild.analyze import analyze_build
+sys.exit(analyze_build())

Modified: cfe/trunk/tools/scan-build-py/bin/intercept-build
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-build?rev=297307=297306=297307=diff
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-build (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-build Wed Mar  8 15:18:51 2017
@@ -13,5 +13,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.intercept import intercept_build_main
-sys.exit(intercept_build_main(this_dir))
+from libscanbuild.intercept import intercept_build
+sys.exit(intercept_build())

Modified: cfe/trunk/tools/scan-build-py/bin/scan-build
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/scan-build?rev=297307=297306=297307=diff
==
--- cfe/trunk/tools/scan-build-py/bin/scan-build (original)
+++ cfe/trunk/tools/scan-build-py/bin/scan-build Wed Mar  8 15:18:51 2017
@@ -13,5 +13,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.analyze import analyze_build_main
-sys.exit(analyze_build_main(this_dir, True))
+from libscanbuild.analyze import scan_build
+sys.exit(scan_build())

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=297307=297306=297307=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Wed Mar  8 15:18:51 
2017
@@ -11,73 +11,68 @@ To run the static analyzer against a bui
  -- Analyze:   run the analyzer against the captured commands,
  -- Report:create a cover report from the analyzer outputs.  """
 
-import sys
 import re
 import os
 import os.path
 import json
-import argparse
 import logging
 import tempfile
 import multiprocessing
 import contextlib
 import datetime
 from libscanbuild import command_entry_point, compiler_wrapper, \
-wrapper_environment, reconfigure_logging, run_build, tempdir
+wrapper_environment, run_build
+from libscanbuild.arguments import parse_args_for_scan_build, \
+parse_args_for_analyze_build
 from libscanbuild.runner import run
 from libscanbuild.intercept import capture
 from libscanbuild.report import document
-from libscanbuild.clang import get_checkers
 from libscanbuild.compilation import split_command
 
-__all__ = ['analyze_build_main', 'analyze_compiler_wrapper']
+__all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
 
 COMPILER_WRAPPER_CC = 'analyze-cc'
 COMPILER_WRAPPER_CXX = 'analyze-c++'
 
 
 @command_entry_point
-def analyze_build_main(bin_dir, from_build_command):
-""" Entry point for 'analyze-build' and 'scan-build'. """
-
-parser = create_parser(from_build_command)
-args = parser.parse_args()
-validate(parser, args, from_build_command)
-
-# setup logging
-reconfigure_logging(args.verbose)
-logging.debug('Raw arguments %s', sys.argv)
+def scan_build():
+""" Entry point for scan-build command. """
 
+args = parse_args_for_scan_build()
 with report_directory(args.output, args.keep_empty) as target_dir:
-if not from_build_command:
-# run analyzer only and generate cover report
-run_analyzer(args, target_dir)
-number_of_bugs = document(args, target_dir, True)
-return number_of_bugs if args.status_bugs else 0
-elif 

r297266 - [scan-build-py] fix some line separator issues

2017-03-08 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Wed Mar  8 03:27:53 2017
New Revision: 297266

URL: http://llvm.org/viewvc/llvm-project?rev=297266=rev
Log:
[scan-build-py] fix some line separator issues

Differential Revision: https://reviews.llvm.org/D30600

Modified:
cfe/trunk/tools/scan-build-py/libear/__init__.py
cfe/trunk/tools/scan-build-py/libscanbuild/report.py

Modified: cfe/trunk/tools/scan-build-py/libear/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libear/__init__.py?rev=297266=297265=297266=diff
==
--- cfe/trunk/tools/scan-build-py/libear/__init__.py (original)
+++ cfe/trunk/tools/scan-build-py/libear/__init__.py Wed Mar  8 03:27:53 2017
@@ -207,9 +207,9 @@ class Configure(object):
 if m:
 key = m.group(1)
 if key not in definitions or not definitions[key]:
-return '/* #undef {} */\n'.format(key)
+return '/* #undef {0} */{1}'.format(key, os.linesep)
 else:
-return '#define {}\n'.format(key)
+return '#define {0}{1}'.format(key, os.linesep)
 return line
 
 with open(template, 'r') as src_handle:

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/report.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/report.py?rev=297266=297265=297266=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/report.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/report.py Wed Mar  8 03:27:53 
2017
@@ -336,11 +336,12 @@ def parse_crash(filename):
 
 match = re.match(r'(.*)\.info\.txt', filename)
 name = match.group(1) if match else None
-with open(filename) as handler:
-lines = handler.readlines()
+with open(filename, mode='rb') as handler:
+# this is a workaround to fix windows read '\r\n' as new lines.
+lines = [line.decode().rstrip() for line in handler.readlines()]
 return {
-'source': lines[0].rstrip(),
-'problem': lines[1].rstrip(),
+'source': lines[0],
+'problem': lines[1],
 'file': name,
 'info': name + '.info.txt',
 'stderr': name + '.stderr.txt'


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r296937 - [scan-build-py] create decorator for compiler wrapper methods

2017-03-03 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Fri Mar  3 19:08:05 2017
New Revision: 296937

URL: http://llvm.org/viewvc/llvm-project?rev=296937=rev
Log:
[scan-build-py] create decorator for compiler wrapper methods

Differential Revision: https://reviews.llvm.org/D29260

Modified:
cfe/trunk/tools/scan-build-py/bin/analyze-c++
cfe/trunk/tools/scan-build-py/bin/analyze-cc
cfe/trunk/tools/scan-build-py/bin/intercept-c++
cfe/trunk/tools/scan-build-py/bin/intercept-cc
cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py

Modified: cfe/trunk/tools/scan-build-py/bin/analyze-c++
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-c%2B%2B?rev=296937=296936=296937=diff
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-c++ (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-c++ Fri Mar  3 19:08:05 2017
@@ -10,5 +10,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.analyze import analyze_build_wrapper
-sys.exit(analyze_build_wrapper(True))
+from libscanbuild.analyze import analyze_compiler_wrapper
+sys.exit(analyze_compiler_wrapper())

Modified: cfe/trunk/tools/scan-build-py/bin/analyze-cc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-cc?rev=296937=296936=296937=diff
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-cc (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-cc Fri Mar  3 19:08:05 2017
@@ -10,5 +10,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.analyze import analyze_build_wrapper
-sys.exit(analyze_build_wrapper(False))
+from libscanbuild.analyze import analyze_compiler_wrapper
+sys.exit(analyze_compiler_wrapper())

Modified: cfe/trunk/tools/scan-build-py/bin/intercept-c++
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-c%2B%2B?rev=296937=296936=296937=diff
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-c++ (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-c++ Fri Mar  3 19:08:05 2017
@@ -10,5 +10,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.intercept import intercept_build_wrapper
-sys.exit(intercept_build_wrapper(True))
+from libscanbuild.intercept import intercept_compiler_wrapper
+sys.exit(intercept_compiler_wrapper())

Modified: cfe/trunk/tools/scan-build-py/bin/intercept-cc
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-cc?rev=296937=296936=296937=diff
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-cc (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-cc Fri Mar  3 19:08:05 2017
@@ -10,5 +10,5 @@ import os.path
 this_dir = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.dirname(this_dir))
 
-from libscanbuild.intercept import intercept_build_wrapper
-sys.exit(intercept_build_wrapper(False))
+from libscanbuild.intercept import intercept_compiler_wrapper
+sys.exit(intercept_compiler_wrapper())

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py?rev=296937=296936=296937=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py Fri Mar  3 19:08:05 
2017
@@ -4,13 +4,21 @@
 # This file is distributed under the University of Illinois Open Source
 # License. See LICENSE.TXT for details.
 """ This module is a collection of methods commonly used in this project. """
+import collections
 import functools
+import json
 import logging
 import os
 import os.path
+import re
+import shlex
 import subprocess
 import sys
 
+ENVIRONMENT_KEY = 'INTERCEPT_BUILD'
+
+Execution = collections.namedtuple('Execution', ['pid', 'cwd', 'cmd'])
+
 
 def duplicate_check(method):
 """ Predicate to detect duplicated entries.
@@ -75,31 +83,53 @@ def run_command(command, cwd=None):
 raise ex
 
 
-def initialize_logging(verbose_level):
-""" Output content controlled by the verbosity level. """
+def reconfigure_logging(verbose_level):
+""" Reconfigure logging level and format based on the verbose flag.
 
-level = logging.WARNING - min(logging.WARNING, (10 * verbose_level))
+:param verbose_level: number of `-v` flags received by the command
+:return: no 

r295045 - [scan-build-py] move function report_directory from report module to analyze module

2017-02-14 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Tue Feb 14 04:43:38 2017
New Revision: 295045

URL: http://llvm.org/viewvc/llvm-project?rev=295045=rev
Log:
[scan-build-py] move function report_directory from report module to analyze 
module

Differential Revision: https://reviews.llvm.org/D29255

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/report.py
cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/test_report.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=295045=295044=295045=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Tue Feb 14 04:43:38 
2017
@@ -18,13 +18,16 @@ import os.path
 import json
 import argparse
 import logging
+import tempfile
 import subprocess
 import multiprocessing
+import contextlib
+import datetime
 from libscanbuild import initialize_logging, tempdir, command_entry_point, \
 run_build
 from libscanbuild.runner import run
 from libscanbuild.intercept import capture
-from libscanbuild.report import report_directory, document
+from libscanbuild.report import document
 from libscanbuild.clang import get_checkers
 from libscanbuild.compilation import split_command
 
@@ -190,6 +193,39 @@ def analyze_build_wrapper(cplusplus):
 return result
 
 
+@contextlib.contextmanager
+def report_directory(hint, keep):
+""" Responsible for the report directory.
+
+hint -- could specify the parent directory of the output directory.
+keep -- a boolean value to keep or delete the empty report directory. """
+
+stamp_format = 'scan-build-%Y-%m-%d-%H-%M-%S-%f-'
+stamp = datetime.datetime.now().strftime(stamp_format)
+parent_dir = os.path.abspath(hint)
+if not os.path.exists(parent_dir):
+os.makedirs(parent_dir)
+name = tempfile.mkdtemp(prefix=stamp, dir=parent_dir)
+
+logging.info('Report directory created: %s', name)
+
+try:
+yield name
+finally:
+if os.listdir(name):
+msg = "Run 'scan-view %s' to examine bug reports."
+keep = True
+else:
+if keep:
+msg = "Report directory '%s' contains no report, but kept."
+else:
+msg = "Removing directory '%s' because it contains no report."
+logging.warning(msg, name)
+
+if not keep:
+os.rmdir(name)
+
+
 def analyzer_params(args):
 """ A group of command line arguments can mapped to command
 line arguments of the analyzer. This method generates those. """

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/report.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/report.py?rev=295045=295044=295045=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/report.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/report.py Tue Feb 14 04:43:38 
2017
@@ -13,54 +13,15 @@ import os
 import os.path
 import sys
 import shutil
-import time
-import tempfile
 import itertools
 import plistlib
 import glob
 import json
 import logging
-import contextlib
-import datetime
 from libscanbuild import duplicate_check
 from libscanbuild.clang import get_version
 
-__all__ = ['report_directory', 'document']
-
-
-@contextlib.contextmanager
-def report_directory(hint, keep):
-""" Responsible for the report directory.
-
-hint -- could specify the parent directory of the output directory.
-keep -- a boolean value to keep or delete the empty report directory. """
-
-stamp_format = 'scan-build-%Y-%m-%d-%H-%M-%S-%f-'
-stamp = datetime.datetime.now().strftime(stamp_format)
-
-parentdir = os.path.abspath(hint)
-if not os.path.exists(parentdir):
-os.makedirs(parentdir)
-
-name = tempfile.mkdtemp(prefix=stamp, dir=parentdir)
-
-logging.info('Report directory created: %s', name)
-
-try:
-yield name
-finally:
-if os.listdir(name):
-msg = "Run 'scan-view %s' to examine bug reports."
-keep = True
-else:
-if keep:
-msg = "Report directory '%s' contans no report, but kept."
-else:
-msg = "Removing directory '%s' because it contains no report."
-logging.warning(msg, name)
-
-if not keep:
-os.rmdir(name)
+__all__ = ['document']
 
 
 def document(args, output_dir, use_cdb):

Modified: cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py?rev=295045=295044=295045=diff

r295043 - [scan-build-py] use subprocess wrapper to execute build

2017-02-14 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Tue Feb 14 04:30:50 2017
New Revision: 295043

URL: http://llvm.org/viewvc/llvm-project?rev=295043=rev
Log:
[scan-build-py] use subprocess wrapper to execute build

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py?rev=295043=295042=295043=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py Tue Feb 14 04:30:50 
2017
@@ -39,6 +39,19 @@ def tempdir():
 return os.getenv('TMPDIR', os.getenv('TEMP', os.getenv('TMP', '/tmp')))
 
 
+def run_build(command, *args, **kwargs):
+""" Run and report build command execution
+
+:param command: array of tokens
+:return: exit code of the process
+"""
+environment = kwargs.get('env', os.environ)
+logging.debug('run build %s, in environment: %s', command, environment)
+exit_code = subprocess.call(command, *args, **kwargs)
+logging.debug('build finished with exit code: %d', exit_code)
+return exit_code
+
+
 def run_command(command, cwd=None):
 """ Run a given command and report the execution.
 

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=295043=295042=295043=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Tue Feb 14 04:30:50 
2017
@@ -20,7 +20,8 @@ import argparse
 import logging
 import subprocess
 import multiprocessing
-from libscanbuild import initialize_logging, tempdir, command_entry_point
+from libscanbuild import initialize_logging, tempdir, command_entry_point, \
+run_build
 from libscanbuild.runner import run
 from libscanbuild.intercept import capture
 from libscanbuild.report import report_directory, document
@@ -70,9 +71,7 @@ def analyze_build_main(bin_dir, from_bui
 # run the build command with compiler wrappers which
 # execute the analyzer too. (interposition)
 environment = setup_environment(args, target_dir, bin_dir)
-logging.debug('run build in environment: %s', environment)
-exit_code = subprocess.call(args.build, env=environment)
-logging.debug('build finished with exit code: %d', exit_code)
+exit_code = run_build(args.build, env=environment)
 # cover report generation and bug counting
 number_of_bugs = document(args, target_dir, False)
 # set exit status as it was requested

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py?rev=295043=295042=295043=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py Tue Feb 14 04:30:50 
2017
@@ -31,7 +31,7 @@ import argparse
 import logging
 import subprocess
 from libear import build_libear, TemporaryDirectory
-from libscanbuild import command_entry_point, run_command
+from libscanbuild import command_entry_point, run_build, run_command
 from libscanbuild import duplicate_check, tempdir, initialize_logging
 from libscanbuild.compilation import split_command
 from libscanbuild.shell import encode, decode
@@ -95,9 +95,7 @@ def capture(args, bin_dir):
 with TemporaryDirectory(prefix='intercept-', dir=tempdir()) as tmp_dir:
 # run the build command
 environment = setup_environment(args, tmp_dir, bin_dir)
-logging.debug('run build in environment: %s', environment)
-exit_code = subprocess.call(args.build, env=environment)
-logging.info('build finished with exit code: %d', exit_code)
+exit_code = run_build(args.build, env=environment)
 # read the intercepted exec calls
 exec_traces = itertools.chain.from_iterable(
 parse_exec_trace(os.path.join(tmp_dir, filename))


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293397 - [scan-build-py] remove batch files

2017-01-28 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Sat Jan 28 16:55:25 2017
New Revision: 293397

URL: http://llvm.org/viewvc/llvm-project?rev=293397=rev
Log:
[scan-build-py] remove batch files

Removed:
cfe/trunk/tools/scan-build-py/bin/analyze-build.bat
cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat
cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat
cfe/trunk/tools/scan-build-py/bin/intercept-build.bat
cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat
cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat
cfe/trunk/tools/scan-build-py/bin/scan-build.bat

Removed: cfe/trunk/tools/scan-build-py/bin/analyze-build.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-build.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-build.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-build.bat (removed)
@@ -1 +0,0 @@
-python %~dp0analyze-build %*

Removed: cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-c%2B%2B.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-c++.bat (removed)
@@ -1 +0,0 @@
-python %~dp0analyze-c++ %*

Removed: cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/analyze-cc.bat (removed)
@@ -1 +0,0 @@
-python %~dp0analyze-cc %*

Removed: cfe/trunk/tools/scan-build-py/bin/intercept-build.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-build.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-build.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-build.bat (removed)
@@ -1 +0,0 @@
-python %~dp0intercept-build %*

Removed: cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-c%2B%2B.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-c++.bat (removed)
@@ -1 +0,0 @@
-python %~dp0intercept-c++ %*

Removed: cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/intercept-cc.bat (removed)
@@ -1 +0,0 @@
-python %~dp0intercept-cc %*

Removed: cfe/trunk/tools/scan-build-py/bin/scan-build.bat
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/bin/scan-build.bat?rev=293396=auto
==
--- cfe/trunk/tools/scan-build-py/bin/scan-build.bat (original)
+++ cfe/trunk/tools/scan-build-py/bin/scan-build.bat (removed)
@@ -1 +0,0 @@
-python %~dp0scan-build %*


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293396 - [scan-build-py] use subprocess wrapper

2017-01-28 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Sat Jan 28 16:48:26 2017
New Revision: 293396

URL: http://llvm.org/viewvc/llvm-project?rev=293396=rev
Log:
[scan-build-py] use subprocess wrapper

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
cfe/trunk/tools/scan-build-py/libscanbuild/clang.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py
cfe/trunk/tools/scan-build-py/libscanbuild/runner.py
cfe/trunk/tools/scan-build-py/tests/unit/test_intercept.py
cfe/trunk/tools/scan-build-py/tests/unit/test_runner.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py?rev=293396=293395=293396=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/__init__.py Sat Jan 28 16:48:26 
2017
@@ -3,10 +3,13 @@
 #
 # This file is distributed under the University of Illinois Open Source
 # License. See LICENSE.TXT for details.
-"""
-This module responsible to run the Clang static analyzer against any build
-and generate reports.
-"""
+""" This module is a collection of methods commonly used in this project. """
+import functools
+import logging
+import os
+import os.path
+import subprocess
+import sys
 
 
 def duplicate_check(method):
@@ -33,16 +36,35 @@ def duplicate_check(method):
 def tempdir():
 """ Return the default temorary directory. """
 
-from os import getenv
-return getenv('TMPDIR', getenv('TEMP', getenv('TMP', '/tmp')))
+return os.getenv('TMPDIR', os.getenv('TEMP', os.getenv('TMP', '/tmp')))
+
+
+def run_command(command, cwd=None):
+""" Run a given command and report the execution.
+
+:param command: array of tokens
+:param cwd: the working directory where the command will be executed
+:return: output of the command
+"""
+def decode_when_needed(result):
+""" check_output returns bytes or string depend on python version """
+return result.decode('utf-8') if isinstance(result, bytes) else result
+
+try:
+directory = os.path.abspath(cwd) if cwd else os.getcwd()
+logging.debug('exec command %s in %s', command, directory)
+output = subprocess.check_output(command,
+ cwd=directory,
+ stderr=subprocess.STDOUT)
+return decode_when_needed(output).splitlines()
+except subprocess.CalledProcessError as ex:
+ex.output = decode_when_needed(ex.output).splitlines()
+raise ex
 
 
 def initialize_logging(verbose_level):
 """ Output content controlled by the verbosity level. """
 
-import sys
-import os.path
-import logging
 level = logging.WARNING - min(logging.WARNING, (10 * verbose_level))
 
 if verbose_level <= 3:
@@ -57,9 +79,6 @@ def initialize_logging(verbose_level):
 def command_entry_point(function):
 """ Decorator for command entry points. """
 
-import functools
-import logging
-
 @functools.wraps(function)
 def wrapper(*args, **kwargs):
 

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/clang.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/clang.py?rev=293396=293395=293396=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/clang.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/clang.py Sat Jan 28 16:48:26 2017
@@ -9,8 +9,7 @@ Since Clang command line interface is so
 a subset of that, it makes sense to create a function specific wrapper. """
 
 import re
-import subprocess
-import logging
+from libscanbuild import run_command
 from libscanbuild.shell import decode
 
 __all__ = ['get_version', 'get_arguments', 'get_checkers']
@@ -25,8 +24,9 @@ def get_version(clang):
 :param clang:   the compiler we are using
 :return:the version string printed to stderr """
 
-output = subprocess.check_output([clang, '-v'], stderr=subprocess.STDOUT)
-return output.decode('utf-8').splitlines()[0]
+output = run_command([clang, '-v'])
+# the relevant version info is in the first line
+return output[0]
 
 
 def get_arguments(command, cwd):
@@ -38,12 +38,11 @@ def get_arguments(command, cwd):
 
 cmd = command[:]
 cmd.insert(1, '-###')
-logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))
 
-output = subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)
+output = run_command(cmd, cwd=cwd)
 # The relevant information is in the last line of the output.
 # Don't check if finding last line fails, would throw exception anyway.
-last_line = output.decode('utf-8').splitlines()[-1]
+last_line = output[-1]
 if re.search(r'clang(.*): error:', last_line):
 raise Exception(last_line)
 return decode(last_line)

Re: [PATCH] D19260: [analyzer][scan-build-py] subprocess output handling reviewed in clang module

2016-09-23 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist closed this revision.
rizsotto.mailinglist added a comment.

commited at r282317


https://reviews.llvm.org/D19260



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r282317 - [analyzer][scan-build-py] subprocess output handling reviewed in clang module

2016-09-23 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Fri Sep 23 19:20:59 2016
New Revision: 282317

URL: http://llvm.org/viewvc/llvm-project?rev=282317=rev
Log:
[analyzer][scan-build-py] subprocess output handling reviewed in clang module

Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/clang.py
cfe/trunk/tools/scan-build-py/tests/unit/test_clang.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=282317=282316=282317=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Fri Sep 23 19:20:59 
2016
@@ -269,6 +269,9 @@ def validate(parser, args, from_build_co
 """ Validation done by the parser itself, but semantic check still
 needs to be done. This method is doing that. """
 
+# Make plugins always a list. (It might be None when not specified.)
+args.plugins = args.plugins if args.plugins else []
+
 if args.help_checkers_verbose:
 print_checkers(get_checkers(args.clang, args.plugins))
 parser.exit()

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/clang.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/clang.py?rev=282317=282316=282317=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/clang.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/clang.py Fri Sep 23 19:20:59 2016
@@ -15,142 +15,143 @@ from libscanbuild.shell import decode
 
 __all__ = ['get_version', 'get_arguments', 'get_checkers']
 
+# regex for activated checker
+ACTIVE_CHECKER_PATTERN = re.compile(r'^-analyzer-checker=(.*)$')
 
-def get_version(cmd):
-""" Returns the compiler version as string. """
 
-lines = subprocess.check_output([cmd, '-v'], stderr=subprocess.STDOUT)
-return lines.decode('ascii').splitlines()[0]
+def get_version(clang):
+""" Returns the compiler version as string.
+
+:param clang:   the compiler we are using
+:return:the version string printed to stderr """
+
+output = subprocess.check_output([clang, '-v'], stderr=subprocess.STDOUT)
+return output.decode('utf-8').splitlines()[0]
 
 
 def get_arguments(command, cwd):
 """ Capture Clang invocation.
 
-This method returns the front-end invocation that would be executed as
-a result of the given driver invocation. """
-
-def lastline(stream):
-last = None
-for line in stream:
-last = line
-if last is None:
-raise Exception("output not found")
-return last
+:param command: the compilation command
+:param cwd: the current working directory
+:return:the detailed front-end invocation command """
 
 cmd = command[:]
 cmd.insert(1, '-###')
 logging.debug('exec command in %s: %s', cwd, ' '.join(cmd))
-child = subprocess.Popen(cmd,
- cwd=cwd,
- universal_newlines=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
-line = lastline(child.stdout)
-child.stdout.close()
-child.wait()
-if child.returncode == 0:
-if re.search(r'clang(.*): error:', line):
-raise Exception(line)
-return decode(line)
-else:
-raise Exception(line)
+
+output = subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)
+# The relevant information is in the last line of the output.
+# Don't check if finding last line fails, would throw exception anyway.
+last_line = output.decode('utf-8').splitlines()[-1]
+if re.search(r'clang(.*): error:', last_line):
+raise Exception(last_line)
+return decode(last_line)
 
 
 def get_active_checkers(clang, plugins):
-""" To get the default plugins we execute Clang to print how this
-compilation would be called.
+""" Get the active checker list.
 
-For input file we specify stdin and pass only language information. """
+:param clang:   the compiler we are using
+:param plugins: list of plugins which was requested by the user
+:return:list of checker names which are active
+
+To get the default checkers we execute Clang to print how this
+compilation would be called. And take out the enabled checker from the
+arguments. For input file we specify stdin and pass only language
+information. """
 
-def checkers(language):
+def get_active_checkers_for(language):
 """ Returns a list of active checkers for the given language. """
 
-load = [elem
-for plugin in plugins
-for elem in ['-Xclang', '-load', '-Xclang', plugin]]
-cmd = [clang, 

Re: [PATCH] D24470: [analyzer] scan-build-py: Remove relative path hack for SATestsBuild.py

2016-09-13 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist accepted this revision.
rizsotto.mailinglist added a comment.
This revision is now accepted and ready to land.

thanks Devin, i like smaller code, have no problem with this change. :)

about the file/directory paths: i agree that the situation is not ideal. but 
there are/were strict constrains on how a compilation database shall look like. 
once a year i ask the question 
 on the 
mailing list about it. the situation might have been improved since... besides, 
using absolute path is actually the safest bet we can make. (other tools doing 
the same (CMake is a good example)) would not invest time into this until i see 
it got broken.


https://reviews.llvm.org/D24470



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24040: codechecker tool core

2016-09-02 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

In https://reviews.llvm.org/D24040#532718, @o.gyorgy wrote:

> In https://reviews.llvm.org/D24040#530293, @rizsotto.mailinglist wrote:
>
> > Gyorgy and the ericsson team, thanks for doing this. very good job! good 
> > targeted functionality. i don't want to underestimate the complexity it 
> > requires, but to me this is a giant code. i do miss the explanation of the 
> > overall functional description what a module does and how it relates to 
> > other modules. i found a gap between the high level overview and the code 
> > comments.
>
>
> Would that help If update architecture.md documentation (which gives a high 
> level overview) to be more in sync with the source code, with additional 
> comments and descriptions in the modules?


i prefer python docstrings instead of the markdown files. found that the 
`__init__.py` files are empty. those are good candidates for a higher overview 
of the package architecture. now module headers are one liners most of the 
places, which is a missed opportunity to document the connections between the 
modules. method docstrings are non descriptive enough. (echoing back the 
function names with spaces.) would read about the usage of the method, contract 
between the caller and the callee, or the implementation difficulties.

> > generally speaking i found this code under documented and a bit verbose. 
> > the comments in the code is not really paint the picture that i need in 
> > order to fix a bug, or implement a feature. and it might only be my 
> > personal taste, but found that creating types (or classes this case) in a 
> > dynamically typed script language, it makes the code very verbose while it 
> > does not implement much.

> 

> 

> We use classes to handle and setup environment, build, analyzer and other 
> configurations. In the infrastructure this makes available to easily 
> introduce new analyzers and handle the output of them. Multiple output 
> handling is supported for each analyzer (print to stdout, store to database).


yes, i got that you were using OO. and try to re-use code this way... my point 
is, this abstraction, in this language, ends up to have an abstract class with 
empty methods, a couple of implementations and the user of the abstract class, 
which enjoys the polymorphism. to understand a single implementation i have to 
read (at least) three different modules/files. it's very fragmented to me... my 
proposal would be, to write util methods. implement the different analyzer 
commands as a combination of the util methods. this abstraction fits better to 
a script language. it also make your code more dense, less verbose, easier to 
maintain, test or reason about... those was my two cents.


https://reviews.llvm.org/D24040



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24163: [scan-build-py] Increase precision of timestamp in report directory name

2016-09-02 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

looks good to me. i like the test. :) but would keep the `pep8` cleanness.



Comment at: tools/scan-build-py/libscanbuild/report.py:38
@@ -36,3 +37,3 @@
 
-stamp = time.strftime('scan-build-%Y-%m-%d-%H%M%S-', time.localtime())
+stamp = 
datetime.datetime.now().strftime('scan-build-%Y-%m-%d-%H-%M-%S-%f-')
 

this line length's is 80, which breaks the `pep8` check. (would kill some of 
the `-`)


https://reviews.llvm.org/D24163



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24040: codechecker tool core

2016-08-31 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

Gyorgy and the ericsson team, thanks for doing this. very good job! good 
targeted functionality. i don't want to underestimate the complexity it 
requires, but to me this is a giant code. i do miss the explanation of the 
overall functional description what a module does and how it relates to other 
modules. i found a gap between the high level overview and the code comments.
generally speaking i found this code under documented and a bit verbose. the 
comments in the code is not really paint the picture that i need in order to 
fix a bug, or implement a feature. and it might only be my personal taste, but 
found that creating types (or classes this case) in a dynamically typed script 
language, it makes the code very verbose while it does not implement much.
was commented only on two random modules, but found the same patterns in many 
other ones.
found that this code is not `pep8` conform. `pylint` found a lot of errors and 
warnings, and a couple of duplicate codes.
i hope we can fix these findings and that would make this code more solid and 
understood by others.



Comment at: tools/codechecker/bin/CodeChecker:35
@@ +34,3 @@
+
+python = os.path.join('python')
+common_lib = os.path.join(package_root,

wow, that looks woodoo. can you explain (in code comment) why is that necessary?


Comment at: tools/codechecker/bin/CodeChecker:67
@@ +66,3 @@
+
+original_env = os.environ.copy()
+checker_env = original_env

can you explain (in code comment) why are you playing with the environment? 
what problem does it solve and why do you need a backup?


Comment at: tools/codechecker/bin/CodeChecker:70
@@ +69,3 @@
+
+tmp_dir = tempfile.mkdtemp()
+

can you backport `tempfile.TemporaryDirectory` (from python 3.2) in one of your 
modules and use it inside `with` for proper resource guarding?


Comment at: tools/codechecker/bin/CodeChecker:85
@@ +84,3 @@
+pid = os.getpid()
+for p in procPool:
+os.kill(p, signal.SIGINT)

why not store the `subprocess.Popen` object and send signal via `send_signal`? 
(that would make it more portable too.)


Comment at: tools/codechecker/libcodechecker/build_manager.py:30
@@ +29,3 @@
+"""
+proc = subprocess.Popen(command,
+bufsize=-1,

is there any reason not to use `subprocess.call` instead? if you want that to 
be in silent, you shall pass `{'stdout': subprocess.PIPE, 'stderr': 
subprocess.STDOUT}` to it, otherwise it prints the output without you doing the 
copy. also noticed the `shell=True` which makes it very non-portable. and the 
`command` parameter is a string instead of a list. is there any reason for 
doing like this?


Comment at: tools/codechecker/libcodechecker/build_manager.py:55
@@ +54,3 @@
+
+try:
+original_env_file = os.environ['CODECHECKER_ORIGINAL_BUILD_ENV']

save-to-file and restore-from-file the environment would deserve a separate 
module i would say. is there any reason why it's not having those utility 
methods?


Comment at: tools/codechecker/libcodechecker/build_manager.py:131
@@ +130,3 @@
+return None
+except AttributeError as ex:
+# args.log_file was not set

why not have a command line parameter accessor method, that would either return 
the value if that was given or None? i found this pattern multiple files. that 
would get rid of the `try` block completely.


Comment at: tools/codechecker/libcodechecker/build_manager.py:150
@@ +149,3 @@
+
+if intercept_build_executable == None:
+if platform.system() == 'Linux':

`if intercept_build_executable is None:` would be more python.


Comment at: tools/codechecker/libcodechecker/build_manager.py:169
@@ +168,3 @@
+
+open(log_file, 'a').close()  # same as linux's touch
+

the comment is not really helpful!
why does it need a touch? or you just create an empty one? what for?


Comment at: tools/codechecker/libcodechecker/build_manager.py:177
@@ +176,3 @@
+except AttributeError as aerr:
+LOG.error(aerr)
+sys.exit(1)

`logger.exception` is logging the exception value implicitly at `ERROR` level 
too. but what i'm trying to say is, there is no error message in this line. you 
just throw the exception into the user face. can you add some explanation or 
instruction for the user?


https://reviews.llvm.org/D24040



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19260: [analyzer][scan-build-py] subprocess output handling reviewed in clang module

2016-06-12 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

hey Devin, thanks for looking to it.



Comment at: tools/scan-build-py/libscanbuild/clang.py:90
@@ -89,2 +89,3 @@
 
-{: (, )} """
+predicate.patterns = [re.compile(r'^' + a + r'(\.|$)') for a in checkers]
+return predicate

dcoughlin wrote:
> What's the benefit of using a function attribute here rather than simply 
> closing over a local variable?
there is no difference between the two. (it even can be written in the same 
order.) i guess, just wanted to decorate the name of the variable. i have no 
preference.


http://reviews.llvm.org/D19260



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r266726 - D17487: [analyzer][scan-build-py] flag filter modification for compilation database creation

2016-04-19 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Tue Apr 19 07:03:03 2016
New Revision: 266726

URL: http://llvm.org/viewvc/llvm-project?rev=266726=rev
Log:
D17487: [analyzer][scan-build-py] flag filter modification for compilation 
database creation

Added:
cfe/trunk/tools/scan-build-py/libscanbuild/compilation.py
cfe/trunk/tools/scan-build-py/tests/functional/src/build/Makefile
cfe/trunk/tools/scan-build-py/tests/unit/test_compilation.py
cfe/trunk/tools/scan-build-py/tests/unit/test_libear.py
Removed:
cfe/trunk/tools/scan-build-py/libscanbuild/command.py
cfe/trunk/tools/scan-build-py/tests/unit/fixtures.py
cfe/trunk/tools/scan-build-py/tests/unit/test_command.py
Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/intercept.py
cfe/trunk/tools/scan-build-py/libscanbuild/runner.py
cfe/trunk/tools/scan-build-py/tests/functional/cases/test_create_cdb.py
cfe/trunk/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py
cfe/trunk/tools/scan-build-py/tests/functional/cases/test_from_cdb.py
cfe/trunk/tools/scan-build-py/tests/functional/cases/test_from_cmd.py
cfe/trunk/tools/scan-build-py/tests/unit/__init__.py
cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/test_clang.py
cfe/trunk/tools/scan-build-py/tests/unit/test_intercept.py
cfe/trunk/tools/scan-build-py/tests/unit/test_report.py
cfe/trunk/tools/scan-build-py/tests/unit/test_runner.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=266726=266725=266726=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Tue Apr 19 07:03:03 
2016
@@ -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']
 
@@ -107,7 +106,7 @@ def run_analyzer(args, output_dir):
 'output_format': args.output_format,
 'output_failures': args.output_failures,
 'direct_args': analyzer_params(args),
-'force_analyze_debug_code' : args.force_analyze_debug_code
+'force_debug': args.force_debug
 }
 
 logging.debug('run analyzer against compilation database')
@@ -140,8 +139,7 @@ def setup_environment(args, 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_FORCE_ANALYZE_DEBUG_CODE'
-: 'yes' if args.force_analyze_debug_code else ''
+'ANALYZE_BUILD_FORCE_DEBUG': 'yes' if args.force_debug else ''
 })
 return environment
 
@@ -163,32 +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_analyze_debug_code':
-os.getenv('ANALYZE_BUILD_FORCE_ANALYZE_DEBUG_CODE'),
+'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
 

Re: [PATCH] D17091: [analyzer][scan-build-py] Non-existing directory for scan-build output.

2016-02-20 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

the semicolon at the end of line 39 is an issue for PEP8. please remove it.


http://reviews.llvm.org/D17091



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17091: [analyzer][scan-build-py] Non-existing directory for scan-build output.

2016-02-20 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist accepted this revision.
rizsotto.mailinglist added a comment.
This revision is now accepted and ready to land.

thanks Anton, LGTM!


http://reviews.llvm.org/D17091



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r257533 - D9600: Add scan-build python implementation

2016-01-13 Thread Laszlo Nagy via cfe-commits
yes, it is just an initial drop. improvements are planed to make a full
replacement of the one written in Perl.

On Thu, Jan 14, 2016 at 12:14 AM, Ismail Donmez <ism...@i10z.com> wrote:

> Hi,
>
> On Wed, Jan 13, 2016 at 12:38 AM, Laszlo Nagy via cfe-commits
> <cfe-commits@lists.llvm.org> wrote:
> > Author: rizsotto
> > Date: Tue Jan 12 16:38:41 2016
> > New Revision: 257533
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=257533=rev
> > Log:
> > D9600: Add scan-build python implementation
>
> This doesn't seem to be installed by default, is that intended?
>
> Regards,
> ismail
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2016-01-12 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

Thank you guys for your review and help! The latest patch is commited. Let's do 
the next steps too. ;)

@danielmarjamaki the standalone Bear will be maintained. and your comments will 
also be considered.


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2016-01-05 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

sorry for the delay, hard to get free time these days. ;)



Comment at: tools/scan-build-py/libscanbuild/intercept.py:146
@@ +145,3 @@
+})
+elif sys.platform == 'darwin':
+logging.debug('intercept gonna preload libear on OSX')

dcoughlin wrote:
> Can you change this to default to compiler-wrapper interposition on Darwin 
> with a command-line flag to force library-based interposition?
> 
> Library-based interposition will fail silently if SIP is enabled, so this 
> should be detected when that flag is passed so the user is informed. You can 
> detect whether SIP is enabled on Darwin by checking whether (1) there is a 
> binary called 'csrutil' in the path and, if so, (2) whether the output of 
> executing 'csrutil status' contains 'System Integrity Protection status: 
> enabled'.
> 
> 
ok, implemented the SIP check. (also added SELinux check, which behaves the 
same as SIP.)

about the default behavior: `scan-build` command has the other compiler-wrapper 
(run compiler & analyzer) and flags can turn this module on. `intercept-build` 
default is the library-based and flag can turn the compiler-wrapper 
interposition on... i would keep it this way. (and also not make platform 
dependent switches into the code.)


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-12-14 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added inline comments.


Comment at: tools/scan-build-py/libear/ear.c:142
@@ +141,3 @@
+#endif
+if (!initialized)
+initialized = bear_capture_env_t(_env);

dcoughlin wrote:
> rizsotto.mailinglist wrote:
> > rizsotto.mailinglist wrote:
> > > to run the full test set
> > > 
> > > > PATH=$(pwd)/bin:$PATH python -m unittest discover
> > > 
> > > to run that specific test
> > > 
> > > > PATH=$(pwd)/bin:$PATH python -m unittest -v 
> > > > tests.functional.cases.test_create_cdb.CompilationDatabaseTest.test_successful_build_on_empty_env
> > > 
> > > to more about run tests
> > > 
> > > https://docs.python.org/2/library/unittest.html
> > my understanding on the `_NSGetEnviron` is, that it shall be used when the 
> > library is during the load process. later when the build process calls 
> > `execv` the load process is over, and `environ` variable is available. an 
> > earlier version of this code had a `get_environ` method, which were either 
> > return the `environ` variable or called the `_NSGetEnviron`. then i made 
> > this change and the tests were still passing, so i don't see where your 
> > issue is coming from. please tell me what kind of test you run against it 
> > to find it as problem. would like to add it to the test suite.
> Aaah, I had an ancient libscanbuild in my global site-packages, which seemed 
> to cause `unittest discover` to not work.
> 
> When running the above on your latest patch on a machine without SIP I get.
> 
> ```
> test_successful_build_on_empty_env 
> (tests.functional.cases.test_create_cdb.CompilationDatabaseTest) ... ERROR
> 
> ==
> ERROR: test_successful_build_on_empty_env 
> (tests.functional.cases.test_create_cdb.CompilationDatabaseTest)
> --
> Traceback (most recent call last):
>   File "tests/functional/cases/test_create_cdb.py", line 58, in 
> test_successful_build_on_empty_env
> 'env', '-'] + make)
>   File "tests/functional/cases/__init__.py", line 38, in silent_check_call
> return subprocess.check_call(cmd, *args, **kwargs)
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",
>  line 540, in check_call
> raise CalledProcessError(retcode, cmd)
> CalledProcessError: Command '['intercept-build', '--cdb', 
> '/var/folders/mq/46lsd1kx65v5702dzrkgzdlrgn/T/scan-build-test-cKXza1/cdb.json',
>  'env', '-', 'make', 'SRCDIR=tests/functional/src', 
> 'OBJDIR=/var/folders/mq/46lsd1kx65v5702dzrkgzdlrgn/T/scan-build-test-cKXza1',
>  '-f', 'tests/functional/src/build/Makefile', 'CC=clang', 'build_regular']' 
> returned non-zero exit status 2
> 
> --
> Ran 1 test in 0.554s
> 
> FAILED (errors=1)
> ```
> This goes away if you use my suggested *_NSGetEnviron() fix above.
> After applying that fix, all but 6 test past on OS X without SIP. The 
> remaining 6 failures are due to your use of mknod() in tests, which requires 
> superuser privileges on OS X:
> 
> 
> ```
> ==
> ERROR: test_interposition_cxx_works 
> (tests.functional.cases.test_from_cmd.RunAnalyzerTest)
> --
> Traceback (most recent call last):
>   File 
> "/Volumes/Data/Clangs/OpenSourceGit/clang/tools/scan-build-py/tests/functional/cases/test_from_cmd.py",
>  line 102, in test_interposition_cxx_works
> self.compile_empty_source_file(tmpdir, True))
>   File 
> "/Volumes/Data/Clangs/OpenSourceGit/clang/tools/scan-build-py/tests/functional/cases/test_from_cmd.py",
>  line 87, in compile_empty_source_file
> os.mknod(src_file)
> OSError: [Errno 1] Operation not permitted
> ```
> 
> Is there a more portable way to create an empty file? Perhaps open a file for 
> writing and then closing it?
> 
> 
> With SIP I see different failures:
> 
> ```
> workzilla:scan-build-py dcoughlin$ PATH=$(pwd)/bin:$PATH python -m unittest 
> -v 
> tests.functional.cases.test_create_cdb.CompilationDatabaseTest.test_successful_build_on_empty_env
> test_successful_build_on_empty_env 
> (tests.functional.cases.test_create_cdb.CompilationDatabaseTest) ... FAIL
> 
> ==
> FAIL: test_successful_build_on_empty_env 
> (tests.functional.cases.test_create_cdb.CompilationDatabaseTest)
> --
> Traceback (most recent call last):
>   File "tests/functional/cases/test_create_cdb.py", line 60, in 
> test_successful_build_on_empty_env
> self.assertEqual(5, self.count_entries(result))
> AssertionError: 5 != 0
> 
> --
> Ran 1 test in 1.069s
> 
> FAILED (failures=1)
> ```
> 
> Running the entire 

Re: [PATCH] D9600: Add scan-build python implementation

2015-12-11 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist marked 6 inline comments as done.


Comment at: tools/scan-build-py/README.md:86
@@ +85,3 @@
+The 2. mode is available only on FreeBSD, Linux and OSX. Where library preload
+is available from the dynamic loader. On OSX System Integrity Protection 
security
+feature enabled prevents library preload, so this method will not work in such

zaks.anna wrote:
> This is very unfortunate!
> 
> We should call out that library interposition is "not supported on OS X 
> (unless System Integrity Protection feature is turned off)" and return an 
> error if people are trying to use it (and System Integrity Protection feature 
> is turned on).
comment changed. please hint me with some code how can the script detect SIP 
status. (or postpone the check implementation after the patch is accepted)


Comment at: tools/scan-build-py/bin/analyze-c++:3
@@ +2,3 @@
+# -*- coding: utf-8 -*-
+# The LLVM Compiler Infrastructure
+#

zaks.anna wrote:
> I searched the code and did not see it being called. By looking back at the 
> previous revision I see that that libscanbuild.analyze.main used to call 
> 'analyze-cxx' not 'analyze-c++'. Looks like you've also fixed the same bug 
> with 'intercept-c++'. 
> 
> Is this something that could/would be caught by the tests?
test harness contains only C files, that was the reason this could have gone 
unnoticed. added specific check for it.


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-12-10 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist marked an inline comment as done.


Comment at: tools/scan-build-py/bin/analyze-c++:2
@@ +1,3 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# The LLVM Compiler Infrastructure

zaks.anna wrote:
> Where/How is analyze-c++ used?
this is the compiler wrapper which runs the real compiler + the static 
analyzer. (you guys were call it interposition mode) there is 'analyze-c++' and 
'analyze-cc' for C++ and C compilers. it is used from the 
libscanbuild.analyze.main method.


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-12-10 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added inline comments.


Comment at: tools/scan-build-py/libear/ear.c:141
@@ +140,3 @@
+environ = *_NSGetEnviron();
+#endif
+if (!initialized)

this call just sets up the `environ` variables for the `bear_capture_env_t` 
method, two lines down. that call saves the relevant variables... so, if before 
execv'ing somebody modify the variables we still have it saved. (by the way 
`Scons` is the tool which does this.) and when `call_execve` called it recovers 
from the saved environment.

there is a test against it. (tests/functional/cases/test_create_cdb.py:53)

> The issue I am seeing with library-interposition on OS X [...]

can you give me details what did you see? what was the test you were running?


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-12-10 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist marked 7 inline comments as done.
rizsotto.mailinglist added a comment.

thanks for the comments.



Comment at: tools/scan-build-py/bin/analyze-c++:1
@@ +1,2 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-

zaks.anna wrote:
> What calls this script?
sorry, don't get the question


Comment at: tools/scan-build-py/libscanbuild/runner.py:23
@@ +22,3 @@
+""" Decorator for checking the required values in state.
+
+It checks the required attributes in the passed state and stop when

dcoughlin wrote:
> Ok. If I create a patch with additional documentation for these fields, would 
> you be willing to take a look at it to make sure the comments are correct?
sure


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-12-10 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added inline comments.


Comment at: tools/scan-build-py/libear/ear.c:282
@@ +281,3 @@
+DLSYM(func, fp, "execve");
+
+char const **const menvp = bear_update_environment(envp, _env);

okay, since i don't have access for OSX machines can you help me to make it 
right?


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-12-09 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist marked an inline comment as done.
rizsotto.mailinglist added a comment.

> Also, what do you think about renaming intercept-build to "log-build" or some 
> of the other alternatives I proposed above? I think it is important for the 
> name of the executable to communicate its purpose.


i do think differently. :) first, i think you can rename executables to 
whatever you like. previously i made this functionality in a tool called Bear. 
within 4 years got more than 100 bug reports, improvement ideas, but nobody did 
care about the executable name. second, i'm not a native speaker, but to me 
'intercept compiler calls from build' can be shortened to 'intercept-build'. 
third, if i rename the executable from intercept-build, shall rename the 
intercept module too? and to be honest, the executable name scan-build just as 
bad as intercept-build. :) if i did not convinced you, give me a name and i 
will rename to it.



Comment at: tools/scan-build-py/MANIFEST.in:2
@@ +1,3 @@
+include README.md
+include *.txt
+recursive-include libear *

dcoughlin wrote:
> I see that at https://pypi.python.org/pypi/scan-build it lists clang as a 
> prerequisite. But since scan-build-py will now be distributed as part of 
> clang I don't understand what the point of the standalone tool is. Can you 
> explain why this is needed?
thought to have more distribution channel is better. but if that so confusing, 
i've deleted it.


Comment at: tools/scan-build-py/libscanbuild/driver.py:67
@@ +66,3 @@
+except Exception:
+logging.exception("Something unexpected had happened.")
+return 127

jroelofs wrote:
> dcoughlin wrote:
> > rizsotto.mailinglist wrote:
> > > jroelofs wrote:
> > > > rizsotto.mailinglist wrote:
> > > > > dcoughlin wrote:
> > > > > > I think this error message can be improved. Perhaps "Unexpected 
> > > > > > error running intercept-build"?
> > > > > this line is printed as:
> > > > > 
> > > > >   intercept-build: ERROR: Something unexpected had happened.
> > > > >   (and the stack-trace)
> > > > > 
> > > > > because the logging formating. so, 'intercept-build' and 'error' will 
> > > > > be part of the message anyway.
> > > > Is there a pythonic way of doing llvm crash handlers? I.e. the "here's 
> > > > the steps to reproduce this, a stack trace, and a bug report url" 
> > > > things that clang spits out.
> > > this crash/exception is not a clang crash. it's more like this program's 
> > > fault. clang crash reports are recorded already in crash report files 
> > > (and linked into the html report file).
> > Maybe this should ask the user to file a bug against scan-build? Can it 
> > point to the bugzilla and tell the user what information, files, etc. they 
> > should attach to the bug report to help us reproduce the problem? Just 
> > saying "Something unexpected happened" is not as user-friendly as it could 
> > be because it does not tell the user that the problem is not their fault 
> > nor what they should do about it.
> Oh, I don't mean to handle clang crashes... I mean for handling python 
> crashes. I meant to draw an analogy to a feature that clang has: when it 
> crashes, it prints a stack trace, and some steps to reproduce the problem.  I 
> was wondering if a similar thing existed in python, for when a python app 
> crashes.
good point. added some implementation. if you don't like the text, please 
suggest one instead and will replace.


Comment at: tools/scan-build-py/libscanbuild/runner.py:22
@@ +21,3 @@
+def require(required):
+""" Decorator for checking the required values in state.
+

the comment says exactly the value coming from the compilation database. anyway 
added more explanations. if you have something in mind, please write the text 
and will copy it.


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-11-20 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist marked 13 inline comments as done.
rizsotto.mailinglist added a comment.

thanks Devin for your comments. made some changes already (will upload it 
tonight after some tests).



Comment at: tools/scan-build-py/CHANGES.txt:1
@@ +1,1 @@
+v,  -- Initial release.

dcoughlin wrote:
> Is this one needed too?
in order to make this code a standalone python tool tool, we need this file. 
(see llvm/utils/lit directory for example.)


Comment at: tools/scan-build-py/MANIFEST.in:1
@@ +1,2 @@
+include README.md
+include *.txt

dcoughlin wrote:
> How about this one? Is it needed in clang trunk?
in order to make this code a standalone python tool tool, we need this file. 
(see llvm/utils/lit directory for example.)


Comment at: tools/scan-build-py/libear/__init__.py:1
@@ +1,2 @@
+# -*- coding: utf-8 -*-
+# The LLVM Compiler Infrastructure

dcoughlin wrote:
> How does this file fit into the overall build picture? Will this file go away 
> once scan-build-py is built with the common clang cmake?
this is quiet confusing me. previously you were asking make it work without 
installation. this file makes it possible to compile the `ear` library compiled 
before the build runs to use as preloaded library. the thing which is not 
needed is the CMakefile actually.


Comment at: tools/scan-build-py/libear/__init__.py:99
@@ +98,3 @@
+def dl_libraries(self):
+pass
+

dcoughlin wrote:
> I gather the intent is that subclasses will override to provide their own 
> versions of these methods? If so, these methods need to be documented so that 
> people adding new support for additional platforms know what they should 
> provide in their subclasses.
> 
> If there are reasonable defaults (for example., `[]` for `dl_libraries`), 
> those should be returned here rather than `pass`. If not, these should 
> probably raise an exception indicating they must be implemented rather than 
> silently doing nothing.
now rise `NotImplementedError` runtime exception.


Comment at: tools/scan-build-py/libear/__init__.py:166
@@ +165,3 @@
+self.ctx = context
+self.results = {'APPLE': sys.platform == 'darwin'}
+

dcoughlin wrote:
> What does this do? Why is it hard-coded?
this is added to mimic `cmake` behaviour. it is used in the `config.h.in` file.


Comment at: tools/scan-build-py/libscanbuild/command.py:20
@@ +19,3 @@
+
+def classify_parameters(command):
+""" Parses the command line arguments of the given invocation. """

dcoughlin wrote:
> I think it would be good to document the keys and meaning of the returned 
> dictionary. Or perhaps it would be better represented as class?
now documented when create the return value. (creating class would not bring 
much to the kitchen i think.)


Comment at: tools/scan-build-py/libscanbuild/command.py:23
@@ +22,3 @@
+
+ignored = {
+'-g': 0,

dcoughlin wrote:
> I think it would good to document what the value in this mapping means 
> (number of expected parameters). I realize ccc-analyzer in the original 
> scan-build is similarly un-documented, but we should do better here!
> 
> Also: should this include all the arguments `IgnoredOptionMap` in 
> ccc-analyzer? It is missing `-u' and adds '-g'. Or are these changes 
> intentional?
`-u` is part of ignored linker flags. (see a few line above)
`-g` is added to mimic the `ccc-analyzer` results.
comment about key, value is added.


Comment at: tools/scan-build-py/libscanbuild/driver.py:1
@@ +1,2 @@
+# -*- coding: utf-8 -*-
+# The LLVM Compiler Infrastructure

dcoughlin wrote:
> Why is this file called "driver"?
any recommendation? it was the only entry point before the interposition was 
introduced. so it was the driver of the libscanbuild library.


Comment at: tools/scan-build-py/libscanbuild/driver.py:34
@@ +33,3 @@
+def main(bin_dir):
+""" Entry point for 'scan-build'. """
+

dcoughlin wrote:
> Should this be 'intercept-build'?
can be anything, but would make it rhyme with the module name...


Comment at: tools/scan-build-py/libscanbuild/driver.py:67
@@ +66,3 @@
+except Exception:
+logging.exception("Something unexpected had happened.")
+return 127

dcoughlin wrote:
> I think this error message can be improved. Perhaps "Unexpected error running 
> intercept-build"?
this line is printed as:

  intercept-build: ERROR: Something unexpected had happened.
  (and the stack-trace)

because the logging formating. so, 'intercept-build' and 'error' will be part 
of the message anyway.


Comment at: tools/scan-build-py/libscanbuild/intercept.py:98
@@ +97,3 @@
+
+if args.override_compiler or not ear_library_path:

Re: [PATCH] D14629: [analyzer] Configuration file for scan-build.

2015-11-19 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

I think the `scan-build` user experience would be improved by config file! And 
I really like how the `clang-tidy` guys were doing it. (In case if you are not 
familiar with it, copy from the help output)

  Configuration files:
clang-tidy attempts to read configuration for each source file from a
.clang-tidy file located in the closest parent directory of the source
file. If any configuration options have a corresponding command-line
option, command-line option takes precedence. The effective
configuration can be inspected using -dump-config:
  
$ clang-tidy -dump-config - --
  ---
  Checks:  '-*,some-check'
  HeaderFilterRegex: ''
  AnalyzeTemporaryDtors: false
  User:user
  CheckOptions:
- key: some-check.SomeOption
  value:   'some value'
  ...

So the major difference from the current patch would be:

- It's not a windows .ini file, but YAML/JSON syntax.
- No need to provide default config file and check into the source repository.
- Loading of the config file is a bit more complex logic, than taking value 
from a specific location.

Benefit for the user to have common usage pattern of the clang related analyzer 
tools. What do you think?


http://reviews.llvm.org/D14629



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-11-17 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

In http://reviews.llvm.org/D9600#290031, @jroelofs wrote:

> Thanks for re-uploading!


thanks for your comments! :)

most of your comments are about to embed it more into the clang build, test 
infrastructure. i think these are valid points!

i would like to have these code in the repository first and to do -the work 
you've proposed- afterwards. i might need help for some of those too. (like 
using lint to run python unit tests.)


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-11-12 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

In http://reviews.llvm.org/D9600#287157, @jroelofs wrote:

> Would you mind re-uploading this patch as a diff against upstream trunk with 
> full context?


i'm not sure i do understand what do you ask. i wish i could upload these 
changes as a single patch, but don't know is that possible?


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D9600: Add scan-build python implementation

2015-11-09 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist updated this revision to Diff 39703.
rizsotto.mailinglist added a comment.

findings from compare from older Perl implementation


http://reviews.llvm.org/D9600

Files:
  tools/scan-build-py/README.md
  tools/scan-build-py/libear/CMakeLists.txt
  tools/scan-build-py/libear/__init__.py
  tools/scan-build-py/libear/config.h.in
  tools/scan-build-py/libear/ear.c
  tools/scan-build-py/libscanbuild/clang.py
  tools/scan-build-py/libscanbuild/command.py
  tools/scan-build-py/libscanbuild/driver.py
  tools/scan-build-py/libscanbuild/intercept.py
  tools/scan-build-py/libscanbuild/interposition.py
  tools/scan-build-py/libscanbuild/options.py
  tools/scan-build-py/libscanbuild/report.py
  tools/scan-build-py/libscanbuild/runner.py
  tools/scan-build-py/libscanbuild/shell.py
  tools/scan-build-py/setup.py
  tools/scan-build-py/tests/functional/cases/__init__.py
  tools/scan-build-py/tests/functional/cases/test_from_cdb.py
  tools/scan-build-py/tests/functional/cases/test_from_cmd.py
  tools/scan-build-py/tests/functional/exec/main.c
  tools/scan-build-py/tests/functional/src/build/Makefile
  tools/scan-build-py/tests/unit/__init__.py
  tools/scan-build-py/tests/unit/test_clang.py
  tools/scan-build-py/tests/unit/test_command.py
  tools/scan-build-py/tests/unit/test_intercept.py
  tools/scan-build-py/tests/unit/test_runner.py
  tools/scan-build-py/tests/unit/test_shell.py

Index: tools/scan-build-py/tests/unit/test_shell.py
===
--- /dev/null
+++ tools/scan-build-py/tests/unit/test_shell.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+
+import libscanbuild.shell as sut
+import unittest
+
+
+class ShellTest(unittest.TestCase):
+
+def test_encode_decode_are_same(self):
+def test(value):
+self.assertEqual(sut.encode(sut.decode(value)), value)
+
+test("")
+test("clang")
+test("clang this and that")
+
+def test_decode_encode_are_same(self):
+def test(value):
+self.assertEqual(sut.decode(sut.encode(value)), value)
+
+test([])
+test(['clang'])
+test(['clang', 'this', 'and', 'that'])
+test(['clang', 'this and', 'that'])
+test(['clang', "it's me", 'again'])
+test(['clang', 'some "words" are', 'quoted'])
+
+def test_encode(self):
+self.assertEqual(sut.encode(['clang', "it's me", 'again']),
+ 'clang "it\'s me" again')
+self.assertEqual(sut.encode(['clang', "it(s me", 'again)']),
+ 'clang "it(s me" "again)"')
+self.assertEqual(sut.encode(['clang', 'redirect > it']),
+ 'clang "redirect > it"')
+self.assertEqual(sut.encode(['clang', '-DKEY="VALUE"']),
+ 'clang -DKEY=\\"VALUE\\"')
+self.assertEqual(sut.encode(['clang', '-DKEY="value with spaces"']),
+ 'clang -DKEY=\\"value with spaces\\"')
Index: tools/scan-build-py/tests/unit/test_runner.py
===
--- tools/scan-build-py/tests/unit/test_runner.py
+++ tools/scan-build-py/tests/unit/test_runner.py
@@ -141,18 +141,19 @@
 def test(expected, input):
 spy = fixtures.Spy()
 self.assertEqual(spy.success, sut.language_check(input, spy.call))
-self.assertEqual(expected, spy.arg)
+self.assertEqual(expected, spy.arg['language'])
 
 l = 'language'
 f = 'file'
-i = 'cxx'
-test({f: 'file.c', l: 'c'}, {f: 'file.c', l: 'c'})
-test({f: 'file.c', l: 'c++'}, {f: 'file.c', l: 'c++'})
-test({f: 'file.c', l: 'c++', i: True}, {f: 'file.c', i: True})
-test({f: 'file.c', l: 'c'}, {f: 'file.c'})
-test({f: 'file.cxx', l: 'c++'}, {f: 'file.cxx'})
-test({f: 'file.i', l: 'c-cpp-output'}, {f: 'file.i'})
-test({f: 'f.i', l: 'c-cpp-output'}, {f: 'f.i', l: 'c-cpp-output'})
+i = 'c++'
+test('c',   {f: 'file.c', l: 'c', i: False})
+test('c++', {f: 'file.c', l: 'c++', i: False})
+test('c++', {f: 'file.c', i: True})
+test('c',   {f: 'file.c', i: False})
+test('c++', {f: 'file.cxx', i: False})
+test('c-cpp-output',   {f: 'file.i', i: False})
+test('c++-cpp-output', {f: 'file.i', i: True})
+test('c-cpp-output',   {f: 'f.i', l: 'c-cpp-output', i: True})
 
 def test_arch_loop(self):
 def test(input):
@@ -163,16 +164,16 @@
 input = {'key': 'value'}
 self.assertEqual(input, test(input))
 
-input = {'archs_seen': ['-arch', 'i386']}
+input = {'archs_seen': ['i386']}
 self.assertEqual({'arch': 'i386'}, test(input))
 
-input = {'archs_seen': ['-arch', 'ppc']}
+input = 

Re: [PATCH] D9600: Add scan-build python implementation

2015-11-09 Thread Laszlo Nagy via cfe-commits
rizsotto.mailinglist added a comment.

the latest update has the following improvements:

- makes it work without installation.
- pass the `SATestBuild.py` test harness against different projects with 
`--strictness 2` arguments. (coreutils-8.23, gawk-4.1.1, make-4.0, 
openssl-1.0.0s, patch-2.7.4, tar-1.28) these minor adjustments were needed.
  - get silents when it runs against `configure` or `autogen`.
  - implements `--override-compiler` which enforce to use compiler wrappers.
  - a couple of minor fixes to get rid of the differences.
- small number of improvement for compilation database generation (mainly shell 
escaping when that's needed). which were learnt form my other project Bear.


http://reviews.llvm.org/D9600



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits