@@ -1,5 +1,7 @@
1−{ stdenv, callPackage, lib, fetchurl, fetchpatch, runCommand, makeWrapper
2−, zip, unzip, bash, writeCBin, coreutils
1+{ stdenv, callPackage, lib, fetchurl, fetchpatch, runCommand, runCommandCC, makeWrapper
2+# this package (through the fixpoint glass)
3+, bazel
4+, lr, xe, zip, unzip, bash, writeCBin, coreutils
35, which, python, perl, gawk, gnused, gnutar, gnugrep, gzip, findutils
46# Apple dependencies
57, cctools, clang, libcxx, CoreFoundation, CoreServices, Foundation
@@ -14,14 +16,42 @@
1416
1517let
1618 srcDeps = [
19+ # From: $REPO_ROOT/WORKSPACE
1720 (fetchurl {
1821 url = "https://github.com/google/desugar_jdk_libs/archive/915f566d1dc23bc5a8975320cd2ff71be108eb9c.zip";
1922 sha256 = "0b926df7yxyyyiwm9cmdijy6kplf0sghm23sf163zh8wrk87wfi7";
2023 })
21−
2224 (fetchurl {
23− url = "https://mirror.bazel.build/bazel_java_tools/java_tools_pkg-0.5.1.tar.gz";
24− sha256 = "1ld8m5cj9j0r474f56pixcfi0xvx3w7pzwahxngs8f6ns0yimz5w";
25+ url = "https://mirror.bazel.build/github.com/bazelbuild/skydoc/archive/2d9566b21fbe405acf5f7bf77eda30df72a4744c.tar.gz";
26+ sha256 = "4a1318fed4831697b83ce879b3ab70ae09592b167e5bda8edaff45132d1c3b3f";
27+ })
28+ (fetchurl {
29+ url = "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz";
30+ sha256 = "ba5d15ca230efca96320085d8e4d58da826d1f81b444ef8afccd8b23e0799b52";
31+ })
32+ (fetchurl {
33+ url = "https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/8ccf4f1c351928b55d5dddf3672e3667f6978d60.tar.gz";
34+ sha256 = "d868ce50d592ef4aad7dec4dd32ae68d2151261913450fac8390b3fd474bb898";
35+ })
36+ (fetchurl {
37+ url = "https://mirror.bazel.build/bazel_java_tools/releases/javac10/v3.1/java_tools_javac10_linux-v3.1.zip";
38+ sha256 = "a0cd51f9db1bf05a722ff7f5c60a07fa1c7d27428fff0815c342d32aa6c53576";
39+ })
40+ (fetchurl {
41+ url = "https://mirror.bazel.build/bazel_java_tools/releases/javac10/v3.1/java_tools_javac10_darwin-v3.1.zip";
42+ sha256 = "c646aad8808b8ec5844d6a80a1287fc8e13203375fe40d6af4819eff48b9bbaf";
43+ })
44+ (fetchurl {
45+ url = "https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v1.0.zip";
46+ sha256 = "cc470e529fafb6165b5be3929ff2d99b38429b386ac100878687416603a67889";
47+ })
48+ (fetchurl {
49+ url = "https://github.com/bazelbuild/rules_nodejs/archive/0.16.2.zip";
50+ sha256 = "9b72bb0aea72d7cbcfc82a01b1e25bf3d85f791e790ddec16c65e2d906382ee0";
51+ })
52+ (fetchurl {
53+ url = "https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.2.tar.gz";
54+ sha256 = "04f85f2dd049e87805511e3babc5cea3f5e72332b1627e34f3a5461cc38e815f";
2555 })
2656 ];
2757
@@ -63,17 +93,19 @@ let
6393 # Java toolchain used for the build and tests
6494 javaToolchain = "@bazel_tools//tools/jdk:toolchain_host${buildJdkName}";
6595
96+ platforms = lib.platforms.linux ++ lib.platforms.darwin;
97+
6698in
6799stdenv.mkDerivation rec {
68100
69− version = "0.24.0";
101+ version = "0.26.0";
70102
71103 meta = with lib; {
72104 homepage = "https://github.com/bazelbuild/bazel/";
73105 description = "Build tool that builds code quickly and reliably";
74106 license = licenses.asl20;
75107 maintainers = [ maintainers.mboes ];
76− platforms = platforms.linux ++ platforms.darwin;
108+ inherit platforms;
77109 };
78110
79111 # Additional tests that check bazel’s functionality. Execute
@@ -81,16 +113,68 @@ stdenv.mkDerivation rec {
81113 # nix-build . -A bazel.tests
82114 #
83115 # in the nixpkgs checkout root to exercise them locally.
84− passthru.tests = {
85− pythonBinPath = callPackage ./python-bin-path-test.nix {};
86− bashTools = callPackage ./bash-tools-test.nix {};
87− };
116+ passthru.tests =
117+ let
118+ runLocal = name: attrs: script: runCommandCC name ({
119+ preferLocalBuild = true;
120+ meta.platforms = platforms;
121+ } // attrs) script;
122+
123+ # bazel wants to extract itself into $install_dir/install every time it runs,
124+ # so let’s do that only once.
125+ extracted =
126+ let install_dir =
127+ # `install_base` field printed by `bazel info`, minus the hash.
128+ # yes, this path is kinda magic. Sorry.
129+ "$HOME/.cache/bazel/_bazel_nixbld";
130+ in runLocal "bazel-extracted-homedir" { passthru.install_dir = install_dir; } ''
131+ export HOME=$(mktemp -d)
132+ touch WORKSPACE # yeah, everything sucks
133+ install_base="$(${bazel}/bin/bazel info | grep install_base)"
134+ # assert it’s actually below install_dir
135+ [[ "$install_base" =~ ${install_dir} ]] \
136+ || (echo "oh no! $install_base but we are \
137+ trying to copy ${install_dir} to $out instead!"; exit 1)
138+ cp -R ${install_dir} $out
139+ '';
140+
141+ bazelTest = { name, bazelScript, workspaceDir }:
142+ runLocal name {} (
143+ # skip extraction caching on Darwin, because nobody knows how Darwin works
144+ (lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
145+ # set up home with pre-unpacked bazel
146+ export HOME=$(mktemp -d)
147+ mkdir -p ${extracted.install_dir}
148+ cp -R ${extracted}/install ${extracted.install_dir}
149+
150+ # https://stackoverflow.com/questions/47775668/bazel-how-to-skip-corrupt-installation-on-centos6
151+ # Bazel checks whether the mtime of the install dir files
152+ # is >9 years in the future, otherwise it extracts itself again.
153+ # see PosixFileMTime::IsUntampered in src/main/cpp/util
154+ # What the hell bazel.
155+ ${lr}/bin/lr -0 -U ${extracted.install_dir} | ${xe}/bin/xe -N0 -0 touch --date="9 years 6 months" {}
156+ '')
157+ +
158+ ''
159+ # Note https://github.com/bazelbuild/bazel/issues/5763#issuecomment-456374609
160+ # about why to create a subdir for the workspace.
161+ cp -r ${workspaceDir} wd && chmod u+w wd && cd wd
162+
163+ ${bazelScript}
164+
165+ touch $out
166+ '');
167+
168+ in {
169+ pythonBinPath = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; };
170+ bashTools = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; };
171+ };
88172
89173 name = "bazel-${version}";
90174
91175 src = fetchurl {
92176 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/${name}-dist.zip";
93− sha256 = "11gsc00ghxqkbci8nrflkwq1lcvqawlgkaryj458b24si6bjl7b2";
177+ sha256 = "d26dadf62959255d58e523da3448a6222af768fe1224e321b120c1d5bbe4b4f2";
94178 };
95179
96180 # Necessary for the tests to pass on Darwin with sandbox enabled.
@@ -148,10 +232,6 @@ stdenv.mkDerivation rec {
148232 # https://github.com/NixOS/nixpkgs/pull/41589
149233 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem ${libcxx}/include/c++/v1"
150234
151− # 10.10 apple_sdk Foundation doesn't have type arguments on classes
152− # Remove this when we update apple_sdk
153− sed -i -e 's/<.*\*>//g' tools/osx/xcode_locator.m
154−
155235 # don't use system installed Xcode to run clang, use Nix clang instead
156236 sed -i -e "s;/usr/bin/xcrun clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $NIX_LDFLAGS -framework CoreFoundation;g" \
157237 scripts/bootstrap/compile.sh \
@@ -159,6 +239,9 @@ stdenv.mkDerivation rec {
159239 src/tools/xcode/stdredirect/BUILD \
160240 tools/osx/BUILD
161241
242+ # nixpkgs's libSystem cannot use pthread headers directly, must import GCD headers instead
243+ sed -i -e "/#include <pthread\/spawn.h>/i #include <dispatch/dispatch.h>" src/main/cpp/blaze_util_darwin.cc
244+
162245 # clang installed from Xcode has a compatibility wrapper that forwards
163246 # invocations of gcc to clang, but vanilla clang doesn't
164247 sed -i -e 's;_find_generic(repository_ctx, "gcc", "CC", overriden_tools);_find_generic(repository_ctx, "clang", "CC", overriden_tools);g' tools/cpp/unix_cc_configure.bzl
@@ -193,7 +276,7 @@ stdenv.mkDerivation rec {
193276
194277 # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
195278 substituteInPlace scripts/bootstrap/compile.sh \
196− --replace /bin/sh ${customBash}/bin/bash
279+ --replace /bin/bash ${customBash}/bin/bash
197280
198281 # add nix environment vars to .bazelrc
199282 cat >> .bazelrc <<EOF
@@ -297,7 +380,9 @@ stdenv.mkDerivation rec {
297380 cp ./bazel_src/scripts/zsh_completion/_bazel $out/share/zsh/site-functions/
298381 '';
299382
300− doInstallCheck = true;
383+ # Temporarily disabling for now. A new approach is needed for this derivation as Bazel
384+ # accesses the internet during the tests which fails in a sandbox.
385+ doInstallCheck = false;
301386 installCheckPhase = ''
302387 export TEST_TMPDIR=$(pwd)
303388