about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/build-managers/bazel/0.4.nix
blob: 1018abd6ee9c150214f9252e49bbbf17d0647194 (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
{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, makeWrapper, which, coreutils
# Always assume all markers valid (don't redownload dependencies).
# Also, don't clean up environment variables.
, enableNixHacks ? false
}:

stdenv.mkDerivation rec {

  version = "0.4.5";

  meta = with stdenv.lib; {
    homepage = https://github.com/bazelbuild/bazel/;
    description = "Build tool that builds code quickly and reliably";
    license = licenses.asl20;
    maintainers = with maintainers; [ cstrahan philandstuff ];
    platforms = platforms.linux;
    broken = true; # 2018-08-07
  };

  name = "bazel-${version}";

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

  preUnpack = ''
    mkdir bazel
    cd bazel
  '';
  sourceRoot = ".";

  patches = lib.optional enableNixHacks ./nix-hacks-0.4.patch;

  postPatch = ''
    for f in $(grep -l -r '/bin/bash'); do
      substituteInPlace "$f" --replace '/bin/bash' '${bash}/bin/bash'
    done
    for f in $(grep -l -r '/usr/bin/env'); do
      substituteInPlace "$f" --replace '/usr/bin/env' '${coreutils}/bin/env'
    done
  '' + lib.optionalString stdenv.isDarwin ''
    sed -i 's,/usr/bin/xcrun clang,clang,g' \
      scripts/bootstrap/compile.sh \
      src/tools/xcode/realpath/BUILD \
      src/tools/xcode/stdredirect/BUILD \
      src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
    sed -i 's,/usr/bin/xcrun "''${TOOLNAME}","''${TOOLNAME}",g' \
      src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
    sed -i 's/"xcrun", "clang"/"clang"/g' tools/osx/xcode_configure.bzl
  '';

  buildInputs = [
    jdk
    zip
    unzip
    makeWrapper
    which
  ];

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

  propagatedBuildInputs = [
    bash
  ];

  buildPhase = ''
    export TMPDIR=/tmp/.bazel-$UID
    ./compile.sh
    ./output/bazel --output_user_root=$TMPDIR/.bazel build //scripts:bash_completion \
      --spawn_strategy=standalone \
      --genrule_strategy=standalone
    cp bazel-bin/scripts/bazel-complete.bash output/
  '';

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

  # Bazel expects gcc and java to be in the path.

  installPhase = ''
    mkdir -p $out/bin
    mv output/bazel $out/bin
    wrapProgram "$out/bin/bazel" --prefix PATH : "${stdenv.cc}/bin:${jdk}/bin"
    mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions
    mv output/bazel-complete.bash $out/share/bash-completion/completions/
    cp scripts/zsh_completion/_bazel $out/share/zsh/site-functions/
  '';

  dontStrip = true;
  dontPatchELF = true;
}