Skip to content

Commit

Permalink
bazel 0.27.0 --> 0.28.1 (digital-asset#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
aherrmann-da authored Aug 19, 2019
1 parent b4dc886 commit 64e8f83
Showing 7 changed files with 183 additions and 81 deletions.
6 changes: 3 additions & 3 deletions dev-env/windows/manifests/bazel.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"homepage": "https://bazel.build",
"version": "0.27.0",
"version": "0.28.1",
"license": "Apache-2.0",
"bin": "bazel.exe",
"architecture": {
"64bit": {
"url": "https://github.com/bazelbuild/bazel/releases/download/0.27.0/bazel-0.27.0-windows-x86_64.zip",
"hash": "6d496005bf02151b983aed1320f1728aca461de2246ee50cbcc56886078b813e"
"url": "https://github.com/bazelbuild/bazel/releases/download/0.28.1/bazel-0.28.1-windows-x86_64.zip",
"hash": "2cb949887f0c8aa5039bb39f52a13a9a13cfcd019d42f65ee16dd134d41c0f72"
}
},
"depends": [
112 changes: 69 additions & 43 deletions nix/overrides/bazel/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{ stdenv, callPackage, lib, fetchurl, runCommand, runCommandCC, makeWrapper
, diffutils, getopt, perl, postgresql
{ stdenv, callPackage, lib, fetchurl, fetchFromGitHub
, runCommand, runCommandCC, makeWrapper, recurseIntoAttrs
# this package (through the fixpoint glass)
, bazel
, lr, xe, zip, unzip, bash, writeCBin, coreutils
, which, gawk, gnused, gnutar, gnugrep, gzip, findutils
# XXX: Modified relative to upstream Nix expression.
, diffutils, getopt, perl, postgresql
# updater
, python3, writeScript
# Apple dependencies
@@ -12,19 +14,21 @@
, buildJdk, runJdk
, buildJdkName
, runtimeShell
# Always assume all markers valid (don't redownload dependencies).
# Also, don't clean up environment variables.
# Downstream packages for tests
, bazel-watcher
# Always assume all markers valid (this is needed because we remove markers; they are non-deterministic).
# Also, don't clean up environment variables (so that NIX_ environment variables are passed to compilers).
, enableNixHacks ? false
, gcc-unwrapped
, autoPatchelfHook
}:

let
version = "0.27.0";
version = "0.28.1";

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

# Update with `eval $(nix-build -A bazel.updater)`,
@@ -34,7 +38,6 @@ let
let
srcs = (builtins.fromJSON (builtins.readFile ./src-deps.json));
toFetchurl = d: lib.attrsets.nameValuePair d.name (fetchurl {
name = d.name;
urls = d.urls;
sha256 = d.sha256;
});
@@ -43,12 +46,13 @@ let
srcs.io_bazel_skydoc
srcs.bazel_skylib
srcs.io_bazel_rules_sass
srcs.platforms
(if stdenv.hostPlatform.isDarwin
then srcs.${"java_tools_javac11_darwin-v2.0.zip"}
else srcs.${"java_tools_javac11_linux-v2.0.zip"})
srcs.${"coverage_output_generator-v1.0.zip"}
srcs.build_bazel_rules_nodejs
srcs.${"android_tools_pkg-0.4.tar.gz"}
srcs.${"android_tools_pkg-0.7.tar.gz"}
]);

distDir = runCommand "bazel-deps" {} ''
@@ -85,7 +89,8 @@ let
# )
#
# XXX: Modified relative to upstream Nix expression.
[ bash coreutils diffutils findutils gawk gnugrep gnutar gnused gzip perl which unzip getopt postgresql ];
[ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip
diffutils getopt perl postgresql ];

# Java toolchain used for the build and tests
javaToolchain = "@bazel_tools//tools/jdk:toolchain_host${buildJdkName}";
@@ -96,8 +101,7 @@ let
# however it contains prebuilt java binaries, with wrong interpreter
# and libraries path.
# We prefetch it, patch it, and override it in a global bazelrc.
system = if stdenv.hostPlatform.isDarwin
then "darwin" else "linux";
system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";

remote_java_tools = stdenv.mkDerivation {
name = "remote_java_tools_${system}";
@@ -135,7 +139,10 @@ stdenv.mkDerivation rec {
sourceRoot = ".";

patches = [
./python-stub-path-fix.patch
# On Darwin, the last argument to gcc is coming up as an empty string. i.e: ''
# This is breaking the build of any C target. This patch removes the last
# argument if it's found to be an empty string.
./trim-last-argument-to-gcc-if-empty.patch
] ++ lib.optional enableNixHacks ./nix-hacks.patch;


@@ -146,11 +153,16 @@ stdenv.mkDerivation rec {
# in the nixpkgs checkout root to exercise them locally.
passthru.tests =
let
runLocal = name: attrs: script: runCommandCC name ({
runLocal = name: attrs: script:
let
attrs' = removeAttrs attrs [ "buildInputs" ];
buildInputs = [ python3 ] ++ (attrs.buildInputs or []);
in
runCommandCC name ({
inherit buildInputs;
preferLocalBuild = true;
meta.platforms = platforms;
buildInputs = [ python3 ];
} // attrs) script;
} // attrs') script;

# bazel wants to extract itself into $install_dir/install every time it runs,
# so let’s do that only once.
@@ -170,10 +182,10 @@ stdenv.mkDerivation rec {
cp -R ${install_dir} $out
'';

bazelTest = { name, bazelScript, workspaceDir, bazelPkg }:
bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
let
be = extracted bazelPkg;
in runLocal name {} (
in runLocal name { inherit buildInputs; } (
# skip extraction caching on Darwin, because nobody knows how Darwin works
(lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
# set up home with pre-unpacked bazel
@@ -200,12 +212,38 @@ stdenv.mkDerivation rec {
'');

bazelWithNixHacks = bazel.override { enableNixHacks = true; };

bazel-examples = fetchFromGitHub {
owner = "bazelbuild";
repo = "examples";
rev = "5d8c8961a2516ebf875787df35e98cadd08d43dc";
sha256 = "03c1bwlq5bs3hg96v4g4pg2vqwhqq6w538h66rcpw02f83yy7fs8";
};

in {
pythonBinPathWithoutNixHacks = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; };
bashToolsWithoutNixHacks = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; };
bashTools = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; };
cpp = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; };
java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples; };
protobuf = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; };
pythonBinPath = callPackage ./python-bin-path-test.nix { inherit runLocal bazelTest; };

pythonBinPathWithNixHacks = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
bashToolsWithNixHacks = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };

cppWithNixHacks = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; bazel = bazelWithNixHacks; };
javaWithNixHacks = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples; bazel = bazelWithNixHacks; };
protobufWithNixHacks = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
pythonBinPathWithNixHacks = callPackage ./python-bin-path-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };

# downstream packages using buildBazelPackage
# fixed-output hashes of the fetch phase need to be spot-checked manually
downstream = recurseIntoAttrs ({
inherit bazel-watcher;
}
# dm-sonnet is only packaged for linux
// (lib.optionalAttrs stdenv.isLinux {
# TODO(timokau) dm-sonnet is broken currently
# dm-sonnet-linux = python3.pkgs.dm-sonnet;
}));
};

# update the list of workspace dependencies
@@ -222,7 +260,6 @@ stdenv.mkDerivation rec {
__darwinAllowLocalNetworking = true;

# Bazel expects several utils to be available in Bash even without PATH. Hence this hack.

customBash = writeCBin "bash" ''
#include <stdio.h>
#include <stdlib.h>
@@ -290,9 +327,8 @@ stdenv.mkDerivation rec {
genericPatches = ''
# Substitute python's stub shebang to plain python path. (see TODO add pr URL)
# See also `postFixup` where python is added to $out/nix-support
substituteInPlace src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt\
--replace "/usr/bin/env python" "${python3}/bin/python" \
--replace "NIX_STORE_PYTHON_PATH" "${python3}/bin/python" \
substituteInPlace src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt \
--replace "#!/usr/bin/env python" "#!${python3}/bin/python"
# md5sum is part of coreutils
sed -i 's|/sbin/md5|md5sum|' \
@@ -312,15 +348,20 @@ stdenv.mkDerivation rec {
substituteInPlace tools/build_rules/test_rules.bzl \
--replace /bin/bash ${customBash}/bin/bash
for i in $(find tools/cpp/ -type f)
do
substituteInPlace $i \
--replace /bin/bash ${customBash}/bin/bash
done
# Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
substituteInPlace scripts/bootstrap/compile.sh \
--replace /bin/bash ${customBash}/bin/bash
# add nix environment vars to .bazelrc
cat >> .bazelrc <<EOF
build --experimental_distdir=${distDir}
fetch --experimental_distdir=${distDir}
build --distdir=${distDir}
fetch --distdir=${distDir}
build --copt="$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt="/g')"
build --host_copt="$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt="/g')"
build --linkopt="-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt="-Wl,/g')"
@@ -436,24 +477,8 @@ stdenv.mkDerivation rec {
installCheckPhase = ''
export TEST_TMPDIR=$(pwd)
tar xf ${srcDepsSet.io_bazel_skydoc} -C $TEST_TMPDIR
mv $(ls | grep skydoc-) io_bazel_skydoc
tar xf ${srcDepsSet.bazel_skylib} -C $TEST_TMPDIR
mv $(ls | grep bazel-skylib-) bazel_skylib
tar xf ${srcDepsSet.io_bazel_rules_sass} -C $TEST_TMPDIR
mv $(ls | grep rules_sass-) rules_sass
unzip ${srcDepsSet.build_bazel_rules_nodejs} -d $TEST_TMPDIR
mv rules_nodejs-0.16.2 build_bazel_rules_nodejs
hello_test () {
$out/bin/bazel test \
--override_repository=io_bazel_skydoc=$TEST_TMPDIR/io_bazel_skydoc \
--override_repository=bazel_skylib=$TEST_TMPDIR/bazel_skylib \
--override_repository=io_bazel_rules_sass=$TEST_TMPDIR/rules_sass \
--override_repository=build_bazel_rules_nodejs=$TEST_TMPDIR/build_bazel_rules_nodejs \
$out/bin/bazel test --distdir=${distDir} \
--test_output=errors \
--java_toolchain='${javaToolchain}' \
examples/cpp:hello-success_test \
@@ -484,6 +509,7 @@ stdenv.mkDerivation rec {
'';

# Save paths to hardcoded dependencies so Nix can detect them.
# XXX: Modified relative to upstream Nix expression.
postFixup = ''
mkdir -p $out/nix-support
echo "${customBash} ${defaultShellPath}" >> $out/nix-support/depends
13 changes: 0 additions & 13 deletions nix/overrides/bazel/python-stub-path-fix.patch

This file was deleted.

Loading

0 comments on commit 64e8f83

Please sign in to comment.