[PATCH] D70693: [scan-build-py] Set of small fixes

2019-12-05 Thread Gábor Horváth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8994d632c8d3: [scan-build-py] Set of small fixes (authored 
by xazax.hun).

Changed prior to commit:
  https://reviews.llvm.org/D70693?vs=230960&id=232364#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70693/new/

https://reviews.llvm.org/D70693

Files:
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/clang.py


Index: clang/tools/scan-build-py/libscanbuild/clang.py
===
--- clang/tools/scan-build-py/libscanbuild/clang.py
+++ clang/tools/scan-build-py/libscanbuild/clang.py
@@ -19,6 +19,11 @@
 ACTIVE_CHECKER_PATTERN = re.compile(r'^-analyzer-checker=(.*)$')
 
 
+class ClangErrorException(Exception):
+def __init__(self, error):
+self.error = error
+
+
 def get_version(clang):
 """ Returns the compiler version as string.
 
@@ -39,13 +44,14 @@
 
 cmd = command[:]
 cmd.insert(1, '-###')
+cmd.append('-fno-color-diagnostics')
 
 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[-1]
 if re.search(r'clang(.*): error:', last_line):
-raise Exception(last_line)
+raise ClangErrorException(last_line)
 return decode(last_line)
 
 
Index: clang/tools/scan-build-py/libscanbuild/analyze.py
===
--- clang/tools/scan-build-py/libscanbuild/analyze.py
+++ clang/tools/scan-build-py/libscanbuild/analyze.py
@@ -33,7 +33,8 @@
 from libscanbuild.report import document
 from libscanbuild.compilation import split_command, classify_source, \
 compiler_language
-from libscanbuild.clang import get_version, get_arguments, get_triple_arch
+from libscanbuild.clang import get_version, get_arguments, get_triple_arch, \
+ClangErrorException
 from libscanbuild.shell import decode
 
 __all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
@@ -435,7 +436,7 @@
 of the compilation database.
 
 This complex task is decomposed into smaller methods which are calling
-each other in chain. If the analyzis is not possible the given method
+each other in chain. If the analysis is not possible the given method
 just return and break the chain.
 
 The passed parameter is a python dictionary. Each method first check
@@ -451,7 +452,7 @@
 
 return arch_check(opts)
 except Exception:
-logging.error("Problem occurred during analyzis.", exc_info=1)
+logging.error("Problem occurred during analysis.", exc_info=1)
 return None
 
 
@@ -490,10 +491,15 @@
 os.close(handle)
 # Execute Clang again, but run the syntax check only.
 cwd = opts['directory']
-cmd = get_arguments(
-[opts['clang'], '-fsyntax-only', '-E'
- ] + opts['flags'] + [opts['file'], '-o', name], cwd)
-run_command(cmd, cwd=cwd)
+cmd = [opts['clang'], '-fsyntax-only', '-E'] + opts['flags'] + \
+[opts['file'], '-o', name]
+try:
+cmd = get_arguments(cmd, cwd)
+run_command(cmd, cwd=cwd)
+except subprocess.CalledProcessError:
+pass
+except ClangErrorException:
+pass
 # write general information about the crash
 with open(name + '.info.txt', 'w') as handle:
 handle.write(opts['file'] + os.linesep)
@@ -542,6 +548,12 @@
 opts.update(result)
 continuation(opts)
 return result
+except ClangErrorException as ex:
+result = {'error_output': ex.error, 'exit_code': 0}
+if opts.get('output_failures', False):
+opts.update(result)
+continuation(opts)
+return result
 
 
 def extdef_map_list_src_to_ast(extdef_src_list):


Index: clang/tools/scan-build-py/libscanbuild/clang.py
===
--- clang/tools/scan-build-py/libscanbuild/clang.py
+++ clang/tools/scan-build-py/libscanbuild/clang.py
@@ -19,6 +19,11 @@
 ACTIVE_CHECKER_PATTERN = re.compile(r'^-analyzer-checker=(.*)$')
 
 
+class ClangErrorException(Exception):
+def __init__(self, error):
+self.error = error
+
+
 def get_version(clang):
 """ Returns the compiler version as string.
 
@@ -39,13 +44,14 @@
 
 cmd = command[:]
 cmd.insert(1, '-###')
+cmd.append('-fno-color-diagnostics')
 
 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[-1]
 if re.search(r'clang(.*): error:', last_line):
-raise Exception(last_line)
+raise ClangErrorException(last_line)
 return decode(last_line)
 
 
Index: clang/tools/scan-build-py/libscanbuild/analy

[PATCH] D70693: [scan-build-py] Set of small fixes

2019-12-04 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.

In D70693#1762137 , @xazax.hun wrote:

> So after investigating the effects of this patch, the result is the following:
>
> Verbose mode (`-v`) that also prints findings to the command line will no 
> longer be colored after the patch.


These warning printouts are fairly useless anyway, users still need to read the 
html reports, so I don't care all that much. Thanks for cleaning this up!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70693/new/

https://reviews.llvm.org/D70693



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


[PATCH] D70693: [scan-build-py] Set of small fixes

2019-11-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

So after investigating the effects of this patch, the result is the following:

Verbose mode (`-v`) that also prints findings to the command line will no 
longer be colored after the patch. If we do not want this regression there are 
two easy ways around it:

1. Make the parsing of error more forgiving
2. Make two `-###` invocation, one for parsing the potential error and the 
other for actually getting the arguments.

Any preferences?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70693/new/

https://reviews.llvm.org/D70693



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


[PATCH] D70693: [scan-build-py] Set of small fixes

2019-11-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun marked an inline comment as done.
xazax.hun added inline comments.



Comment at: clang/tools/scan-build-py/libscanbuild/clang.py:47
 cmd.insert(1, '-###')
+cmd.append('-fno-color-diagnostics')
 

phosek wrote:
> Alternative would be to set `TERM=dumb` environment variable which disables 
> color support as well, but this also works.
Thanks! I'd love to have another solution, but it looks like the command line 
takes precedence over the environment variables and if `-fcolor-diagnostics` is 
specified in the command line it will always turn the colors on. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70693/new/

https://reviews.llvm.org/D70693



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


[PATCH] D70693: [scan-build-py] Set of small fixes

2019-11-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/tools/scan-build-py/libscanbuild/clang.py:47
 cmd.insert(1, '-###')
+cmd.append('-fno-color-diagnostics')
 

Alternative would be to set `TERM=dumb` environment variable which disables 
color support as well, but this also works.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70693/new/

https://reviews.llvm.org/D70693



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


[PATCH] D70693: [scan-build-py] Set of small fixes

2019-11-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Sorry, there was a brain hiccup on my side. We just do not generate HTMLs for 
every translation units (which is the case for plists).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70693/new/

https://reviews.llvm.org/D70693



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


[PATCH] D70693: [scan-build-py] Set of small fixes

2019-11-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.
xazax.hun added reviewers: NoQ, haowei, rizsotto.mailinglist.
Herald added subscribers: Charusso, gamesh411, Szelethus, dkrupp, rnkovacs, 
whisperity.
Herald added a project: clang.
xazax.hun added a subscriber: phosek.

This patch fix some small errors in scan-build-py, including:

- When invoking clang with `-###` and parsing error add 
`-fno-color-diagnostics` to the invocation to avoid problems parsing potential 
errors. This might be sub-optimal for users expecting to see the results in the 
command line and expecting to have colors. If we really want this to work I can 
either make the regex more forgiving or try to restore the 
`-fcolor-diagnostics`flag to its original state after the `-###` invocation.
- If a file was missing from a compilation database the whole analysis was 
stopped due to an unhandled exception.
- Fix two typos: analyzis -> analysis


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70693

Files:
  clang/tools/scan-build-py/libscanbuild/analyze.py
  clang/tools/scan-build-py/libscanbuild/clang.py


Index: clang/tools/scan-build-py/libscanbuild/clang.py
===
--- clang/tools/scan-build-py/libscanbuild/clang.py
+++ clang/tools/scan-build-py/libscanbuild/clang.py
@@ -19,6 +19,11 @@
 ACTIVE_CHECKER_PATTERN = re.compile(r'^-analyzer-checker=(.*)$')
 
 
+class ClangErrorException(Exception):
+def __init__(self, error):
+self.error = error
+
+
 def get_version(clang):
 """ Returns the compiler version as string.
 
@@ -39,13 +44,14 @@
 
 cmd = command[:]
 cmd.insert(1, '-###')
+cmd.append('-fno-color-diagnostics')
 
 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[-1]
 if re.search(r'clang(.*): error:', last_line):
-raise Exception(last_line)
+raise ClangErrorException(last_line)
 return decode(last_line)
 
 
Index: clang/tools/scan-build-py/libscanbuild/analyze.py
===
--- clang/tools/scan-build-py/libscanbuild/analyze.py
+++ clang/tools/scan-build-py/libscanbuild/analyze.py
@@ -33,7 +33,8 @@
 from libscanbuild.report import document
 from libscanbuild.compilation import split_command, classify_source, \
 compiler_language
-from libscanbuild.clang import get_version, get_arguments, get_triple_arch
+from libscanbuild.clang import get_version, get_arguments, get_triple_arch, \
+ClangErrorException
 from libscanbuild.shell import decode
 
 __all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
@@ -435,7 +436,7 @@
 of the compilation database.
 
 This complex task is decomposed into smaller methods which are calling
-each other in chain. If the analyzis is not possible the given method
+each other in chain. If the analysis is not possible the given method
 just return and break the chain.
 
 The passed parameter is a python dictionary. Each method first check
@@ -451,7 +452,7 @@
 
 return arch_check(opts)
 except Exception:
-logging.error("Problem occurred during analyzis.", exc_info=1)
+logging.error("Problem occurred during analysis.", exc_info=1)
 return None
 
 
@@ -490,10 +491,13 @@
 os.close(handle)
 # Execute Clang again, but run the syntax check only.
 cwd = opts['directory']
-cmd = get_arguments(
-[opts['clang'], '-fsyntax-only', '-E'
- ] + opts['flags'] + [opts['file'], '-o', name], cwd)
-run_command(cmd, cwd=cwd)
+cmd = [opts['clang'], '-fsyntax-only', '-E'] + opts['flags'] + \
+[opts['file'], '-o', name]
+try:
+cmd = get_arguments(cmd, cwd)
+run_command(cmd, cwd=cwd)
+except ClangErrorException:
+pass
 # write general information about the crash
 with open(name + '.info.txt', 'w') as handle:
 handle.write(opts['file'] + os.linesep)
@@ -542,6 +546,12 @@
 opts.update(result)
 continuation(opts)
 return result
+except ClangErrorException as ex:
+result = {'error_output': ex.error, 'exit_code': 0}
+if opts.get('output_failures', False):
+opts.update(result)
+continuation(opts)
+return result
 
 
 def extdef_map_list_src_to_ast(extdef_src_list):


Index: clang/tools/scan-build-py/libscanbuild/clang.py
===
--- clang/tools/scan-build-py/libscanbuild/clang.py
+++ clang/tools/scan-build-py/libscanbuild/clang.py
@@ -19,6 +19,11 @@
 ACTIVE_CHECKER_PATTERN = re.compile(r'^-analyzer-checker=(.*)$')
 
 
+class ClangErrorException(Exception):
+def __init__(self, error):
+self.error = error
+
+
 def get_version(clang):
 """ Returns the compiler version as string.
 
@@ -39,13 +44,