2008-11-24 15:10:06 +00:00
|
|
|
# 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'.
|
|
|
|
|
2010-09-10 12:39:57 +00:00
|
|
|
{ buildOutOfSourceTree ? false
|
|
|
|
, preConfigure ? null
|
|
|
|
, doCoverageAnalysis ? false
|
2008-12-04 15:32:30 +00:00
|
|
|
, lcovFilter ? []
|
2010-05-12 12:22:44 +00:00
|
|
|
, lcovExtraTraceFiles ? []
|
2008-12-04 15:32:30 +00:00
|
|
|
, src, stdenv
|
2009-03-02 13:45:48 +00:00
|
|
|
, name ? if doCoverageAnalysis then "nix-coverage" else "nix-build"
|
2012-02-28 17:10:50 +00:00
|
|
|
, failureHook ? null
|
2012-03-19 02:45:52 +00:00
|
|
|
, postPhases ? []
|
2008-12-04 15:32:30 +00:00
|
|
|
, ... } @ args:
|
2008-11-24 15:10:06 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation (
|
|
|
|
|
|
|
|
{
|
|
|
|
# Also run a `make check'.
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
# When doing coverage analysis, we don't care about the result.
|
|
|
|
dontInstall = doCoverageAnalysis;
|
|
|
|
|
|
|
|
showBuildStats = true;
|
|
|
|
|
2009-06-17 07:02:59 +00:00
|
|
|
finalPhase =
|
|
|
|
''
|
|
|
|
# Propagate the release name of the source tarball. This is
|
|
|
|
# to get nice package names in channels.
|
|
|
|
if test -e $origSrc/nix-support/hydra-release-name; then
|
|
|
|
cp $origSrc/nix-support/hydra-release-name $out/nix-support/hydra-release-name
|
|
|
|
fi
|
|
|
|
'';
|
2010-12-22 14:57:18 +00:00
|
|
|
|
2012-02-28 17:10:50 +00:00
|
|
|
failureHook = (stdenv.lib.optionalString (failureHook != null) failureHook) +
|
|
|
|
''
|
2010-12-22 14:57:18 +00:00
|
|
|
if test -n "$succeedOnFailure"; then
|
|
|
|
if test -n "$keepBuildDirectory"; then
|
|
|
|
KEEPBUILDDIR="$out/`basename $TMPDIR`"
|
|
|
|
header "Copying build directory to $KEEPBUILDDIR"
|
2012-01-18 20:16:00 +00:00
|
|
|
mkdir -p $KEEPBUILDDIR
|
2011-01-05 09:06:53 +00:00
|
|
|
cp -R $TMPDIR/* $KEEPBUILDDIR
|
2010-12-22 14:57:18 +00:00
|
|
|
stopNest
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
'';
|
2008-11-24 15:10:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// args //
|
|
|
|
|
|
|
|
{
|
2009-03-02 14:33:33 +00:00
|
|
|
name = name + (if src ? version then "-" + src.version else "");
|
2009-03-02 13:45:48 +00:00
|
|
|
|
2008-11-24 15:10:06 +00:00
|
|
|
postHook = ''
|
2012-01-18 20:16:00 +00:00
|
|
|
mkdir -p $out/nix-support
|
2008-11-24 15:10:06 +00:00
|
|
|
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.
|
2009-03-02 13:45:48 +00:00
|
|
|
origSrc=$src
|
2008-11-24 15:10:06 +00:00
|
|
|
if test -d $src/tarballs; then
|
2011-10-11 14:47:56 +00:00
|
|
|
src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz $src/tarballs/*.tar.xz | sort | head -1)
|
2008-11-24 15:10:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set GCC flags for coverage analysis, if desired.
|
|
|
|
if test -n "${toString doCoverageAnalysis}"; then
|
2009-08-31 15:02:27 +00:00
|
|
|
export NIX_CFLAGS_COMPILE="-O0 --coverage $NIX_CFLAGS_COMPILE"
|
2008-11-24 15:10:06 +00:00
|
|
|
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
|
2010-05-12 12:22:44 +00:00
|
|
|
|
2008-11-24 15:10:06 +00:00
|
|
|
mkdir $out/coverage
|
2010-05-12 12:22:44 +00:00
|
|
|
${args.lcov}/bin/genhtml app.info $lcovExtraTraceFiles -o $out/coverage > log
|
2008-11-24 15:10:06 +00:00
|
|
|
|
|
|
|
# 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 "";
|
|
|
|
|
|
|
|
|
2008-12-04 15:32:30 +00:00
|
|
|
lcovFilter = ["/nix/store/*"] ++ lcovFilter;
|
2009-03-02 13:45:48 +00:00
|
|
|
|
2010-05-12 12:22:44 +00:00
|
|
|
inherit lcovExtraTraceFiles;
|
2009-03-02 13:45:48 +00:00
|
|
|
|
2012-03-19 02:45:52 +00:00
|
|
|
postPhases = postPhases ++
|
|
|
|
(stdenv.lib.optional doCoverageAnalysis "coverageReportPhase") ++ ["finalPhase"];
|
|
|
|
|
2008-11-26 14:34:29 +00:00
|
|
|
meta = (if args ? meta then args.meta else {}) // {
|
2008-11-25 15:54:05 +00:00
|
|
|
description = if doCoverageAnalysis then "Coverage analysis" else "Native Nix build on ${stdenv.system}";
|
2008-11-24 15:10:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2010-09-10 12:39:57 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
(if buildOutOfSourceTree
|
|
|
|
then {
|
|
|
|
preConfigure =
|
|
|
|
# Build out of source tree and make the source tree read-only. This
|
|
|
|
# helps catch violations of the GNU Coding Standards (info
|
|
|
|
# "(standards) Configuration"), like `make distcheck' does.
|
|
|
|
'' mkdir "../build"
|
|
|
|
cd "../build"
|
|
|
|
configureScript="../$sourceRoot/configure"
|
|
|
|
chmod -R a-w "../$sourceRoot"
|
|
|
|
|
|
|
|
echo "building out of source tree, from \`$PWD'..."
|
|
|
|
|
|
|
|
${if preConfigure != null then preConfigure else ""}
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
else {})
|
2008-11-24 15:10:06 +00:00
|
|
|
)
|