diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-08-28 16:45:56 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-08-28 16:45:56 +0000 |
commit | 0fd5ed507e0733346c836760c344d3aa4597b121 (patch) | |
tree | ae9b1217109b302ffc5df1221d9d28b3d654e569 | |
parent | df5cd8776a40f995900e9646982d663ea00e4f02 (diff) | |
download | nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.tar nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.tar.gz nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.tar.bz2 nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.tar.lz nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.tar.xz nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.tar.zst nixpkgs-0fd5ed507e0733346c836760c344d3aa4597b121.zip |
* A stdenv adapter to build a package with coverage instrumentation.
svn path=/nixpkgs/trunk/; revision=16890
-rw-r--r-- | pkgs/stdenv/adapters.nix | 50 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 13 |
2 files changed, 57 insertions, 6 deletions
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 2cdf95476a5..621aef466aa 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -121,4 +121,54 @@ rec { { mkDerivation = args: stdenv.mkDerivation (args // extraAttrs); }; + /* Return a modified stdenv that builds packages with GCC's coverage + instrumentation. The coverage note files (*.gcno) are stored in + $out/.coverage, along with the source code of the package, to + enable programs like lcov to produce pretty-printed reports. + */ + addCoverageInstrumentation = stdenv: + addAttrsToDerivation + { NIX_CFLAGS_COMPILE = "-O0 --coverage"; + + prePhases = "moveBuildDir"; + postPhases = "cleanupBuildDir"; + + # Object files instrumented with coverage analysis write + # runtime coverage data to <path>/<object>.gcda, where <path> + # is the location where gcc originally created the object + # file. That would be /tmp/nix-build-<something>, which will + # be long gone by the time we run the program. Furthermore, + # the <object>.gcno files created at compile time are also + # written there. And to make nice coverage reports with lcov, + # we need the source code. So we move the whole build tree to + # $out/.coverage. + moveBuildDir = + '' + ensureDir $out/.coverage + cd $out/.coverage + ''; + + # This is an uberhack to prevent libtool from removing gcno + # files. This has been fixed in libtool, but there are + # packages out there with old ltmain.sh scripts. + # See http://www.mail-archive.com/libtool@gnu.org/msg10725.html + postUnpack = + '' + for i in $(find -name ltmain.sh); do + substituteInPlace $i --replace '*.$objext)' '*.$objext | *.gcno)' + done + ''; + + # Get rid of everything that isn't a gcno file or a C source + # file. This also includes the gcda files; we're not + # interested in coverage resulting from the package's own test + # suite. + cleanupBuildDir = + '' + find $out/.coverage/ -type f -a ! \ + \( -name "*.c" -o -name "*.gcno" -o -name "*.h" \) \ + | xargs rm -f -- + ''; + } + stdenv; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ed3c192b786..6d2297bcf42 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -226,7 +226,8 @@ let inherit (import ../stdenv/adapters.nix {inherit (pkgs) dietlibc fetchurl runCommand;}) overrideGCC overrideInStdenv overrideSetup - useDietLibC useKlibc makeStaticBinaries; + useDietLibC useKlibc makeStaticBinaries addAttrsToDerivation + addCoverageInstrumentation; ### BUILD SUPPORT @@ -2771,11 +2772,11 @@ let inherit (xlibs) libX11; }; - apr = import ../development/libraries/apr { + apr = makeOverridable (import ../development/libraries/apr) { inherit fetchurl stdenv; }; - aprutil = import ../development/libraries/apr-util { + aprutil = makeOverridable (import ../development/libraries/apr-util) { inherit fetchurl stdenv apr expat db4; bdbSupport = true; }; @@ -2802,7 +2803,7 @@ let inherit fetchurl stdenv; }); - aterm25 = import ../development/libraries/aterm/2.5.nix { + aterm25 = makeOverridable (import ../development/libraries/aterm/2.5.nix) { inherit fetchurl stdenv; }; @@ -4500,7 +4501,7 @@ let ### SERVERS - apacheHttpd = import ../servers/http/apache-httpd { + apacheHttpd = makeOverridable (import ../servers/http/apache-httpd) { inherit fetchurl stdenv perl openssl zlib apr aprutil pcre; sslSupport = true; }; @@ -6613,7 +6614,7 @@ let inherit fetchurl stdenv Xaw3d ghostscriptX; }; - hello = import ../applications/misc/hello/ex-2 { + hello = makeOverridable (import ../applications/misc/hello/ex-2) { inherit fetchurl stdenv; }; |