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>
This commit is contained in:
parent
27a0d56514
commit
59528d9f0e
@ -0,0 +1,33 @@
|
|||||||
|
From 6ab08bc1c889e4fb9a39432b1a654eaa19ee65eb Mon Sep 17 00:00:00 2001
|
||||||
|
From: Austin Seipp <aseipp@pobox.com>
|
||||||
|
Date: Fri, 2 May 2014 12:28:23 -0500
|
||||||
|
Subject: [PATCH] Fix scan-build to use NIX_CFLAGS_COMPILE
|
||||||
|
|
||||||
|
Signed-off-by: Austin Seipp <aseipp@pobox.com>
|
||||||
|
---
|
||||||
|
tools/scan-build/ccc-analyzer | 9 +++++++++
|
||||||
|
1 file changed, 9 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer
|
||||||
|
index b463ec0..9d39dd0 100755
|
||||||
|
--- a/tools/scan-build/ccc-analyzer
|
||||||
|
+++ b/tools/scan-build/ccc-analyzer
|
||||||
|
@@ -207,6 +207,15 @@ sub Analyze {
|
||||||
|
push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph";
|
||||||
|
}
|
||||||
|
|
||||||
|
+
|
||||||
|
+ # Add Nix flags to analysis
|
||||||
|
+ if (defined $ENV{'NIX_CFLAGS_COMPILE'}) {
|
||||||
|
+ my @nixArgs = split(/\s+/, $ENV{'NIX_CFLAGS_COMPILE'});
|
||||||
|
+ foreach my $nixArg (@nixArgs) {
|
||||||
|
+ push @Args, $nixArg;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
my $AnalysisArgs = GetCCArgs("--analyze", \@Args);
|
||||||
|
@CmdArgs = @$AnalysisArgs;
|
||||||
|
}
|
||||||
|
--
|
||||||
|
1.8.3.2
|
||||||
|
|
@ -9,6 +9,7 @@ stdenv.mkDerivation rec {
|
|||||||
sha256 = "06rb4j1ifbznl3gfhl98s7ilj0ns01p7y7zap4p7ynmqnc6pia92";
|
sha256 = "06rb4j1ifbznl3gfhl98s7ilj0ns01p7y7zap4p7ynmqnc6pia92";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
patches = [ ./0001-Fix-scan-build-to-use-NIX_CFLAGS_COMPILE.patch ];
|
||||||
buildInputs = [ clang llvmPackages.clang perl makeWrapper ];
|
buildInputs = [ clang llvmPackages.clang perl makeWrapper ];
|
||||||
buildPhase = "true";
|
buildPhase = "true";
|
||||||
|
|
||||||
@ -18,7 +19,10 @@ stdenv.mkDerivation rec {
|
|||||||
cp -R tools/scan-build $out/libexec
|
cp -R tools/scan-build $out/libexec
|
||||||
|
|
||||||
makeWrapper $out/libexec/scan-view/scan-view $out/bin/scan-view
|
makeWrapper $out/libexec/scan-view/scan-view $out/bin/scan-view
|
||||||
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"
|
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'"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
|
Loading…
Reference in New Issue
Block a user