about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2009-09-01 21:56:46 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2009-09-01 21:56:46 +0000
commit58e61617682239f5d20320066b1a79de127bcc61 (patch)
tree9d823bb53fe62c826937eee30731bec01dda3a8a
parent043fe38f80db59dbc0d6283575892ea06a4b55c5 (diff)
downloadnixlib-58e61617682239f5d20320066b1a79de127bcc61.tar
nixlib-58e61617682239f5d20320066b1a79de127bcc61.tar.gz
nixlib-58e61617682239f5d20320066b1a79de127bcc61.tar.bz2
nixlib-58e61617682239f5d20320066b1a79de127bcc61.tar.lz
nixlib-58e61617682239f5d20320066b1a79de127bcc61.tar.xz
nixlib-58e61617682239f5d20320066b1a79de127bcc61.tar.zst
nixlib-58e61617682239f5d20320066b1a79de127bcc61.zip
* addCoverageInstrumentation: factor out the code that keeps the build
  tree under $out into a separate stdenv adapter named keepBuildTree.
* makeModulesClosure: support building an initrd for a kernel that has
  been compiled with coverage instrumentation.

svn path=/nixpkgs/trunk/; revision=16916
-rw-r--r--pkgs/build-support/kernel/modules-closure.nix4
-rw-r--r--pkgs/build-support/kernel/modules-closure.sh5
-rw-r--r--pkgs/stdenv/adapters.nix55
-rw-r--r--pkgs/top-level/all-packages.nix13
4 files changed, 47 insertions, 30 deletions
diff --git a/pkgs/build-support/kernel/modules-closure.nix b/pkgs/build-support/kernel/modules-closure.nix
index 7eac04819790..cc197edbef19 100644
--- a/pkgs/build-support/kernel/modules-closure.nix
+++ b/pkgs/build-support/kernel/modules-closure.nix
@@ -3,11 +3,13 @@
 # the modules identified by `rootModules', plus their dependencies.
 # Also generate an appropriate modules.dep.
 
-{stdenv, kernel, rootModules, module_init_tools, allowMissing ? false}:
+{ stdenv, kernel, nukeReferences, rootModules
+, module_init_tools, allowMissing ? false }:
 
 stdenv.mkDerivation {
   name = kernel.name + "-shrunk";
   builder = ./modules-closure.sh;
+  buildInputs = [nukeReferences];
   inherit kernel rootModules module_init_tools allowMissing;
   allowedReferences = ["out"];
 }
diff --git a/pkgs/build-support/kernel/modules-closure.sh b/pkgs/build-support/kernel/modules-closure.sh
index 035893ebd69f..e75ef927baae 100644
--- a/pkgs/build-support/kernel/modules-closure.sh
+++ b/pkgs/build-support/kernel/modules-closure.sh
@@ -29,6 +29,11 @@ for module in $closure; do
     mkdir -p $(dirname $target)
     echo $module
     cp $module $target
+    # If the kernel is compiled with coverage instrumentation, it
+    # contains the paths of the *.gcda coverage data output files
+    # (which it doesn't actually use...).  Get rid of them to prevent
+    # the whole kernel from being included in the initrd.
+    nuke-refs $target
     echo $target >> $out/insmod-list
 done
 
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix
index 621aef466aa3..92970b1c51f1 100644
--- a/pkgs/stdenv/adapters.nix
+++ b/pkgs/stdenv/adapters.nix
@@ -121,33 +121,33 @@ rec {
     { mkDerivation = args: stdenv.mkDerivation (args // extraAttrs); };
 
 
+  /* Return a modified stdenv that perfoms the build under $out/.build
+     instead of in $TMPDIR.  Thus, the sources are kept available.
+     This is useful for things like debugging or generation of
+     dynamic analysis reports. */ 
+  keepBuildTree = stdenv:
+    addAttrsToDerivation
+      { prePhases = "moveBuildDir";
+
+        moveBuildDir =
+          ''
+            ensureDir $out/.build
+            cd $out/.build
+          '';
+      } stdenv;
+
+
   /* 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.
+     $out/.build, 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.
@@ -165,10 +165,21 @@ rec {
         # suite.
         cleanupBuildDir =
           ''
-             find $out/.coverage/ -type f -a ! \
-               \( -name "*.c" -o -name "*.gcno" -o -name "*.h" \) \
-               | xargs rm -f --
+            find $out/.build/ -type f -a ! \
+              \( -name "*.c" -o -name "*.gcno" -o -name "*.h" \) \
+              | xargs rm -f --
           '';
       }
-      stdenv;
+      
+      # 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 have to use the
+      # `keepBuildTree' adapter as well.
+      (keepBuildTree stdenv);
+      
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index fa973455f9aa..87cc88d826e9 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -228,7 +228,7 @@ let
   inherit (import ../stdenv/adapters.nix {inherit (pkgs) dietlibc fetchurl runCommand;})
     overrideGCC overrideInStdenv overrideSetup
     useDietLibC useKlibc makeStaticBinaries addAttrsToDerivation
-    addCoverageInstrumentation;
+    keepBuildTree addCoverageInstrumentation;
 
 
   ### BUILD SUPPORT
@@ -324,7 +324,8 @@ let
 
   makeModulesClosure = {kernel, rootModules, allowMissing ? false}:
     import ../build-support/kernel/modules-closure.nix {
-      inherit stdenv module_init_tools kernel rootModules allowMissing;
+      inherit stdenv module_init_tools kernel nukeReferences
+        rootModules allowMissing;
     };
 
   pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;
@@ -5169,8 +5170,7 @@ let
       [(getConfig ["kernel" "addConfig"] "")];
   };
 
-  kernel_2_6_28 = (
-    import ../os-specific/linux/kernel/linux-2.6.28.nix {
+  kernel_2_6_28 = makeOverridable (import ../os-specific/linux/kernel/linux-2.6.28.nix) {
     inherit fetchurl stdenv perl mktemp module_init_tools;
     kernelPatches = [
       { name = "fbcondecor-0.9.5-2.6.28";
@@ -5196,7 +5196,7 @@ let
     extraConfig =
       lib.optional (getConfig ["kernel" "no_irqbalance"] false) "# CONFIG_IRQBALANCE is not set" ++
       [(getConfig ["kernel" "addConfig"] "")];
-  });
+  };
 
   kernel_2_6_29 = (
     makeOverridable (import ../os-specific/linux/kernel/linux-2.6.29.nix) {
@@ -5279,8 +5279,7 @@ let
      for a specific kernel.  This function can then be called for
      whatever kernel you're using. */
 
-  kernelPackagesFor = kernel: 
-  rec {
+  kernelPackagesFor = kernel: rec {
 
     inherit kernel;