bazel: add a test asserting java and java proto (#63927)
This commit is contained in:
parent
4c86deee99
commit
7f69cab8a6
@ -94,8 +94,7 @@ let
|
|||||||
# however it contains prebuilt java binaries, with wrong interpreter
|
# however it contains prebuilt java binaries, with wrong interpreter
|
||||||
# and libraries path.
|
# and libraries path.
|
||||||
# We prefetch it, patch it, and override it in a global bazelrc.
|
# We prefetch it, patch it, and override it in a global bazelrc.
|
||||||
system = if stdenv.hostPlatform.isDarwin
|
system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";
|
||||||
then "darwin" else "linux";
|
|
||||||
|
|
||||||
remote_java_tools = stdenv.mkDerivation {
|
remote_java_tools = stdenv.mkDerivation {
|
||||||
name = "remote_java_tools_${system}";
|
name = "remote_java_tools_${system}";
|
||||||
@ -149,11 +148,16 @@ stdenv.mkDerivation rec {
|
|||||||
# in the nixpkgs checkout root to exercise them locally.
|
# in the nixpkgs checkout root to exercise them locally.
|
||||||
passthru.tests =
|
passthru.tests =
|
||||||
let
|
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;
|
preferLocalBuild = true;
|
||||||
meta.platforms = platforms;
|
meta.platforms = platforms;
|
||||||
buildInputs = [ python3 ];
|
} // attrs') script;
|
||||||
} // attrs) script;
|
|
||||||
|
|
||||||
# bazel wants to extract itself into $install_dir/install every time it runs,
|
# bazel wants to extract itself into $install_dir/install every time it runs,
|
||||||
# so let’s do that only once.
|
# so let’s do that only once.
|
||||||
@ -173,10 +177,10 @@ stdenv.mkDerivation rec {
|
|||||||
cp -R ${install_dir} $out
|
cp -R ${install_dir} $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
bazelTest = { name, bazelScript, workspaceDir, bazelPkg }:
|
bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
|
||||||
let
|
let
|
||||||
be = extracted bazelPkg;
|
be = extracted bazelPkg;
|
||||||
in runLocal name {} (
|
in runLocal name { inherit buildInputs; } (
|
||||||
# skip extraction caching on Darwin, because nobody knows how Darwin works
|
# skip extraction caching on Darwin, because nobody knows how Darwin works
|
||||||
(lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
|
(lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
|
||||||
# set up home with pre-unpacked bazel
|
# set up home with pre-unpacked bazel
|
||||||
@ -214,11 +218,13 @@ stdenv.mkDerivation rec {
|
|||||||
in {
|
in {
|
||||||
bashTools = 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; };
|
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; };
|
protobuf = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; };
|
||||||
pythonBinPath = callPackage ./python-bin-path-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; };
|
bashToolsWithNixHacks = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
|
||||||
cppWithNixHacks = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples; 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; };
|
protobufWithNixHacks = callPackage ./protobuf-test.nix { inherit runLocal bazelTest; bazel = bazelWithNixHacks; };
|
||||||
pythonBinPathWithNixHacks = callPackage ./python-bin-path-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;
|
__darwinAllowLocalNetworking = true;
|
||||||
|
|
||||||
# Bazel expects several utils to be available in Bash even without PATH. Hence this hack.
|
# Bazel expects several utils to be available in Bash even without PATH. Hence this hack.
|
||||||
|
|
||||||
customBash = writeCBin "bash" ''
|
customBash = writeCBin "bash" ''
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
56
pkgs/development/tools/build-managers/bazel/java-test.nix
Normal file
56
pkgs/development/tools/build-managers/bazel/java-test.nix
Normal file
@ -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
|
||||||
|
|
@ -5,6 +5,7 @@
|
|||||||
, fetchurl
|
, fetchurl
|
||||||
, gccStdenv
|
, gccStdenv
|
||||||
, lib
|
, lib
|
||||||
|
, openjdk8
|
||||||
, runLocal
|
, runLocal
|
||||||
, runtimeShell
|
, runtimeShell
|
||||||
, writeScript
|
, writeScript
|
||||||
@ -77,6 +78,8 @@ let
|
|||||||
personProto = writeText "person.proto" ''
|
personProto = writeText "person.proto" ''
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package person;
|
||||||
|
|
||||||
message Person {
|
message Person {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
int32 id = 2;
|
int32 id = 2;
|
||||||
@ -134,10 +137,15 @@ let
|
|||||||
name = "bazel-test-protocol-buffers";
|
name = "bazel-test-protocol-buffers";
|
||||||
inherit workspaceDir;
|
inherit workspaceDir;
|
||||||
bazelPkg = bazel;
|
bazelPkg = bazel;
|
||||||
|
buildInputs = [ openjdk8 ];
|
||||||
bazelScript = ''
|
bazelScript = ''
|
||||||
${bazel}/bin/bazel \
|
${bazel}/bin/bazel \
|
||||||
build --verbose_failures \
|
build \
|
||||||
//person:person_proto
|
--host_javabase='@local_jdk//:jdk' \
|
||||||
|
--java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
|
||||||
|
--javabase='@local_jdk//:jdk' \
|
||||||
|
--verbose_failures \
|
||||||
|
//...
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user