lol
1# This function builds and tests an Autoconf-style source tarball.
2# The result can be installed normally in an environment (e.g., after
3# making it available through a channel). If `doCoverageAnalysis' is
4# true, it does an ordinary build from a source tarball, except that
5# it turns on GCC's coverage analysis feature. It then runs `make
6# check' and produces a coverage analysis report using `lcov'.
7
8{ buildOutOfSourceTree ? false
9, preConfigure ? null
10, doCoverageAnalysis ? false
11, doClangAnalysis ? false
12, doCoverityAnalysis ? false
13, lcovFilter ? []
14, lcovExtraTraceFiles ? []
15, src, stdenv
16, name ? if doCoverageAnalysis then "nix-coverage" else "nix-build"
17, failureHook ? null
18, prePhases ? []
19, postPhases ? []
20, buildInputs ? []
21, preHook ? ""
22, postHook ? ""
23, ... } @ args:
24
25let
26 doingAnalysis = doCoverageAnalysis || doClangAnalysis || doCoverityAnalysis;
27in
28stdenv.mkDerivation (
29
30 {
31 # Also run a `make check'.
32 doCheck = true;
33
34 # When doing coverage analysis, we don't care about the result.
35 dontInstall = doingAnalysis;
36 useTempPrefix = doingAnalysis;
37
38 showBuildStats = true;
39
40 finalPhase =
41 ''
42 # Propagate the release name of the source tarball. This is
43 # to get nice package names in channels.
44 if test -e $origSrc/nix-support/hydra-release-name; then
45 cp $origSrc/nix-support/hydra-release-name $out/nix-support/hydra-release-name
46 fi
47
48 # Package up Coverity analysis results
49 if [ ! -z "${toString doCoverityAnalysis}" ]; then
50 if [ -d "_coverity_$name/cov-int" ]; then
51 mkdir -p $out/tarballs
52 NAME=`cat $out/nix-support/hydra-release-name`
53 cd _coverity_$name
54 tar caf $out/tarballs/$NAME-coverity-int.xz cov-int
55 echo "file cov-build $out/tarballs/$NAME-coverity-int.xz" >> $out/nix-support/hydra-build-products
56 fi
57 fi
58
59 # Package up Clang analysis results
60 if [ ! -z "${toString doClangAnalysis}" ]; then
61 if [ ! -z "`ls _clang_analyze_$name`" ]; then
62 cd _clang_analyze_$name && mv * $out/analysis
63 else
64 mkdir -p $out/analysis
65 echo "No bugs found." >> $out/analysis/index.html
66 fi
67
68 echo "report analysis $out/analysis" >> $out/nix-support/hydra-build-products
69 fi
70 '';
71
72 failureHook = (stdenv.lib.optionalString (failureHook != null) failureHook) +
73 ''
74 if test -n "$succeedOnFailure"; then
75 if test -n "$keepBuildDirectory"; then
76 KEEPBUILDDIR="$out/`basename $TMPDIR`"
77 header "Copying build directory to $KEEPBUILDDIR"
78 mkdir -p $KEEPBUILDDIR
79 cp -R "$TMPDIR/"* $KEEPBUILDDIR
80 stopNest
81 fi
82 fi
83 '';
84 }
85
86 // args //
87
88 {
89 name = name + (if src ? version then "-" + src.version else "");
90
91 postHook = ''
92 . ${./functions.sh}
93 origSrc=$src
94 src=$(findTarball $src)
95 ${postHook}
96 '';
97
98 preHook = ''
99 # Perform Coverity Analysis
100 if [ ! -z "${toString doCoverityAnalysis}" ]; then
101 shopt -s expand_aliases
102 mkdir _coverity_$name
103 alias make="cov-build --dir _coverity_$name/cov-int make"
104 fi
105
106 # Perform Clang Analysis
107 if [ ! -z "${toString doClangAnalysis}" ]; then
108 shopt -s expand_aliases
109 alias make="scan-build -o _clang_analyze_$name --html-title='Scan results for $name' make"
110 fi
111
112 ${preHook}
113 '';
114
115 # Clean up after analysis
116 postBuild = ''
117 if [ ! -z "${toString (doCoverityAnalysis || doClangAnalysis)}" ]; then
118 unalias make
119 fi
120 '';
121
122 initPhase = ''
123 mkdir -p $out/nix-support
124 echo "$system" > $out/nix-support/system
125
126 if [ -z "${toString doingAnalysis}" ]; then
127 for i in $outputs; do
128 if [ "$i" = out ]; then j=none; else j="$i"; fi
129 mkdir -p ''${!i}/nix-support
130 echo "nix-build $j ''${!i}" >> ''${!i}/nix-support/hydra-build-products
131 done
132 fi
133 '';
134
135 prePhases = ["initPhase"] ++ prePhases;
136
137 buildInputs =
138 buildInputs ++
139 (stdenv.lib.optional doCoverageAnalysis args.makeGCOVReport) ++
140 (stdenv.lib.optional doClangAnalysis args.clang-analyzer) ++
141 (stdenv.lib.optional doCoverityAnalysis args.cov-build) ++
142 (stdenv.lib.optional doCoverityAnalysis args.xz);
143
144 lcovFilter = ["/nix/store/*"] ++ lcovFilter;
145
146 inherit lcovExtraTraceFiles;
147
148 postPhases = postPhases ++ ["finalPhase"];
149
150 meta = (if args ? meta then args.meta else {}) // {
151 description = if doCoverageAnalysis then "Coverage analysis" else "Nix package for ${stdenv.system}";
152 };
153
154 }
155
156 //
157
158 (if buildOutOfSourceTree
159 then {
160 preConfigure =
161 # Build out of source tree and make the source tree read-only. This
162 # helps catch violations of the GNU Coding Standards (info
163 # "(standards) Configuration"), like `make distcheck' does.
164 '' mkdir "../build"
165 cd "../build"
166 configureScript="../$sourceRoot/configure"
167 chmod -R a-w "../$sourceRoot"
168
169 echo "building out of source tree, from \`$PWD'..."
170
171 ${if preConfigure != null then preConfigure else ""}
172 '';
173 }
174 else {})
175)