@@ -1,35 +1,70 @@
1−{ stdenv, fetchFromGitHub, jdk, zip, zlib, protobuf3_0, pkgconfig, libarchive, unzip, which, makeWrapper }:
2−stdenv.mkDerivation rec {
3− version = "0.3.1";
4− name = "bazel-${version}";
5−
6− src = fetchFromGitHub {
7− owner = "google";
8− repo = "bazel";
9− rev = version;
10− sha256 = "1cm8zjxf8y3ai6h9wndxvflfsijjqhg87fll9ar7ff0hbbbdf6l5";
1+{ stdenv, fetchFromGitHub, buildFHSUserEnv, writeScript, jdk, zip, unzip,
2+ which, makeWrapper, binutils }:
3+
4+let
5+
6+ version = "0.3.2";
7+
8+ meta = with stdenv.lib; {
9+ homepage = http://github.com/bazelbuild/bazel/;
10+ description = "Build tool that builds code quickly and reliably";
11+ license = licenses.asl20;
12+ maintainers = [ maintainers.philandstuff ];
13+ platforms = [ "x86_64-linux" ];
14+ };
15+
16+ bootstrapEnv = buildFHSUserEnv {
17+ name = "bazel-bootstrap-env";
18+
19+ targetPkgs = pkgs: [ ];
20+
21+ inherit meta;
1122 };
1223
13− buildInputs = [ pkgconfig protobuf3_0 zlib zip libarchive unzip which makeWrapper jdk ];
24+ bazelBinary = stdenv.mkDerivation rec {
25+ name = "bazel-${version}";
26+
27+ src = fetchFromGitHub {
28+ owner = "bazelbuild";
29+ repo = "bazel";
30+ rev = version;
31+ sha256 = "085cjz0qhm4a12jmhkjd9w3ic4a67035j01q111h387iklvgn6xg";
32+ };
33+ patches = [ ./java_stub_template.patch ];
1434
15− buildPhase = ''
16− export LD_LIBRARY_PATH="${stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib ]}"
35+ packagesNotFromEnv = [
36+ stdenv.cc stdenv.cc.cc.lib jdk which zip unzip binutils ];
37+ buildInputs = packagesNotFromEnv ++ [ bootstrapEnv makeWrapper ];
1738
18− bash compile.sh
19− '';
39+ buildTimeBinPath = stdenv.lib.makeBinPath packagesNotFromEnv;
40+ buildTimeLibPath = stdenv.lib.makeLibraryPath packagesNotFromEnv;
2041
21− installPhase = ''
22− mkdir -p $out/bin $out/share
23− cp -R output $out/share/bazel
24− ln -s $out/share/bazel/bazel $out/bin/bazel
25− wrapProgram $out/bin/bazel --set JAVA_HOME "${jdk.home}"
26− '';
42+ runTimeBinPath = stdenv.lib.makeBinPath [ jdk stdenv.cc.cc ];
43+ runTimeLibPath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib ];
2744
28− meta = {
29− homepage = http://github.com/google/bazel/;
30− description = "Build tool that builds code quickly and reliably";
31− license = stdenv.lib.licenses.asl20;
32− maintainers = [ stdenv.lib.maintainers.philandstuff ];
33− platforms = [ "x86_64-linux" ];
45+ buildWrapper = writeScript "build-wrapper.sh" ''
46+ #! ${stdenv.shell} -e
47+ export PATH="${buildTimeBinPath}:$PATH"
48+ export LD_LIBRARY_PATH="${buildTimeLibPath}:$LD_LIBRARY_PATH"
49+ ./compile.sh
50+ '';
51+
52+ buildPhase = ''
53+ bazel-bootstrap-env ${buildWrapper}
54+ '';
55+
56+ installPhase = ''
57+ mkdir -p $out/bin
58+ cp output/bazel $out/bin/
59+ wrapProgram $out/bin/bazel \
60+ --suffix PATH ":" "${runTimeBinPath}" \
61+ --suffix LD_LIBRARY_PATH ":" "${runTimeLibPath}"
62+ '';
63+
64+ dontStrip = true;
65+ dontPatchELF = true;
66+
67+ inherit meta;
3468 };
35−}
69+
70+in bazelBinary