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

Jonathan Roelofs via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 29 08:49:34 PST 2018


Author: jroelofs
Date: Mon Jan 29 08:49:34 2018
New Revision: 323665

URL: http://llvm.org/viewvc/llvm-project?rev=323665&view=rev
Log:
[scan-build] Add an option to skip overriding CC and CXX make vars

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

Patch by Paul Fertser!

Modified:
    cfe/trunk/tools/scan-build/bin/scan-build
    cfe/trunk/www/analyzer/scan-build.html

Modified: cfe/trunk/tools/scan-build/bin/scan-build
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/bin/scan-build?rev=323665&r1=323664&r2=323665&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build/bin/scan-build (original)
+++ cfe/trunk/tools/scan-build/bin/scan-build Mon Jan 29 08:49:34 2018
@@ -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/) {

Modified: cfe/trunk/www/analyzer/scan-build.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/scan-build.html?rev=323665&r1=323664&r2=323665&view=diff
==============================================================================
--- cfe/trunk/www/analyzer/scan-build.html (original)
+++ cfe/trunk/www/analyzer/scan-build.html Mon Jan 29 08:49:34 2018
@@ -248,7 +248,7 @@ you will probably need to run <tt>config
 
 <pre class="code_example">
 $ scan-build ./configure
-$ scan-build make
+$ scan-build --keepk-cc make
 </pre>
 
 <p>The reason <tt>configure</tt> also needs to be run through




More information about the cfe-commits mailing list