From bc3cba38457f5e44c00e0c5f5d7acf5936cbfa11 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Thu, 28 Dec 2023 15:00:40 +0100 Subject: [PATCH] bazel_7: Cleanup tests a bit --- .../bazel/bazel_7/java-test.nix | 89 +++++++++++++++++++ .../build-managers/bazel/bazel_7/tests.nix | 12 ++- 2 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix new file mode 100644 index 000000000000..2b231dc52a6e --- /dev/null +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix @@ -0,0 +1,89 @@ +{ bazel +, bazelTest +, bazel-examples +, stdenv +, symlinkJoin +, callPackage +, darwin +, extraBazelArgs ? "" +, lib +, openjdk8 +, jdk11_headless +, runLocal +, runtimeShell +, writeScript +, writeText +, repoCache ? "unused" +, distDir +}: + +let + + localDistDir = callPackage ./bazel-repository-cache.nix { + lockfile = ./cpp-test-MODULE.bazel.lock; + + # Take all the rules_ deps, bazel_ deps and their transitive dependencies, + # but none of the platform-specific binaries, as they are large and useless. + requiredDepNamePredicate = name: + null == builtins.match ".*(macos|osx|linux|win|apple|android|maven).*" name + && null != builtins.match "(platforms|com_google_|protobuf|rules_|bazel_).*" name ; + }; + + mergedDistDir = symlinkJoin { + name = "mergedDistDir"; + paths = [ localDistDir distDir ]; + }; + + toolsBazel = writeScript "bazel" '' + #! ${runtimeShell} + + export CXX='${stdenv.cc}/bin/clang++' + export LD='${darwin.cctools}/bin/ld' + export LIBTOOL='${darwin.cctools}/bin/libtool' + export CC='${stdenv.cc}/bin/clang' + + # 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 {} \; + cp ${./cpp-test-MODULE.bazel} $out/MODULE.bazel + cp ${./cpp-test-MODULE.bazel.lock} $out/MODULE.bazel.lock + '' + + (lib.optionalString stdenv.isDarwin '' + mkdir $out/tools + cp ${toolsBazel} $out/tools/bazel + '')); + + testBazel = bazelTest { + name = "bazel-test-java"; + inherit workspaceDir; + bazelPkg = bazel; + buildInputs = [ (if lib.strings.versionOlder bazel.version "5.0.0" then openjdk8 else jdk11_headless) ]; + bazelScript = '' + ${bazel}/bin/bazel \ + run \ + --announce_rc \ + ${lib.optionalString (lib.strings.versionOlder "5.0.0" bazel.version) + "--toolchain_resolution_debug='@bazel_tools//tools/jdk:(runtime_)?toolchain_type'" + } \ + --distdir=${mergedDistDir} \ + --repository_cache=${mergedDistDir} \ + --verbose_failures \ + --curses=no \ + --strict_java_deps=off \ + //:ProjectRunner \ + '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") '' + --host_javabase='@local_jdk//:jdk' \ + --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ + --javabase='@local_jdk//:jdk' \ + '' + extraBazelArgs; + }; + +in testBazel + diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix index 7aafce0f4619..427ecda09c33 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix @@ -6,15 +6,13 @@ , recurseIntoAttrs , runCommandCC , stdenv -, fetchurl # inputs , Foundation , bazel_self , lr , xe -, bazel-watcher , lockfile -, repoCache +, ... }: let inherit (stdenv.hostPlatform) isDarwin; @@ -133,7 +131,7 @@ let inherit Foundation; inherit bazel; distDir = testsDistDir; - extraBazelArgs = ""; + extraBazelArgs = "--noenable_bzlmod"; repoCache = testsRepoCache; }; in @@ -146,10 +144,10 @@ let }; }) // { bashTools = callBazelTest ../bash-tools-test.nix { }; - cpp = callBazelTest ./cpp-test.nix { }; - java = callBazelTest ../java-test.nix { - extraBazelArgs = "--noenable_bzlmod"; + cpp = callBazelTest ./cpp-test.nix { + extraBazelArgs = ""; }; + java = callBazelTest ./java-test.nix { }; pythonBinPath = callBazelTest ../python-bin-path-test.nix { }; protobuf = callBazelTest ./protobuf-test.nix { }; }