about summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers/bazel/default.nix
blob: a8ad08feec1165400d9955c73005f8ad3d006218 (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
{ stdenv, fetchurl, jdk, zip, unzip, which, bash, binutils, coreutils, makeWrapper }:

stdenv.mkDerivation rec {

  version = "0.4.4";

  meta = with stdenv.lib; {
    homepage = http://github.com/bazelbuild/bazel/;
    description = "Build tool that builds code quickly and reliably";
    license = licenses.asl20;
    maintainers = [ maintainers.philandstuff ];
    platforms = platforms.linux;
  };

  name = "bazel-${version}";

  src = fetchurl {
    url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
    sha256 = "1fwfahkqi680zyxmdriqj603lpacyh6cg6ff25bn9bkilbfj2anm";
  };

  sourceRoot = ".";

  postPatch = ''
    patchShebangs .
    for f in \
      src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java \
      src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java \
      src/test/java/com/google/devtools/build/lib/shell/CommandTest.java \
      src/test/java/com/google/devtools/build/lib/shell/InterruptibleTest.java \
      src/test/java/com/google/devtools/build/lib/shell/LoadTest.java \
      src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java \
      src/test/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategyTest.java
    do
      substituteInPlace $f \
        --replace /bin/bash ${bash}/bin/bash \
        --replace /bin/cat ${coreutils}/bin/cat \
        --replace /bin/echo ${coreutils}/bin/echo \
        --replace /bin/false ${coreutils}/bin/false \
        --replace /bin/pwd ${coreutils}/bin/pwd \
        --replace /bin/sleep ${coreutils}/bin/sleep \
        --replace /bin/true ${coreutils}/bin/true
    done
  '';

  buildInputs = [
    stdenv.cc
    stdenv.cc.cc.lib
    jdk
    zip
    unzip
    which
    binutils
    makeWrapper
  ];

  # These must be propagated since the dependency is hidden in a compressed
  # archive.

  propagatedBuildInputs = [
    bash
    coreutils
  ];

  # If TMPDIR is in the unpack dir we run afoul of blaze's infinite symlink
  # detector (see com.google.devtools.build.lib.skyframe.FileFunction).
  # Change this to $(mktemp -d) as soon as we figure out why.

  buildPhase = ''
    export TMPDIR=/tmp
    ./compile.sh
  '';

  # Build the CPP and Java examples to verify that Bazel works.

  doCheck = true;
  checkPhase = ''
    export TEST_TMPDIR=$(pwd)
    ./output/bazel test --test_output=errors \
        examples/cpp:hello-success_test \
        examples/java-native/src/test/java/com/example/myproject:hello
  '';

  installPhase = ''
    mkdir -p $out/bin
    mv output/bazel $out/bin
    wrapProgram "$out/bin/bazel" --prefix PATH : "${jdk}/bin"
  '';

  dontStrip = true;
  dontPatchELF = true;
}