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 13:39:57 +01:00
|
|
|
{ buildOutOfSourceTree ? false
|
|
|
|
, preConfigure ? null
|
|
|
|
, doCoverageAnalysis ? false
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
, doClangAnalysis ? false
|
|
|
|
, doCoverityAnalysis ? false
|
2008-12-04 15:32:30 +00:00
|
|
|
, lcovFilter ? []
|
2010-05-12 13:22:44 +01:00
|
|
|
, lcovExtraTraceFiles ? []
|
2021-01-24 00:40:18 +00:00
|
|
|
, src, lib, 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 03:45:36 +00:00
|
|
|
, prePhases ? []
|
2012-03-19 02:45:52 +00:00
|
|
|
, postPhases ? []
|
2014-02-05 13:11:21 +00:00
|
|
|
, buildInputs ? []
|
2014-11-06 10:12:29 +00:00
|
|
|
, preHook ? ""
|
|
|
|
, postHook ? ""
|
2008-12-04 15:32:30 +00:00
|
|
|
, ... } @ args:
|
2008-11-24 15:10:06 +00:00
|
|
|
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
let
|
|
|
|
doingAnalysis = doCoverageAnalysis || doClangAnalysis || doCoverityAnalysis;
|
|
|
|
in
|
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.
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
dontInstall = doingAnalysis;
|
|
|
|
useTempPrefix = doingAnalysis;
|
2008-11-24 15:10:06 +00:00
|
|
|
|
|
|
|
showBuildStats = true;
|
|
|
|
|
2009-06-17 08:02:59 +01: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
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
|
|
|
|
# Package up Coverity analysis results
|
|
|
|
if [ ! -z "${toString doCoverityAnalysis}" ]; then
|
|
|
|
if [ -d "_coverity_$name/cov-int" ]; then
|
|
|
|
mkdir -p $out/tarballs
|
|
|
|
NAME=`cat $out/nix-support/hydra-release-name`
|
|
|
|
cd _coverity_$name
|
|
|
|
tar caf $out/tarballs/$NAME-coverity-int.xz cov-int
|
|
|
|
echo "file cov-build $out/tarballs/$NAME-coverity-int.xz" >> $out/nix-support/hydra-build-products
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Package up Clang analysis results
|
|
|
|
if [ ! -z "${toString doClangAnalysis}" ]; then
|
|
|
|
if [ ! -z "`ls _clang_analyze_$name`" ]; then
|
|
|
|
cd _clang_analyze_$name && mv * $out/analysis
|
|
|
|
else
|
|
|
|
mkdir -p $out/analysis
|
|
|
|
echo "No bugs found." >> $out/analysis/index.html
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "report analysis $out/analysis" >> $out/nix-support/hydra-build-products
|
|
|
|
fi
|
2009-06-17 08:02:59 +01:00
|
|
|
'';
|
2010-12-22 14:57:18 +00:00
|
|
|
|
2021-01-24 00:40:18 +00:00
|
|
|
failureHook = (lib.optionalString (failureHook != null) failureHook) +
|
2012-02-28 17:10:50 +00:00
|
|
|
''
|
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
|
2013-04-18 11:18:39 +01:00
|
|
|
cp -R "$TMPDIR/"* $KEEPBUILDDIR
|
2013-02-13 12:53:41 +00:00
|
|
|
stopNest
|
2010-12-22 14:57:18 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
'';
|
2008-11-24 15:10:06 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 12:53:41 +00:00
|
|
|
// args //
|
2008-11-24 15:10:06 +00:00
|
|
|
|
|
|
|
{
|
2009-03-02 14:33:33 +00:00
|
|
|
name = name + (if src ? version then "-" + src.version else "");
|
2013-02-13 12:53:41 +00:00
|
|
|
|
2008-11-24 15:10:06 +00:00
|
|
|
postHook = ''
|
2012-07-13 19:58:39 +01:00
|
|
|
. ${./functions.sh}
|
2009-03-02 13:45:48 +00:00
|
|
|
origSrc=$src
|
2014-11-05 17:21:44 +00:00
|
|
|
src=$(findTarball $src)
|
2014-11-06 10:12:29 +00:00
|
|
|
${postHook}
|
2013-04-18 11:18:39 +01:00
|
|
|
'';
|
2008-11-24 15:10:06 +00:00
|
|
|
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
preHook = ''
|
|
|
|
# Perform Coverity Analysis
|
|
|
|
if [ ! -z "${toString doCoverityAnalysis}" ]; then
|
|
|
|
shopt -s expand_aliases
|
|
|
|
mkdir _coverity_$name
|
|
|
|
alias make="cov-build --dir _coverity_$name/cov-int make"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Perform Clang Analysis
|
|
|
|
if [ ! -z "${toString doClangAnalysis}" ]; then
|
|
|
|
shopt -s expand_aliases
|
|
|
|
alias make="scan-build -o _clang_analyze_$name --html-title='Scan results for $name' make"
|
|
|
|
fi
|
2014-11-06 10:12:29 +00:00
|
|
|
|
|
|
|
${preHook}
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Clean up after analysis
|
|
|
|
postBuild = ''
|
|
|
|
if [ ! -z "${toString (doCoverityAnalysis || doClangAnalysis)}" ]; then
|
|
|
|
unalias make
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2012-03-19 03:45:36 +00:00
|
|
|
initPhase = ''
|
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "$system" > $out/nix-support/system
|
|
|
|
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
if [ -z "${toString doingAnalysis}" ]; then
|
2013-02-13 12:53:41 +00:00
|
|
|
for i in $outputs; do
|
|
|
|
if [ "$i" = out ]; then j=none; else j="$i"; fi
|
2013-02-13 15:30:15 +00:00
|
|
|
mkdir -p ''${!i}/nix-support
|
|
|
|
echo "nix-build $j ''${!i}" >> ''${!i}/nix-support/hydra-build-products
|
2013-02-13 12:53:41 +00:00
|
|
|
done
|
2012-03-19 03:45:36 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
prePhases = ["initPhase"] ++ prePhases;
|
2008-11-24 15:10:06 +00:00
|
|
|
|
releaseTools: add {clang,coverity}Analysis tools
These two expressions greatly simplify using the clang-analyzer or
Coverity static analyzer on your C/C++ projects. In fact, they are
identical to nixBuild in every way out of the box, and should 'Just
Work' providing your code can be compiled with Clang already.
The trick is that when running 'make', we actually just alias it to the
appropriate scan build tool, and add a post-build hook that will bundle
up the results appropriately and unalias it.
For Clang, we put the results in $out/analysis and add an 'analysis'
report to $out/nix-support/hydra-build-products pointing to the result
HTML - this means that if the analyzer finds any bugs, the HTML results
will automatically show up Hydra for easy viewing.
For Coverity, it's slightly different. Instead we run the build tool and
after we're done, we tar up the results in a format that Coverity Scan's
service understands. We put the tarball in $out/tarballs under the name
'foo-cov-int.xz' and add an entry for the file to hydra-build-products
as well for easy viewing.
Of course for Coverity you must then upload the build. A Hydra plugin to
do this is on the way, and it will automatically pick up the
cov-int.tar.xz for uploading.
Note that coverityAnalysis requires allowUnfree = true;, as well as the
cov-build tools, which you can download from https://scan.coverity.com -
they're not linked to your account or anything, it's just an annoying
registration wall.
Note this is a first draft. In particular, scan-build fixes the C/C++
compiler to be Clang, and it's perfectly reasonable to want to use Clang
for the analyzer but have scan-build invoke GCC instead.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2014-05-02 19:26:41 +01:00
|
|
|
buildInputs =
|
|
|
|
buildInputs ++
|
2021-01-24 00:40:18 +00:00
|
|
|
(lib.optional doCoverageAnalysis args.makeGCOVReport) ++
|
|
|
|
(lib.optional doClangAnalysis args.clang-analyzer) ++
|
|
|
|
(lib.optional doCoverityAnalysis args.cov-build) ++
|
|
|
|
(lib.optional doCoverityAnalysis args.xz);
|
2008-11-24 15:10:06 +00:00
|
|
|
|
2008-12-04 15:32:30 +00:00
|
|
|
lcovFilter = ["/nix/store/*"] ++ lcovFilter;
|
2009-03-02 13:45:48 +00:00
|
|
|
|
2010-05-12 13:22:44 +01:00
|
|
|
inherit lcovExtraTraceFiles;
|
2009-03-02 13:45:48 +00:00
|
|
|
|
2014-02-05 13:11:21 +00:00
|
|
|
postPhases = postPhases ++ ["finalPhase"];
|
2012-03-19 02:45:52 +00:00
|
|
|
|
2008-11-26 14:34:29 +00:00
|
|
|
meta = (if args ? meta then args.meta else {}) // {
|
2018-08-20 20:11:29 +01:00
|
|
|
description = if doCoverageAnalysis then "Coverage analysis" else "Nix package for ${stdenv.hostPlatform.system}";
|
2008-11-24 15:10:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2010-09-10 13:39:57 +01: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
|
|
|
)
|