Merge pull request #60844 from thoughtpolice/nixpkgs/bpftrace-update

bpftrace: unstable-2018-10-27 -> 0.9
This commit is contained in:
Austin Seipp 2019-05-03 12:09:57 -05:00 committed by GitHub
commit 89d5bfc2db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 141 deletions

@ -1,32 +0,0 @@
From fc0a5bd2ddb5827c5288ee284c1f2d834d79e432 Mon Sep 17 00:00:00 2001
From: Rodney Lorrimar <dev@rodney.id.au>
Date: Tue, 16 Oct 2018 09:55:59 +1000
Subject: [PATCH 1/3] Don't use ExternalProject for bcc sources
---
CMakeLists.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eae850a..b20fb33 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,6 +31,15 @@ if (OFFLINE_BUILDS)
UPDATE_DISCONNECTED 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target bcc-static
)
+elseif (NIX_BUILDS)
+ include(ExternalProject)
+ ExternalProject_Add(bcc
+ DOWNLOAD_COMMAND rmdir bcc && ln -sf $ENV{bccSrc} bcc
+ STEP_TARGETS build update
+ EXCLUDE_FROM_ALL 1
+ UPDATE_DISCONNECTED 1
+ BUILD_COMMAND ${CMAKE_COMMAND} --build . --target bcc-static
+ )
else()
include(ExternalProject)
ExternalProject_Add(bcc
--
2.17.1

@ -1,57 +1,55 @@
{ stdenv, fetchFromGitHub
, cmake, pkgconfig, flex, bison
, llvmPackages, kernel, linuxHeaders, elfutils, libelf, bcc
, llvmPackages, kernel, elfutils, libelf, bcc
}:
stdenv.mkDerivation rec {
name = "bpftrace-unstable-${version}";
version = "2018-10-27";
name = "bpftrace-${version}";
version = "0.9";
src = fetchFromGitHub {
owner = "iovisor";
repo = "bpftrace";
rev = "c07b54f61fd7b7b49e0a254e746d6f442c5d780d";
sha256 = "1mpcjfyay9akmpqxag2ndwpz1qsdx8ii07jh9fky4w40wi9cipyg";
owner = "iovisor";
repo = "bpftrace";
rev = "refs/tags/v${version}";
sha256 = "1kp6as3i67dnw5v3vc1cj5hmrq6c8pjpg9g38g1qcnc9i6drl1r8";
};
# bpftrace requires an unreleased version of bcc, added to the cmake
# build as an ExternalProject.
# https://github.com/iovisor/bpftrace/issues/184
bccSrc = fetchFromGitHub {
owner = "iovisor";
repo = "bcc";
rev = "afd00154865f3b2da6781cf92cecebaca4853950";
sha256 = "0ad78smrnipr1f377i5rv6ksns7v2vq54g5badbj5ldqs4x0hygd";
};
enableParallelBuilding = true;
buildInputs = [
llvmPackages.llvm llvmPackages.clang-unwrapped kernel
elfutils libelf bccSrc
];
buildInputs = with llvmPackages;
[ llvm clang-unwrapped
kernel elfutils libelf bcc
];
nativeBuildInputs = [ cmake pkgconfig flex bison ]
# libelf is incompatible with elfutils-libelf
++ stdenv.lib.filter (x: x != libelf) kernel.moduleBuildDependencies;
patches = [
./bcc-source.patch
# https://github.com/iovisor/bpftrace/issues/184
./disable-gtests.patch
];
configurePhase = ''
mkdir build
cd build
cmake ../ \
-DKERNEL_HEADERS_DIR=${linuxHeaders} \
-DNIX_BUILDS:BOOL=ON \
-DCMAKE_INSTALL_PREFIX=$out
# patch the source, *then* substitute on @NIX_KERNEL_SRC@ in the result. we could
# also in theory make this an environment variable around bpftrace, but this works
# nicely without wrappers.
patchPhase = ''
patch -p1 < ${./fix-kernel-include-dir.patch}
substituteInPlace ./src/clang_parser.cpp \
--subst-var-by NIX_KERNEL_SRC '${kernel.dev}/lib/modules/${kernel.modDirVersion}'
'';
# tests aren't built, due to gtest shenanigans. see:
#
# https://github.com/iovisor/bpftrace/issues/161#issuecomment-453606728
# https://github.com/iovisor/bpftrace/pull/363
#
cmakeFlags =
[ "-DBUILD_TESTING=FALSE"
"-DLIBBCC_INCLUDE_DIRS=${bcc}/include/bcc"
];
outputs = [ "out" "man" ];
meta = with stdenv.lib; {
description = "High-level tracing language for Linux eBPF";
homepage = https://github.com/iovisor/bpftrace;
license = licenses.asl20;
maintainers = with maintainers; [ rvl ];
homepage = https://github.com/iovisor/bpftrace;
license = licenses.asl20;
maintainers = with maintainers; [ rvl thoughtpolice ];
};
}

@ -1,73 +0,0 @@
From 221eea24674fffb3b657b2bd0c923071b69d48a7 Mon Sep 17 00:00:00 2001
From: Rodney Lorrimar <dev@rodney.id.au>
Date: Tue, 16 Oct 2018 09:56:47 +1000
Subject: [PATCH 2/3] Disable tests
Would prefer to use gtest library in the normal way rather through
ExternalProject.
---
CMakeLists.txt | 4 ++--
tests/CMakeLists.txt | 18 +++++++++++-------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b20fb33..7025d17 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,7 @@ add_compile_options("-Wno-format-security")
#add_compile_options("-Wstrict-overflow=5")
#add_compile_options("-Wdisabled-optimization")
-enable_testing()
+# enable_testing()
if (OFFLINE_BUILDS)
include(ExternalProject)
@@ -79,7 +79,7 @@ include_directories(${CLANG_INCLUDE_DIRS})
add_subdirectory(src/arch)
add_subdirectory(src/ast)
add_subdirectory(src)
-add_subdirectory(tests)
+# add_subdirectory(tests)
add_subdirectory(resources)
add_subdirectory(tools)
add_subdirectory(man)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c283efa..6b5bff0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -45,6 +45,8 @@ if (OFFLINE_BUILDS)
EXCLUDE_FROM_ALL 1
UPDATE_DISCONNECTED 1
)
+elseif (NIX_BUILDS)
+
else()
include(ExternalProject)
ExternalProject_Add(gtest-git
@@ -54,13 +56,15 @@ else()
EXCLUDE_FROM_ALL 1
)
endif()
-add_dependencies(bpftrace_test gtest-git-build)
-ExternalProject_Get_Property(gtest-git source_dir binary_dir)
-target_include_directories(bpftrace_test PUBLIC ${source_dir}/googletest/include)
-target_include_directories(bpftrace_test PUBLIC ${source_dir}/googlemock/include)
-target_link_libraries(bpftrace_test ${binary_dir}/googlemock/gtest/libgtest.a)
-target_link_libraries(bpftrace_test ${binary_dir}/googlemock/gtest/libgtest_main.a)
-target_link_libraries(bpftrace_test ${binary_dir}/googlemock/libgmock.a)
+
+find_library(LIBGTEST "gtest")
+if(LIBGTEST)
+ set(LIBRARY_DEPENDENCIES
+ ${LIBRARY_DEPENDENCIES}
+ ${LIBGTEST}
+ )
+endif()
+
target_link_libraries(bpftrace_test ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME bpftrace_test COMMAND bpftrace_test)
--
2.17.1

@ -0,0 +1,22 @@
commit b6172952c0150d84912fa6f09bab782dd0549f1e
Author: Austin Seipp <aseipp@pobox.com>
Date: Fri May 3 00:47:12 2019 -0500
src: special case nix build directories for clang
Signed-off-by: Austin Seipp <aseipp@pobox.com>
diff --git a/src/clang_parser.cpp b/src/clang_parser.cpp
index b1db8ff..0cfb01f 100644
--- a/src/clang_parser.cpp
+++ b/src/clang_parser.cpp
@@ -140,6 +140,9 @@ static bool is_dir(const std::string& path)
// Both ksrc and kobj are guaranteed to be != "", if at least some trace of kernel sources was found.
static std::tuple<std::string, std::string> get_kernel_dirs(const struct utsname& utsname)
{
+ // NB (aseipp): special case the kernel directory for nix
+ return { "@NIX_KERNEL_SRC@/source", "@NIX_KERNEL_SRC@/build" };
+
#ifdef KERNEL_HEADERS_DIR
return {KERNEL_HEADERS_DIR, KERNEL_HEADERS_DIR};
#endif