Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

clang-analyzer: respect $NIX_CFLAGS_COMPILE

When using scan-build, you're often going to want to use it in the
context of a Nix expression with buildInputs, and the default wrapper
scripts will put things like include locations for those inputs
$NIX_CFLAGS_COMPILE. Thus, scan-build also needs to pass them to the
analyzer - while the link flags aren't relevant, the include flags are.

This is because the analyzer executable that gets run by scan-build is
*not* clang-wrapper, but the actual clang executable, so it doesn't
implicitly add such arguments. The build is two-stage - it runs the real
clang wrapper once, and then the analyzer once.

Signed-off-by: Austin Seipp <aseipp@pobox.com>

+39 -2
+33
pkgs/development/tools/analysis/clang-analyzer/0001-Fix-scan-build-to-use-NIX_CFLAGS_COMPILE.patch
··· 1 + From 6ab08bc1c889e4fb9a39432b1a654eaa19ee65eb Mon Sep 17 00:00:00 2001 2 + From: Austin Seipp <aseipp@pobox.com> 3 + Date: Fri, 2 May 2014 12:28:23 -0500 4 + Subject: [PATCH] Fix scan-build to use NIX_CFLAGS_COMPILE 5 + 6 + Signed-off-by: Austin Seipp <aseipp@pobox.com> 7 + --- 8 + tools/scan-build/ccc-analyzer | 9 +++++++++ 9 + 1 file changed, 9 insertions(+) 10 + 11 + diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer 12 + index b463ec0..9d39dd0 100755 13 + --- a/tools/scan-build/ccc-analyzer 14 + +++ b/tools/scan-build/ccc-analyzer 15 + @@ -207,6 +207,15 @@ sub Analyze { 16 + push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph"; 17 + } 18 + 19 + + 20 + + # Add Nix flags to analysis 21 + + if (defined $ENV{'NIX_CFLAGS_COMPILE'}) { 22 + + my @nixArgs = split(/\s+/, $ENV{'NIX_CFLAGS_COMPILE'}); 23 + + foreach my $nixArg (@nixArgs) { 24 + + push @Args, $nixArg; 25 + + } 26 + + } 27 + + 28 + my $AnalysisArgs = GetCCArgs("--analyze", \@Args); 29 + @CmdArgs = @$AnalysisArgs; 30 + } 31 + -- 32 + 1.8.3.2 33 +
+6 -2
pkgs/development/tools/analysis/clang-analyzer/default.nix
··· 9 9 sha256 = "06rb4j1ifbznl3gfhl98s7ilj0ns01p7y7zap4p7ynmqnc6pia92"; 10 10 }; 11 11 12 + patches = [ ./0001-Fix-scan-build-to-use-NIX_CFLAGS_COMPILE.patch ]; 12 13 buildInputs = [ clang llvmPackages.clang perl makeWrapper ]; 13 14 buildPhase = "true"; 14 15 ··· 18 19 cp -R tools/scan-build $out/libexec 19 20 20 21 makeWrapper $out/libexec/scan-view/scan-view $out/bin/scan-view 21 - makeWrapper $out/libexec/scan-build/scan-build $out/bin/scan-build --add-flags "--use-cc=${clang}/bin/clang" --add-flags "--use-c++=${clang}/bin/clang++" --add-flags "--use-analyzer=${llvmPackages.clang}/bin/clang" 22 + makeWrapper $out/libexec/scan-build/scan-build $out/bin/scan-build \ 23 + --add-flags "--use-cc=${clang}/bin/clang" \ 24 + --add-flags "--use-c++=${clang}/bin/clang++" \ 25 + --add-flags "--use-analyzer='${llvmPackages.clang}/bin/clang'" 22 26 ''; 23 27 24 28 meta = { ··· 28 32 platforms = stdenv.lib.platforms.unix; 29 33 maintainers = [ stdenv.lib.maintainers.thoughtpolice ]; 30 34 }; 31 - } 35 + }