From 59d18301574c9b070ad109948c0b40b198ee10de Mon Sep 17 00:00:00 2001 From: DCHii <13780064348@163.com> Date: Tue, 9 Jul 2024 17:22:26 +0800 Subject: [PATCH] Add build options for specifying Python paths --- README.md | 2 +- build.sh | 12 ++++++++---- build/common.sh | 32 -------------------------------- python/CMakeLists.txt | 9 +++++++-- python/modules/_libkperf/Pmu.py | 1 + 5 files changed, 17 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index ac89a1a..dff65a7 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ bash build.sh python=true 安装后若需要卸载python库, 可以执行下述命令 ```shell -python3 -m pip unistall -y libkperf +python3 -m pip uninstall -y libkperf ``` #### 指令 diff --git a/build.sh b/build.sh index f6eb958..937a117 100644 --- a/build.sh +++ b/build.sh @@ -32,6 +32,7 @@ creat_dir "${BUILD_DIR}" # Specifies the gcc used by all dependencies. export CC=gcc export CXX=g++ +PYTHON_EXE="" if [ -d "${THIRD_PARTY}/local" ];then echo ${THIRD_PARTY}/local "is exist" else @@ -47,12 +48,15 @@ for arg in "$@"; do python=*) PYTHON="${arg#*=}" ;; - installPath=*) + install_path=*) INSTALL_PATH="${arg#*=}" ;; build_type=*) BUILD_TYPE="${arg#*=}" ;; + python_exe=*) + PYTHON_EXE="${arg#*=}" + ;; esac done @@ -86,10 +90,10 @@ function build_elfin() { echo "install log path: $cmake_target_dir" } -build_libprof() +build_libkperf() { cd $BUILD_DIR - cmake -DINCLUDE_TEST=${INCLUDE_TEST} -DPYTHON=${PYTHON} -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. + cmake -DINCLUDE_TEST=${INCLUDE_TEST} -DPYTHON=${PYTHON} -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DPYTHON_KPERF=${PYTHON_EXE} .. make -j ${cpu_core_num} make install echo "build libkperf success" @@ -104,7 +108,7 @@ function build_test() main() { build_elfin - build_libprof + build_libkperf build_test } diff --git a/build/common.sh b/build/common.sh index fd88ba7..9cc16b0 100644 --- a/build/common.sh +++ b/build/common.sh @@ -41,38 +41,6 @@ function build_googletest(){ echo "install log path: $cmake_target_dir" } -function build_sqlite3(){ - local open_source_dir=$1 - local cmake_target_dir=$1/local/sqlite3 - if [ -d "${cmake_target_dir}" ];then - echo ${cmake_target_dir} "is exist" - return - else - echo ${cmake_target_dir} "is not exist" - fi - pushd "$open_source_dir/sqlite_src" - rm -rf sqlite-src-3370200 - unzip sqlite-src-3370200.zip - cd sqlite-src-3370200 - - patch -p1 < ../0001-sqlite-no-malloc-usable-size.patch - patch -p1 < ../0002-remove-fail-testcase-in-no-free-fd-situation.patch - patch -p1 < ../0003-CVE-2022-35737.patch - patch -p1 < ../0004-fix-memory-problem-in-the-rtree-test-suite.patch - patch -p1 < ../0005-fix-integer-overflow-on-gigabyte-string.patch - patch -p1 < ../0006-CVE-2022-46908.patch - patch -p1 < ../backport-CVE-2023-36191.patch - patch -p1 < ../backport-CVE-2023-7104.patch - - bash ./configure --prefix=${cmake_target_dir} --disable-threadsafe --disable-tcl --enable-fts5 --enable-json1 CFLAGS="-O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1 -fstack-protector-all -Wl,-z,relro,-z,now -s -fPIC -ftrapv" LDFLAGS="-pie -s -Wl,-z,relro,-z,now" - make -j ${cpu_core_num} - make install - - popd - rm -rf $open_source_dir/sqlite_src/sqlite-src-3370200 - echo "install sqlite3 path: $cmake_target_dir" -} - function execute_binary() { test_case_dir=("test_perf" "test_symbol") test_case_name=("test_perf" "test_symbol") diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 6782045..12a7af4 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -11,7 +11,12 @@ # Create: 2024-05-16 # Description: libkperf python module project(python_libkperf) -find_package(PythonInterp 3.7 REQUIRED) -find_package(PythonLibs 3.7 REQUIRED) +if(DEFINED PYTHON_KPERF AND NOT PYTHON_KPERF STREQUAL "") + set(PYTHON_EXECUTABLE ${PYTHON_KPERF}) +else() + find_package(PythonInterp 3.7 REQUIRED) + find_package(PythonLibs 3.7 REQUIRED) +endif() +message("PYTHON_EXECUTABLE is ${PYTHON_EXECUTABLE}") add_subdirectory(modules) \ No newline at end of file diff --git a/python/modules/_libkperf/Pmu.py b/python/modules/_libkperf/Pmu.py index 1055547..576ec65 100644 --- a/python/modules/_libkperf/Pmu.py +++ b/python/modules/_libkperf/Pmu.py @@ -844,4 +844,5 @@ __all__ = [ 'PmuRead', 'PmuClose', 'PmuDumpData', + 'CtypesPmuAttr', ] -- Gitee