lol
1{ stdenv, lib, fetchurl, jdk, zip, unzip, bash, makeWrapper, which, coreutils
2# Always assume all markers valid (don't redownload dependencies).
3# Also, don't clean up environment variables.
4, enableNixHacks ? false
5}:
6
7stdenv.mkDerivation rec {
8
9 version = "0.4.5";
10
11 meta = with stdenv.lib; {
12 homepage = https://github.com/bazelbuild/bazel/;
13 description = "Build tool that builds code quickly and reliably";
14 license = licenses.asl20;
15 maintainers = with maintainers; [ cstrahan philandstuff ];
16 platforms = platforms.linux;
17 broken = true; # 2018-08-07
18 };
19
20 name = "bazel-${version}";
21
22 src = fetchurl {
23 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
24 sha256 = "0asmq3kxnl4326zhgh13mvcrc8jvmiswjj4ymrq0943q4vj7nwrb";
25 };
26
27 preUnpack = ''
28 mkdir bazel
29 cd bazel
30 '';
31 sourceRoot = ".";
32
33 patches = lib.optional enableNixHacks ./nix-hacks-0.4.patch;
34
35 postPatch = ''
36 for f in $(grep -l -r '/bin/bash'); do
37 substituteInPlace "$f" --replace '/bin/bash' '${bash}/bin/bash'
38 done
39 for f in $(grep -l -r '/usr/bin/env'); do
40 substituteInPlace "$f" --replace '/usr/bin/env' '${coreutils}/bin/env'
41 done
42 '' + lib.optionalString stdenv.isDarwin ''
43 sed -i 's,/usr/bin/xcrun clang,clang,g' \
44 scripts/bootstrap/compile.sh \
45 src/tools/xcode/realpath/BUILD \
46 src/tools/xcode/stdredirect/BUILD \
47 src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
48 sed -i 's,/usr/bin/xcrun "''${TOOLNAME}","''${TOOLNAME}",g' \
49 src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
50 sed -i 's/"xcrun", "clang"/"clang"/g' tools/osx/xcode_configure.bzl
51 '';
52
53 buildInputs = [
54 jdk
55 zip
56 unzip
57 makeWrapper
58 which
59 ];
60
61 # These must be propagated since the dependency is hidden in a compressed
62 # archive.
63
64 propagatedBuildInputs = [
65 bash
66 ];
67
68 buildPhase = ''
69 export TMPDIR=/tmp/.bazel-$UID
70 ./compile.sh
71 ./output/bazel --output_user_root=$TMPDIR/.bazel build //scripts:bash_completion \
72 --spawn_strategy=standalone \
73 --genrule_strategy=standalone
74 cp bazel-bin/scripts/bazel-complete.bash output/
75 '';
76
77 # Build the CPP and Java examples to verify that Bazel works.
78
79 doCheck = true;
80 checkPhase = ''
81 export TEST_TMPDIR=$(pwd)
82 ./output/bazel test --test_output=errors \
83 examples/cpp:hello-success_test \
84 examples/java-native/src/test/java/com/example/myproject:hello
85 '';
86
87 # Bazel expects gcc and java to be in the path.
88
89 installPhase = ''
90 mkdir -p $out/bin
91 mv output/bazel $out/bin
92 wrapProgram "$out/bin/bazel" --prefix PATH : "${stdenv.cc}/bin:${jdk}/bin"
93 mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions
94 mv output/bazel-complete.bash $out/share/bash-completion/completions/
95 cp scripts/zsh_completion/_bazel $out/share/zsh/site-functions/
96 '';
97
98 dontStrip = true;
99 dontPatchELF = true;
100}