summary refs log tree commit diff
path: root/pkgs/build-support/release/nix-build.nix
blob: 8ebae24c67333ad512739637f5a547ab12d51a20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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'.

{ buildOutOfSourceTree ? false
, preConfigure ? null
, doCoverageAnalysis ? false
, lcovFilter ? []
, lcovExtraTraceFiles ? []
, src, stdenv
, name ? if doCoverageAnalysis then "nix-coverage" else "nix-build"
, failureHook ? null
, prePhases ? []
, postPhases ? []
, buildInputs ? []
, ... } @ args:

stdenv.mkDerivation (

  {
    # Also run a `make check'.
    doCheck = true;

    # When doing coverage analysis, we don't care about the result.
    dontInstall = doCoverageAnalysis;
    useTempPrefix = doCoverageAnalysis;

    showBuildStats = true;

    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
      '';

    failureHook = (stdenv.lib.optionalString (failureHook != null) failureHook) +
    ''
      if test -n "$succeedOnFailure"; then
          if test -n "$keepBuildDirectory"; then
              KEEPBUILDDIR="$out/`basename $TMPDIR`"
              header "Copying build directory to $KEEPBUILDDIR"
              mkdir -p $KEEPBUILDDIR
              cp -R "$TMPDIR/"* $KEEPBUILDDIR
              stopNest
          fi
      fi
    '';
  }

  // args //

  {
    name = name + (if src ? version then "-" + src.version else "");

    postHook = ''
      . ${./functions.sh}
      origSrc=$src
      src=$(findTarballs $src | head -1)
    '';

    initPhase = ''
      mkdir -p $out/nix-support
      echo "$system" > $out/nix-support/system

      if [ -z "${toString doCoverageAnalysis}" ]; then
          for i in $outputs; do
              if [ "$i" = out ]; then j=none; else j="$i"; fi
              mkdir -p ''${!i}/nix-support
              echo "nix-build $j ''${!i}" >> ''${!i}/nix-support/hydra-build-products
          done
      fi
    '';

    prePhases = ["initPhase"] ++ prePhases;

    buildInputs = buildInputs ++ stdenv.lib.optional doCoverageAnalysis args.makeGCOVReport;

    lcovFilter = ["/nix/store/*"] ++ lcovFilter;

    inherit lcovExtraTraceFiles;

    postPhases = postPhases ++ ["finalPhase"];

    meta = (if args ? meta then args.meta else {}) // {
      description = if doCoverageAnalysis then "Coverage analysis" else "Nix package for ${stdenv.system}";
    };

  }

  //

  (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 {})
)