git.iko.soy/typeable/nixpkgs
on master help sign in
bazel: add a test asserting java and java proto (#63927)
commit7f69cab8a606f318efc21edde9da7b5389b2cb13 authorWael Nasreddine <wael.nasreddine@gmail.com> dateMon 1 Jul 2019, 21:18 (7 years ago) parent4c86dee
3 files changed+79−10
pkgs/development/tools/build-managers/bazel/default.nix+13−8 pkgs/development/tools/build-managers/bazel/java-test.nix+56 pkgs/development/tools/build-managers/bazel/protobuf-test.nix+10−2
pkgs/development/tools/build-managers/bazel/default.nix+13−8
@@ -94,8 +94,7 @@ let
9494 # however it contains prebuilt java binaries, with wrong interpreter
9595 # and libraries path.
9696 # We prefetch it, patch it, and override it in a global bazelrc.
97− system = if stdenv.hostPlatform.isDarwin
98− then "darwin" else "linux";
97+ system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";
9998
10099 remote_java_tools = stdenv.mkDerivation {
101100 name = "remote_java_tools_${system}";
@@ -149,11 +148,16 @@ stdenv.mkDerivation rec {
149148 # in the nixpkgs checkout root to exercise them locally.
150149 passthru.tests =
151150 let
152− runLocal = name: attrs: script: runCommandCC name ({
151+ runLocal = name: attrs: script:
152+ let
153+ attrs' = removeAttrs attrs [ "buildInputs" ];
154+ buildInputs = [ python3 ] ++ (attrs.buildInputs or []);
155+ in
156+ runCommandCC name ({
157+ inherit buildInputs;
153158 preferLocalBuild = true;
154159 meta.platforms = platforms;
155− buildInputs = [ python3 ];
156− } // attrs) script;
160+ } // attrs') script;
157161
158162 # bazel wants to extract itself into $install_dir/install every time it runs,
159163 # so let’s do that only once.
@@ -173,10 +177,10 @@ stdenv.mkDerivation rec {
173177 cp -R ${install_dir} $out
174178 '';
175179
176− bazelTest = { name, bazelScript, workspaceDir, bazelPkg }:
180+ bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
177181 let
178182 be = extracted bazelPkg;
179− in runLocal name {} (
183+ in runLocal name { inherit buildInputs; } (
180184 # skip extraction caching on Darwin, because nobody knows how Darwin works
181185 (lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
182186 # set up home with pre-unpacked bazel
@@ -214,11 +218,13 @@ stdenv.mkDerivation rec {
214218 in {
215219 bashTools = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; };
216220 cpp = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; };
221+ java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples; };
217222 protobuf = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; };
218223 pythonBinPath = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; };
219224
220225 bashToolsWithNixHacks = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
221226 cppWithNixHacks = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; bazel = bazelWithNixHacks; };
227+ javaWithNixHacks = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples; bazel = bazelWithNixHacks; };
222228 protobufWithNixHacks = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
223229 pythonBinPathWithNixHacks = callPackage ./python-bin-path-test.nix{ inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
224230 };
@@ -237,7 +243,6 @@ stdenv.mkDerivation rec {
237243 __darwinAllowLocalNetworking = true;
238244
239245 # Bazel expects several utils to be available in Bash even without PATH. Hence this hack.
240−
241246 customBash = writeCBin "bash" ''
242247 #include <stdio.h>
243248 #include <stdlib.h>
pkgs/development/tools/build-managers/bazel/java-test.nixnew file+56
@@ -0,0 +1,56 @@
1+{
2+ bazel
3+, bazelTest
4+, bazel-examples
5+, gccStdenv
6+, lib
7+, openjdk8
8+, runLocal
9+, runtimeShell
10+, writeScript
11+, writeText
12+}:
13+
14+let
15+
16+ toolsBazel = writeScript "bazel" ''
17+ #! ${runtimeShell}
18+
19+ export CXX='${gccStdenv.cc}/bin/g++'
20+ export LD='${gccStdenv.cc}/bin/ld'
21+ export CC='${gccStdenv.cc}/bin/gcc'
22+
23+ # XXX: hack for macosX, this flags disable bazel usage of xcode
24+ # See: https://github.com/bazelbuild/bazel/issues/4231
25+ export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
26+
27+ exec "$BAZEL_REAL" "$@"
28+ '';
29+
30+ workspaceDir = runLocal "our_workspace" {} (''
31+ cp -r ${bazel-examples}/java-tutorial $out
32+ find $out -type d -exec chmod 755 {} \;
33+ ''
34+ + (lib.optionalString gccStdenv.isDarwin ''
35+ mkdir $out/tools
36+ cp ${toolsBazel} $out/tools/bazel
37+ ''));
38+
39+ testBazel = bazelTest {
40+ name = "bazel-test-cpp";
41+ inherit workspaceDir;
42+ bazelPkg = bazel;
43+ buildInputs = [ openjdk8 ];
44+ bazelScript = ''
45+ ${bazel}/bin/bazel \
46+ run \
47+ --host_javabase='@local_jdk//:jdk' \
48+ --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
49+ --javabase='@local_jdk//:jdk' \
50+ --verbose_failures \
51+ //:ProjectRunner
52+ '';
53+ };
54+
55+in testBazel
56+
pkgs/development/tools/build-managers/bazel/protobuf-test.nix+10−2
@@ -5,6 +5,7 @@
55, fetchurl
66, gccStdenv
77, lib
8+, openjdk8
89, runLocal
910, runtimeShell
1011, writeScript
@@ -77,6 +78,8 @@ let
7778 personProto = writeText "person.proto" ''
7879 syntax = "proto3";
7980
81+ package person;
82+
8083 message Person {
8184 string name = 1;
8285 int32 id = 2;
@@ -134,10 +137,15 @@ let
134137 name = "bazel-test-protocol-buffers";
135138 inherit workspaceDir;
136139 bazelPkg = bazel;
140+ buildInputs = [ openjdk8 ];
137141 bazelScript = ''
138142 ${bazel}/bin/bazel \
139− build --verbose_failures \
140− //person:person_proto
143+ build \
144+ --host_javabase='@local_jdk//:jdk' \
145+ --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
146+ --javabase='@local_jdk//:jdk' \
147+ --verbose_failures \
148+ //...
141149 '';
142150 };
143151