summary refs log tree commit diff
path: root/pkgs/build-support/release/nix-build.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2008-11-24 15:10:06 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2008-11-24 15:10:06 +0000
commit01acea6bbc4193ff12495e0d9a0f169fa26c0dc4 (patch)
tree469cbfc922fe045b3bd89ab31498af7579fb4234 /pkgs/build-support/release/nix-build.nix
parent9cb29889d210c5d9fc9ec3fabf5f9f376a16c953 (diff)
downloadnixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.tar
nixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.tar.gz
nixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.tar.bz2
nixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.tar.lz
nixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.tar.xz
nixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.tar.zst
nixlib-01acea6bbc4193ff12495e0d9a0f169fa26c0dc4.zip
* Start moving the Nix expressions that support the build farm
  (e.g. making source tarballs, doing coverage analysis) to the
  Nixpkgs tree.  This makes it easier to run build farm jobs locally
  since you don't need to check out the "release" tree separately.
  Also it means one less input to declare for build farm jobs.

* Removed succeedOnFailure and separate logging of phases.  Hydra
  doesn't need that.

svn path=/nixpkgs/trunk/; revision=13388
Diffstat (limited to 'pkgs/build-support/release/nix-build.nix')
-rw-r--r--pkgs/build-support/release/nix-build.nix91
1 files changed, 91 insertions, 0 deletions
diff --git a/pkgs/build-support/release/nix-build.nix b/pkgs/build-support/release/nix-build.nix
new file mode 100644
index 000000000000..aa026ac3a576
--- /dev/null
+++ b/pkgs/build-support/release/nix-build.nix
@@ -0,0 +1,91 @@
+# This function builds and tests an Autoconf-style source tarball.
+# The result can be installed normally in an environment (e.g., after
+# making it available through a channel).  If `doCoverageAnalysis' is
+# true, it does an ordinary build from a source tarball, except that
+# it turns on GCC's coverage analysis feature.  It then runs `make
+# check' and produces a coverage analysis report using `lcov'.
+
+args: with args;
+
+stdenv.mkDerivation (
+
+  {
+    name = "nix-build";
+
+    # Also run a `make check'.
+    doCheck = true;
+
+    # When doing coverage analysis, we don't care about the result.
+    dontInstall = doCoverageAnalysis;
+
+    showBuildStats = true;
+
+    lcovFilter = ["/nix/store/*"];
+
+    # Hack - swap checkPhase and installPhase (otherwise Stratego barfs).
+    phases = "unpackPhase patchPhase configurePhase buildPhase installPhase checkPhase fixupPhase distPhase ${if doCoverageAnalysis then "coverageReportPhase" else ""}";
+  }
+
+  // args // 
+
+  {
+    src = src.path;
+
+    postHook = ''
+      ensureDir $out/nix-support
+      echo "$system" > $out/nix-support/system
+
+      if test -z "${toString doCoverageAnalysis}"; then
+          echo "nix-build none $out" >> $out/nix-support/hydra-build-products
+      fi
+
+      # If `src' is the result of a call to `makeSourceTarball', then it
+      # has a subdirectory containing the actual tarball(s).  If there are
+      # multiple tarballs, just pick the first one.
+      echo $src
+      if test -d $src/tarballs; then
+          src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz | sort | head -1)
+      fi
+
+      # Hack to compress log files.  Prevents (by pointer hiding!)
+      # unnecessary dependencies.
+      startLogWrite() {
+          # Use process substitution to send the FIFO output to both
+          # stdout and bzip2.
+          bash -c "tee >(bzip2 > \"$1\".bz2) < \"$2\"" &
+          logWriterPid=$!
+      }
+
+      # Set GCC flags for coverage analysis, if desired.
+      if test -n "${toString doCoverageAnalysis}"; then
+          export NIX_CFLAGS_COMPILE="-O0 -fprofile-arcs -ftest-coverage $NIX_CFLAGS_COMPILE"
+          export CFLAGS="-O0"
+          export CXXFLAGS="-O0"
+      fi
+
+    ''; # */
+
+
+    # In the report phase, create a coverage analysis report.
+    coverageReportPhase = if doCoverageAnalysis then ''
+      ${args.lcov}/bin/lcov --directory . --capture --output-file app.info
+      set -o noglob
+      ${args.lcov}/bin/lcov --remove app.info $lcovFilter > app2.info
+      set +o noglob
+      mv app2.info app.info
+      mkdir $out/coverage
+      ${args.lcov}/bin/genhtml app.info -o $out/coverage > log
+
+      # Grab the overall coverage percentage for use in release overviews.
+      grep "Overall coverage rate" log | sed 's/^.*(\(.*\)%).*$/\1/' > $out/nix-support/coverage-rate
+
+      echo "report coverage $out/coverage" >> $out/nix-support/hydra-build-products
+    '' else "";
+
+
+    meta = {
+      description = if doCoverageAnalysis then "Coverage analysis" else "Native Nix build";
+    };
+
+  }
+)