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 /pkgs/stdenv/adapters.nix | |
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
Diffstat (limited to 'pkgs/stdenv/adapters.nix')
-rw-r--r-- | pkgs/stdenv/adapters.nix | 50 |
1 files changed, 50 insertions, 0 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; } |