[PATCH] [scan-build] Add an option to skip overriding CC and CXX make vars

2018-01-14 Thread Paul Fertser via cfe-commits
Autoconf and some other systems tend to add essential compilation
options to CC (e.g. -std=gnu99). When running such an auto-generated
makefile, scan-build does not need to change CC and CXX as they are
already set to use ccc-analyzer by a configure script.

Implement a new option --keep-cc as was proposed in this discussion:
http://lists.llvm.org/pipermail/cfe-dev/2013-September/031832.html
---
 tools/scan-build/bin/scan-build | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/tools/scan-build/bin/scan-build b/tools/scan-build/bin/scan-build
index cbf3bf3..49018eb 100755
--- a/tools/scan-build/bin/scan-build
+++ b/tools/scan-build/bin/scan-build
@@ -51,6 +51,7 @@ my %Options = (
   OutputDir => undef,# Parent directory to store HTML files.
   HtmlTitle => basename($CurrentDir)." - scan-build results",
   IgnoreErrors => 0, # Ignore build errors.
+  KeepCC => 0,   # Do not override CC and CXX make variables
   ViewResults => 0,  # View results when the build terminates.
   ExitStatusFoundBugs => 0,  # Exit status reflects whether bugs were found
   ShowDescription => 0,  # Display the description of the defect in the 
list
@@ -1062,6 +1063,7 @@ sub RunXcodebuild {
 sub RunBuildCommand {
   my $Args = shift;
   my $IgnoreErrors = shift;
+  my $KeepCC = shift;
   my $Cmd = $Args->[0];
   my $CCAnalyzer = shift;
   my $CXXAnalyzer = shift;
@@ -1099,8 +1101,10 @@ sub RunBuildCommand {
 unshift @$Args, $CXXAnalyzer;
   }
   elsif ($Cmd eq "make" or $Cmd eq "gmake" or $Cmd eq "mingw32-make") {
-AddIfNotPresent($Args, "CC=$CCAnalyzer");
-AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
+if (!$KeepCC) {
+  AddIfNotPresent($Args, "CC=$CCAnalyzer");
+  AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
+}
 if ($IgnoreErrors) {
   AddIfNotPresent($Args,"-k");
   AddIfNotPresent($Args,"-i");
@@ -1158,6 +1162,12 @@ OPTIONS:
currently supports make and xcodebuild. This is a convenience option; one
can specify this behavior directly using build options.
 
+ --keep-cc
+
+   Do not override CC and CXX make variables. Useful when running make in
+   autoconf-based (and similar) projects where configure can add extra flags
+   to those variables.
+
  --html-title [title]
  --html-title=[title]
 
@@ -1532,6 +1542,12 @@ sub ProcessArgs {
   next;
 }
 
+if ($arg eq "--keep-cc") {
+  shift @$Args;
+  $Options{KeepCC} = 1;
+  next;
+}
+
 if ($arg =~ /^--use-cc(=(.+))?$/) {
   shift @$Args;
   my $cc;
@@ -1838,8 +1854,8 @@ my %EnvVars = (
 );
 
 # Run the build.
-my $ExitStatus = RunBuildCommand(\@ARGV, $Options{IgnoreErrors}, $Cmd, $CmdCXX,
-\%EnvVars);
+my $ExitStatus = RunBuildCommand(\@ARGV, $Options{IgnoreErrors}, 
$Options{KeepCC},
+   $Cmd, $CmdCXX, \%EnvVars);
 
 if (defined $Options{OutputFormat}) {
   if ($Options{OutputFormat} =~ /plist/) {
-- 
2.7.0

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


[PATCH] [analyzer] Fix -x language argument for C preprocessed sources

2018-01-14 Thread Paul Fertser via cfe-commits
clang's -x option doesn't accept c-cpp-output as a language (even though
463eb6ab was merged, the driver still doesn't handle that).

This bug prevents testing C language projects when ccache is used.

Fixes #25851.

Investigation and patch by Dave Rigby.
---
 tools/scan-build/libexec/ccc-analyzer | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/scan-build/libexec/ccc-analyzer 
b/tools/scan-build/libexec/ccc-analyzer
index b0ec7e7..73cd2ff 100755
--- a/tools/scan-build/libexec/ccc-analyzer
+++ b/tools/scan-build/libexec/ccc-analyzer
@@ -419,7 +419,7 @@ my %LangMap = (
   'cc'  => 'c++',
   'C'   => 'c++',
   'ii'  => 'c++-cpp-output',
-  'i'   => $IsCXX ? 'c++-cpp-output' : 'c-cpp-output',
+  'i'   => $IsCXX ? 'c++-cpp-output' : 'cpp-output',
   'm'   => 'objective-c',
   'mi'  => 'objective-c-cpp-output',
   'mm'  => 'objective-c++',
@@ -439,7 +439,7 @@ my %LangsAccepted = (
   "c" => 1,
   "c++" => 1,
   "objective-c++" => 1,
-  "c-cpp-output" => 1,
+  "cpp-output" => 1,
   "objective-c-cpp-output" => 1,
   "c++-cpp-output" => 1
 );
-- 
2.7.0

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


[PATCH] [scan-build] Mention --keep-cc in the HTML documentation

2018-01-15 Thread Paul Fertser via cfe-commits
---

Feel free to squash this into the keep-cc introduction commit if appropriate.

 www/analyzer/scan-build.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/www/analyzer/scan-build.html b/www/analyzer/scan-build.html
index b16f6bb..83efea9 100644
--- a/www/analyzer/scan-build.html
+++ b/www/analyzer/scan-build.html
@@ -248,7 +248,7 @@ you will probably need to run configure script 
through
 
 
 $ scan-build ./configure
-$ scan-build make
+$ scan-build --keep-cc make
 
 
 The reason configure also needs to be run through
-- 
2.7.0

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


Re: [PATCH] [scan-build] Add an option to skip overriding CC and CXX make vars

2018-01-19 Thread Paul Fertser via cfe-commits
Hello Jonathan,

On Mon, Jan 15, 2018 at 08:36:03AM -0700, Jonathan Roelofs wrote:
> LGTM. Would you like me to commit it for you?

Yes, please, commit this patch with my next html documentation patch
squashed into it, and also please commit the ccc-analyzer patch and
close the related ticket as I do not have any permissions.

-- 
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:fercer...@gmail.com
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits