Skip to content

Instantly share code, notes, and snippets.

@zombiezen
Created August 26, 2023 17:03
Show Gist options
  • Save zombiezen/07bb2bc32cd065dc00a2adf93012cff5 to your computer and use it in GitHub Desktop.
Save zombiezen/07bb2bc32cd065dc00a2adf93012cff5 to your computer and use it in GitHub Desktop.
Fixed up Bear Nix derivation
{ lib, stdenv
, fetchFromGitHub
, cmake
, ninja
, pkg-config
, grpc
, protobuf
, openssl
, nlohmann_json
, gtest
, spdlog
, c-ares
, zlib
, sqlite
, re2
, lit
, python3
, coreutils
}:
stdenv.mkDerivation rec {
pname = "bear";
version = "3.1.2";
src = fetchFromGitHub {
owner = "rizsotto";
repo = pname;
rev = version;
sha256 = "sha256-x46BS+By5Zj5xeYRD45eXRDCAOqwpkkivVyJPnhkAMc=";
};
nativeBuildInputs = [
cmake
ninja
pkg-config
];
buildInputs = [
grpc
protobuf
openssl
nlohmann_json
spdlog
c-ares
zlib
sqlite
re2
];
checkInputs = [
gtest
lit
python3
];
patches = [
# Fix toolchain environment variable handling and the Darwin SIP check.
./fix-functional-tests.patch
# Don't run the tests in the default build target.
./exclude-test-from-main.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' {} +
'';
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"
];
preConfigure = ''
if [ -z "''${doCheck-}" ]; then
cmakeFlags="-DENABLE_UNIT_TESTS=OFF -DENABLE_FUNC_TESTS=OFF $cmakeFlags"
fi
'';
doCheck = false;
# TODO: These targets don't seem to get defined.
checkTarget = "subprojects/Stamp/BearSource/BearSource-test subprojects/Stamp/BearTest/BearTest-test";
# Functional tests use loopback networking.
__darwinAllowLocalNetworking = true;
meta = with lib; {
description = "Tool that generates a compilation database for clang tooling";
longDescription = ''
Note: the bear command is very useful to generate compilation commands
e.g. for YouCompleteMe. You just enter your development nix-shell
and run `bear make`. It's not perfect, but it gets a long way.
'';
homepage = "https://github.com/rizsotto/Bear";
license = licenses.gpl3Plus;
platforms = platforms.unix;
maintainers = with maintainers; [ babariviere qyliss ];
};
}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 30bdeb5..a657741 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,7 +78,7 @@ ExternalProject_Add(BearSource
-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS}
-DROOT_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
${CMAKE_CACHE_ARGS_EXTRA}
- TEST_BEFORE_INSTALL
+ TEST_EXCLUDE_FROM_MAIN
1
TEST_COMMAND
ctest # or `ctest -T memcheck`
@@ -95,7 +95,7 @@ if (ENABLE_FUNC_TESTS)
-DCMAKE_INSTALL_LIBDIR:PATH=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_BINDIR:PATH=${CMAKE_INSTALL_BINDIR}
-DSTAGED_INSTALL_PREFIX:PATH=${STAGED_INSTALL_PREFIX}
- TEST_BEFORE_INSTALL
+ TEST_EXCLUDE_FROM_MAIN
1
INSTALL_COMMAND
""
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment