From d5056156e645a9dafa9af6ca4f862ec31d93446b Mon Sep 17 00:00:00 2001 From: Emily Date: Mon, 19 Jun 2023 08:32:48 +0100 Subject: [PATCH 1/4] bear: fix The previous build system patch was incomplete and left the `wrapper.d` directory empty, leaving Bear unable to pick up any build commands at all and breaking the functional test suite, which we also weren't running. Switch to overriding CMake flags instead and add the patches and dependencies necessary to get the functional tests running to prevent a future regression. I've checked that the instructions in Nix's `doc/manual/src/contributing/hacking.md` work after this change, which is what started this yak shave in the first place. (cherry picked from commit ec4de10162ba6d3d649c5b83440f4c535fd060b9) --- .../tools/build-managers/bear/default.nix | 34 +++++++++++++++++-- .../bear/fix-functional-tests.patch | 32 +++++++++++++++++ .../bear/no-double-relative.patch | 27 --------------- 3 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 pkgs/development/tools/build-managers/bear/fix-functional-tests.patch delete mode 100644 pkgs/development/tools/build-managers/bear/no-double-relative.patch diff --git a/pkgs/development/tools/build-managers/bear/default.nix b/pkgs/development/tools/build-managers/bear/default.nix index 880184880db11ab..949225aeb226c81 100644 --- a/pkgs/development/tools/build-managers/bear/default.nix +++ b/pkgs/development/tools/build-managers/bear/default.nix @@ -13,6 +13,9 @@ , zlib , sqlite , re2 +, lit +, python3 +, coreutils }: stdenv.mkDerivation rec { @@ -26,7 +29,14 @@ stdenv.mkDerivation rec { hash = "sha256-1nZPzgLWcmaRkOUXdm16IW2Nw/p1w8GBGEfZX/v+En0="; }; - nativeBuildInputs = [ cmake pkg-config ]; + nativeBuildInputs = [ + cmake + pkg-config + + # Used for functional tests, which run during buildPhase. + lit + python3 + ]; buildInputs = [ grpc @@ -41,11 +51,29 @@ stdenv.mkDerivation rec { re2 ]; + cmakeFlags = [ + # Build system and generated files concatenate install prefix and + # CMAKE_INSTALL_{BIN,LIB}DIR, which breaks if these are absolute paths. + "-DCMAKE_INSTALL_BINDIR=bin" + "-DCMAKE_INSTALL_LIBDIR=lib" + ]; + patches = [ - # Default libexec would be set to /nix/store/*-bear//nix/store/*-bear/libexec/... - ./no-double-relative.patch + # Fix toolchain environment variable handling and the Darwin SIP check. + ./fix-functional-tests.patch ]; + postPatch = '' + patchShebangs test/bin + + # /usr/bin/env is used in test commands and embedded scripts. + find test -name '*.sh' \ + -exec sed -ie 's|/usr/bin/env|${coreutils}/bin/env|g' {} + + ''; + + # Functional tests use loopback networking. + __darwinAllowLocalNetworking = true; + meta = with lib; { broken = stdenv.isDarwin; description = "Tool that generates a compilation database for clang tooling"; diff --git a/pkgs/development/tools/build-managers/bear/fix-functional-tests.patch b/pkgs/development/tools/build-managers/bear/fix-functional-tests.patch new file mode 100644 index 000000000000000..99d64f26d077ebf --- /dev/null +++ b/pkgs/development/tools/build-managers/bear/fix-functional-tests.patch @@ -0,0 +1,32 @@ +diff --git a/test/lit.cfg b/test/lit.cfg +index 118c979..b69fecc 100644 +--- a/test/lit.cfg ++++ b/test/lit.cfg +@@ -207,13 +207,8 @@ def is_preload_disabled(): + if is_windows: + return True + elif sys.platform == 'darwin': +- command = ['csrutil', 'status'] +- pattern = re.compile(r'System Integrity Protection status:\s+enabled') +- try: +- output = subprocess.check_output(command, stderr=subprocess.STDOUT) +- return any(pattern.match(line) for line in output.decode('utf-8').splitlines()) +- except (OSError, subprocess.CalledProcessError): +- return False ++ # csrutil(8) isn't available in the Nix build sandbox. ++ return True + else: + return False + +@@ -221,6 +216,11 @@ def is_preload_disabled(): + if not is_preload_disabled(): + config.available_features.add('preload') + ++# Preserve the variables required for the Nix toolchain wrappers. ++for var, value in os.environ.items(): ++ if var.startswith('NIX_'): ++ config.environment[var] = value ++ + print(config.substitutions) + print(config.environment) + print(config.available_features) diff --git a/pkgs/development/tools/build-managers/bear/no-double-relative.patch b/pkgs/development/tools/build-managers/bear/no-double-relative.patch deleted file mode 100644 index e8087feb1afb2b8..000000000000000 --- a/pkgs/development/tools/build-managers/bear/no-double-relative.patch +++ /dev/null @@ -1,27 +0,0 @@ -diff --git a/source/config.h.in b/source/config.h.in -index 6b659c2..f7bdf22 100644 ---- a/source/config.h.in -+++ b/source/config.h.in -@@ -108,8 +108,8 @@ namespace cmd { - } - - namespace wrapper { -- constexpr char DEFAULT_PATH[] = "@ROOT_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/bear/wrapper"; -- constexpr char DEFAULT_DIR_PATH[] = "@ROOT_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/bear/wrapper.d"; -+ constexpr char DEFAULT_PATH[] = "@CMAKE_INSTALL_LIBDIR@/bear/wrapper"; -+ constexpr char DEFAULT_DIR_PATH[] = "@CMAKE_INSTALL_LIBDIR@/bear/wrapper.d"; - - constexpr char FLAG_VERBOSE[] = "--verbose"; - constexpr char FLAG_DESTINATION[] = "--destination"; -@@ -134,9 +134,9 @@ namespace cmd { - // And use the `libexec.so` path default value with a single path, - // that matches both. (The match can be achieved by the $LIB token - // expansion from the dynamic loader. See `man ld.so` for more.) -- constexpr char DEFAULT_PATH[] = "@ROOT_INSTALL_PREFIX@/$LIB/bear/@CMAKE_SHARED_LIBRARY_PREFIX@exec@CMAKE_SHARED_LIBRARY_SUFFIX@"; -+ constexpr char DEFAULT_PATH[] = "$LIB/bear/@CMAKE_SHARED_LIBRARY_PREFIX@exec@CMAKE_SHARED_LIBRARY_SUFFIX@"; - #else -- constexpr char DEFAULT_PATH[] = "@ROOT_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/bear/@CMAKE_SHARED_LIBRARY_PREFIX@exec@CMAKE_SHARED_LIBRARY_SUFFIX@"; -+ constexpr char DEFAULT_PATH[] = "@CMAKE_INSTALL_LIBDIR@/bear/@CMAKE_SHARED_LIBRARY_PREFIX@exec@CMAKE_SHARED_LIBRARY_SUFFIX@"; - #endif - constexpr char KEY_REPORTER[] = "INTERCEPT_REPORT_COMMAND"; - constexpr char KEY_DESTINATION[] = "INTERCEPT_REPORT_DESTINATION"; From d185b17483804c421ff25a9674ae65db4d06427f Mon Sep 17 00:00:00 2001 From: Emily Date: Mon, 19 Jun 2023 09:27:54 +0100 Subject: [PATCH 2/4] bear: use ninja (cherry picked from commit 3637fa5b79a6b55d0bdcdda101d00411aa16f804) --- pkgs/development/tools/build-managers/bear/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/tools/build-managers/bear/default.nix b/pkgs/development/tools/build-managers/bear/default.nix index 949225aeb226c81..a79520e8fd56f52 100644 --- a/pkgs/development/tools/build-managers/bear/default.nix +++ b/pkgs/development/tools/build-managers/bear/default.nix @@ -2,6 +2,7 @@ , fetchFromGitHub , fetchpatch , cmake +, ninja , pkg-config , grpc , protobuf @@ -31,6 +32,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake + ninja pkg-config # Used for functional tests, which run during buildPhase. From b7fbcb1091cb3e103174ea68bae13292c0f8ef22 Mon Sep 17 00:00:00 2001 From: Justin Restivo Date: Fri, 5 Jan 2024 18:33:55 -0500 Subject: [PATCH 3/4] bear: remove broken on darwin (cherry picked from commit 75a177b813627615b4fb98296bacbc5ebdaaac33) --- pkgs/development/tools/build-managers/bear/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/development/tools/build-managers/bear/default.nix b/pkgs/development/tools/build-managers/bear/default.nix index a79520e8fd56f52..6c22a0c5dd2a2e2 100644 --- a/pkgs/development/tools/build-managers/bear/default.nix +++ b/pkgs/development/tools/build-managers/bear/default.nix @@ -77,7 +77,6 @@ stdenv.mkDerivation rec { __darwinAllowLocalNetworking = true; meta = with lib; { - broken = stdenv.isDarwin; description = "Tool that generates a compilation database for clang tooling"; longDescription = '' Note: the bear command is very useful to generate compilation commands From a351df16c79d761f238ba7ebcd21d582c3a2267c Mon Sep 17 00:00:00 2001 From: Justin Restivo Date: Thu, 11 Jan 2024 11:24:35 -0500 Subject: [PATCH 4/4] bear: disable tests (cherry picked from commit 459e2889615da6fc03b9869b611bfd4777cae28e) --- pkgs/development/tools/build-managers/bear/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/tools/build-managers/bear/default.nix b/pkgs/development/tools/build-managers/bear/default.nix index 6c22a0c5dd2a2e2..2789d3cefaffe71 100644 --- a/pkgs/development/tools/build-managers/bear/default.nix +++ b/pkgs/development/tools/build-managers/bear/default.nix @@ -58,6 +58,8 @@ stdenv.mkDerivation rec { # CMAKE_INSTALL_{BIN,LIB}DIR, which breaks if these are absolute paths. "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_LIBDIR=lib" + (lib.cmakeBool "ENABLE_UNIT_TESTS" false) + (lib.cmakeBool "ENABLE_FUNC_TESTS" false) ]; patches = [