From bea2b3c5177a9fae5df5598574bd25bca8f6cb09 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 5 Feb 2014 12:49:53 +0100 Subject: [PATCH] addCoverageInstrumentation: Set NIX_CFLAGS_COMPILE as an attribute This allows it to show up in nix-shell. --- pkgs/stdenv/adapters.nix | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index da4e0691e43..3bac5341154 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -231,8 +231,17 @@ rec { programs like lcov to produce pretty-printed reports. */ addCoverageInstrumentation = stdenv: - addAttrsToDerivation - { + # Object files instrumented with coverage analysis write runtime + # coverage data to /.gcda, where is the + # location where gcc originally created the object file. That + # would be /tmp/nix-build-, which will be long gone by + # the time we run the program. Furthermore, the .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 have to use the `keepBuildTree' adapter as well. + let stdenv' = cleanupBuildTree (keepBuildTree stdenv); in + { mkDerivation = args: stdenv'.mkDerivation (args // { + NIX_CFLAGS_COMPILE = toString (args.NIX_CFLAGS_COMPILE or "") + " -O0 --coverage"; postUnpack = '' # This is an uberhack to prevent libtool from removing gcno @@ -242,21 +251,9 @@ rec { for i in $(find -name ltmain.sh); do substituteInPlace $i --replace '*.$objext)' '*.$objext | *.gcno)' done - - export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -O0 --coverage" - ''; - } - - # Object files instrumented with coverage analysis write - # runtime coverage data to /.gcda, where - # is the location where gcc originally created the object - # file. That would be /tmp/nix-build-, which will - # be long gone by the time we run the program. Furthermore, - # the .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 have to use the - # `keepBuildTree' adapter as well. - (cleanupBuildTree (keepBuildTree stdenv)); + '' + args.postUnpack or ""; + }); + }; /* Replace the meta.maintainers field of a derivation. This is useful