Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-23.11] bear: fix #291814

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions pkgs/development/tools/build-managers/bear/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, fetchFromGitHub
, fetchpatch
, cmake
, ninja
, pkg-config
, grpc
, protobuf
Expand All @@ -13,6 +14,9 @@
, zlib
, sqlite
, re2
, lit
, python3
, coreutils
}:

stdenv.mkDerivation rec {
Expand All @@ -26,7 +30,15 @@ stdenv.mkDerivation rec {
hash = "sha256-1nZPzgLWcmaRkOUXdm16IW2Nw/p1w8GBGEfZX/v+En0=";
};

nativeBuildInputs = [ cmake pkg-config ];
nativeBuildInputs = [
cmake
ninja
pkg-config

# Used for functional tests, which run during buildPhase.
lit
python3
];

buildInputs = [
grpc
Expand All @@ -41,13 +53,32 @@ 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"
(lib.cmakeBool "ENABLE_UNIT_TESTS" false)
(lib.cmakeBool "ENABLE_FUNC_TESTS" false)
];

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";
longDescription = ''
Note: the bear command is very useful to generate compilation commands
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

This file was deleted.