about summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers
diff options
context:
space:
mode:
authorWael Nasreddine <wael.nasreddine@gmail.com>2019-07-01 21:18:02 -0700
committerGitHub <noreply@github.com>2019-07-01 21:18:02 -0700
commit7f69cab8a606f318efc21edde9da7b5389b2cb13 (patch)
treeb80e1bdd38bbd42ba0b7ceff070778d8c3916e21 /pkgs/development/tools/build-managers
parent4c86deee99bd1d61b6a9de6d3dcabcc55051e15d (diff)
downloadnixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.tar
nixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.tar.gz
nixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.tar.bz2
nixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.tar.lz
nixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.tar.xz
nixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.tar.zst
nixlib-7f69cab8a606f318efc21edde9da7b5389b2cb13.zip
bazel: add a test asserting java and java proto (#63927)
Diffstat (limited to 'pkgs/development/tools/build-managers')
-rw-r--r--pkgs/development/tools/build-managers/bazel/default.nix21
-rw-r--r--pkgs/development/tools/build-managers/bazel/java-test.nix56
-rw-r--r--pkgs/development/tools/build-managers/bazel/protobuf-test.nix12
3 files changed, 79 insertions, 10 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/default.nix b/pkgs/development/tools/build-managers/bazel/default.nix
index 8aac432d3bb6..bad0023eef32 100644
--- a/pkgs/development/tools/build-managers/bazel/default.nix
+++ b/pkgs/development/tools/build-managers/bazel/default.nix
@@ -94,8 +94,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}";
@@ -149,11 +148,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.
@@ -173,10 +177,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
@@ -214,11 +218,13 @@ stdenv.mkDerivation rec {
     in {
       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; };
 
       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; };
     };
@@ -237,7 +243,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>
diff --git a/pkgs/development/tools/build-managers/bazel/java-test.nix b/pkgs/development/tools/build-managers/bazel/java-test.nix
new file mode 100644
index 000000000000..5f780a795e31
--- /dev/null
+++ b/pkgs/development/tools/build-managers/bazel/java-test.nix
@@ -0,0 +1,56 @@
+{
+  bazel
+, bazelTest
+, bazel-examples
+, gccStdenv
+, lib
+, openjdk8
+, runLocal
+, runtimeShell
+, writeScript
+, writeText
+}:
+
+let
+
+  toolsBazel = writeScript "bazel" ''
+    #! ${runtimeShell}
+
+    export CXX='${gccStdenv.cc}/bin/g++'
+    export LD='${gccStdenv.cc}/bin/ld'
+    export CC='${gccStdenv.cc}/bin/gcc'
+
+    # XXX: hack for macosX, this flags disable bazel usage of xcode
+    # See: https://github.com/bazelbuild/bazel/issues/4231
+    export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
+
+    exec "$BAZEL_REAL" "$@"
+  '';
+
+  workspaceDir = runLocal "our_workspace" {} (''
+    cp -r ${bazel-examples}/java-tutorial $out
+    find $out -type d -exec chmod 755 {} \;
+  ''
+  + (lib.optionalString gccStdenv.isDarwin ''
+    mkdir $out/tools
+    cp ${toolsBazel} $out/tools/bazel
+  ''));
+
+  testBazel = bazelTest {
+    name = "bazel-test-cpp";
+    inherit workspaceDir;
+    bazelPkg = bazel;
+    buildInputs = [ openjdk8 ];
+    bazelScript = ''
+      ${bazel}/bin/bazel \
+        run \
+          --host_javabase='@local_jdk//:jdk' \
+          --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
+          --javabase='@local_jdk//:jdk' \
+          --verbose_failures \
+          //:ProjectRunner
+    '';
+  };
+
+in testBazel
+
diff --git a/pkgs/development/tools/build-managers/bazel/protobuf-test.nix b/pkgs/development/tools/build-managers/bazel/protobuf-test.nix
index c4120f2fc031..90065be67bc7 100644
--- a/pkgs/development/tools/build-managers/bazel/protobuf-test.nix
+++ b/pkgs/development/tools/build-managers/bazel/protobuf-test.nix
@@ -5,6 +5,7 @@
 , fetchurl
 , gccStdenv
 , lib
+, openjdk8
 , runLocal
 , runtimeShell
 , writeScript
@@ -77,6 +78,8 @@ let
   personProto = writeText "person.proto" ''
     syntax = "proto3";
 
+    package person;
+
     message Person {
       string name = 1;
       int32 id = 2;
@@ -134,10 +137,15 @@ let
     name = "bazel-test-protocol-buffers";
     inherit workspaceDir;
     bazelPkg = bazel;
+    buildInputs = [ openjdk8 ];
     bazelScript = ''
       ${bazel}/bin/bazel \
-        build --verbose_failures \
-          //person:person_proto
+        build \
+          --host_javabase='@local_jdk//:jdk' \
+          --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
+          --javabase='@local_jdk//:jdk' \
+          --verbose_failures \
+          //...
     '';
   };