diff --git a/thirdparty/g3log/HPKBUILD b/thirdparty/g3log/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..69bbe93af0591a29c26d61cad886969f1265bfb4 --- /dev/null +++ b/thirdparty/g3log/HPKBUILD @@ -0,0 +1,74 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Contributor: wangjialun <2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangyihao<2471389@stu.neu.edu.cn>, wangying +# Maintainer: wangyihao<2471389@stu.neu.edu.cn>, wangjialun<2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangying + +pkgname=g3log +pkgver=1.3 +pkgrel=0 +pkgdesc="G3log is an asynchronous, "crash safe", logger that is easy to use with default logging sinks." +url="https://github.com/KjellKod/g3log/tree/1.3" +archs=("armeabi-v7a" "arm64-v8a") +license=("MIT license") +depends=() +makedepends=() +source="https://github.com/KjellKod/g3log/archive/refs/tags/1.3.zip" + +downloadpackage=true +autounpack=true +buildtools=cmake +patchflag=true + +builddir=g3log-1.3 +packagename=g3log-1.3.zip + +prepare() { + if $patchflag + then + cd $builddir + #解压gtest压缩包到原目录,供激活测试后用;添加测试到ctest + patch -p1 < `pwd`/../g3log-1.3_oh_pkg.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + + mkdir -p $builddir/$ARCH-build +} + +build() { + cd $builddir + ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -DCMAKE_C_FLAGS="-Wno-unused-command-line-argument" \ + -DCMAKE_CXX_FLAGS="-Wno-unused-command-line-argument" -B$ARCH-build -S./ -DADD_G3LOG_UNIT_TEST=ON > $buildlog 2>&1 + $MAKE VERBOSE=1 -C $ARCH-build >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir + $MAKE -C $ARCH-build install >> $buildlog 2>&1 + cd $OLDPWD +} + + +check() { + echo "The test must be on an OpenHarmony device!" +} + + +cleanbuild() { + rm -rf ${PWD}/$builddir +} \ No newline at end of file diff --git a/thirdparty/g3log/HPKCHECK b/thirdparty/g3log/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..4420bd9138381baa068ed2984bf2813668c04971 --- /dev/null +++ b/thirdparty/g3log/HPKCHECK @@ -0,0 +1,34 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Contributor: wangjialun <2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangyihao<2471389@stu.neu.edu.cn> , wangying +# Maintainer: wangyihao<2471389@stu.neu.edu.cn>, wangjialun<2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangying + +source HPKBUILD > /dev/null 2>&1 # 导入HPKBUILD文件 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +# 在OH环境执行测试的接口 +openharmonycheck() { + res=0 + cd ${builddir}/${ARCH}-build # 进入到测试目录 + ctest > $logfile 2>&1 + #批量测试时,有4个测试用例因找不到符号“backtrace”和“backtrace_symbols”而失败。 + #尝试将libexecinfo.so、libunwind.so.8.0.1等可以与backtrace功能兼容的轻量级库部署到开发板并设置环境变量,仍无法解决问题。可能是由于平台本身不支持或限制了完整的堆栈回溯功能。 + res=$? + if [ $res -ne 0 ];then + mkdir ${LYCIUM_FAULT_PATH}/${pkgname} + cp Testing/Temporary/LastTest.log ${LYCIUM_FAULT_PATH}/${pkgname}/ + fi + cd $OLDPWD + return $res +} \ No newline at end of file diff --git a/thirdparty/g3log/README.OpenSource b/thirdparty/g3log/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..6c2989c51d6897c2e79ade6fdf6d319ae4157099 --- /dev/null +++ b/thirdparty/g3log/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "g3log", + "License": " Unlicense license", + "License File": "https://github.com/KjellKod/g3log/blob/master/LICENSE", + "Version Number": "1.3", + "Owner": "2942375747@qq.com", + "Upstream URL": "https://github.com/KjellKod/g3log", + "Description": "G3log is an asynchronous, "crash safe", logger that is easy to use with default logging sinks." + } +] \ No newline at end of file diff --git a/thirdparty/g3log/README_zh.md b/thirdparty/g3log/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..af5705be6d481fd22d9948659cd4a22aeda14f68 --- /dev/null +++ b/thirdparty/g3log/README_zh.md @@ -0,0 +1,9 @@ +# g3log三方库说明 +## 功能简介 +g3log是一个异步日志记录器。 +## 三方库版本: +- 1.3 +## 使用约束: +- [IDE和SDK版本](../../docs/constraint.md) +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) \ No newline at end of file diff --git a/thirdparty/g3log/SHA512SUM b/thirdparty/g3log/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..cbe8f19b5c76e409db5faa3f33c18355085ce850 --- /dev/null +++ b/thirdparty/g3log/SHA512SUM @@ -0,0 +1 @@ +aa01576a0b616060c500438556c00974622f230ef6bb7c3fca1f8ad8ee8fc8e5c4260ebd909029a9726caa0a05dd1a9c766da8a594be078996e3ae789bd93a82 g3log-1.3.zip \ No newline at end of file diff --git a/thirdparty/g3log/docs/hap_integrate.md b/thirdparty/g3log/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..f0e72c5ea1c8e7d6158e5685286e7f79bd4856e1 --- /dev/null +++ b/thirdparty/g3log/docs/hap_integrate.md @@ -0,0 +1,81 @@ +# g3log 集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/g3log-1.3 #三方库g3log的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md #三方库简介 + ├── g3log-1.3_oh_pkg.patch #用于g3log库编译的补丁 + ``` + +- 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh g3log + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + g3log/arm64-v8a g3log/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的头文件和库文件拷贝到该目录下,将编译生成的三方库(动态库名字带版本号和不带版本号的都需要)拷贝到工程的libs目录下,如下图所示: +   + +  ![thirdparty_install_dir](pic/g3log_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/g3log/${OHOS_ARCH}/lib/libg3logger.so) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/g3log/${OHOS_ARCH}/include) + ``` + +## 测试三方库 +- 编译出可执行的文件,使用原库自带的测试用例来做测试 [准备三方库测试环境](../../../lycium/README.md#3ci环境准备) +- 进入到构建目录运行测试用例(注意arm64-v8a为构建64位的目录,armeabi-v7a为构建32位的目录)。 +批量测试时,有4个测试用例因找不到符号“backtrace”和“backtrace_symbols”而失败。尝试将libexecinfo.so、libunwind.so.8.0.1等可以与backtrace功能兼容的轻量级库部署到开发板并设置环境变量,仍无法解决问题。可能是由于平台本身不支持或限制了完整的堆栈回溯功能。 + 执行结果如图所示: + +```shell + cd /data/tpc_c_cplusplus/thirdparty/g3log-1.3/g3log-1.3/arm64-v8a-build + ./ctest +``` + ![g3log_test](pic/g3log_test.png) + +## 参考资料 + +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) \ No newline at end of file diff --git a/thirdparty/g3log/docs/pic/g3log_install_dir.png b/thirdparty/g3log/docs/pic/g3log_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..24c3ec3e86d87823b6d63d093812804388c0f749 Binary files /dev/null and b/thirdparty/g3log/docs/pic/g3log_install_dir.png differ diff --git a/thirdparty/g3log/docs/pic/g3log_test.png b/thirdparty/g3log/docs/pic/g3log_test.png new file mode 100644 index 0000000000000000000000000000000000000000..a36f3cd1846f44ea8d772c8d1b589cf5c4cb354b Binary files /dev/null and b/thirdparty/g3log/docs/pic/g3log_test.png differ diff --git a/thirdparty/g3log/g3log-1.3_oh_pkg.patch b/thirdparty/g3log/g3log-1.3_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..a1fcff49460ec425d0805b952a5fb348c7749c13 --- /dev/null +++ b/thirdparty/g3log/g3log-1.3_oh_pkg.patch @@ -0,0 +1,68 @@ +diff -urN g3log-1.3_old/Build.cmake g3log-1.3/Build.cmake +--- g3log-1.3_old/Build.cmake 2017-03-30 01:25:23.000000000 +0800 ++++ g3log-1.3/Build.cmake 2024-10-09 22:23:32.850081312 +0800 +@@ -36,7 +36,7 @@ + ENDIF() + ELSEIF (APPLE) + set(PLATFORM_LINK_LIBRIES c++abi) +- ELSEIF (NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")) ++ ELSEIF (NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "OHOS")) + set(PLATFORM_LINK_LIBRIES rt c++abi) + ELSE() + set(PLATFORM_LINK_LIBRIES rt) +diff -urN g3log-1.3_old/CMakeLists.txt g3log-1.3/CMakeLists.txt +--- g3log-1.3_old/CMakeLists.txt 2017-03-30 01:25:23.000000000 +0800 ++++ g3log-1.3/CMakeLists.txt 2024-10-09 22:22:21.066197648 +0800 +@@ -45,6 +45,30 @@ + # otherwise just run: "make -j" + # + # ============================================================================ ++#测试需要googletest,以下内容为解压并注册googletest ++get_filename_component(PROJECT_SOURCE_DIR "${CMAKE_SOURCE_DIR}" REALPATH) ++# 设置gtest zip文件的绝对路径 ++set(GTEST_ZIP "${PROJECT_SOURCE_DIR}/3rdParty/gtest/gtest-1.7.0.zip") ++# 检查gtest压缩包是否存在 ++if(EXISTS ${GTEST_ZIP}) ++ message("Found gtest zip file: ${GTEST_ZIP}") ++ # 创建一个目录来解压gtest ++ set(GTEST_DIR "${PROJECT_SOURCE_DIR}/3rdParty/gtest") ++ file(MAKE_DIRECTORY ${GTEST_DIR}) ++ ++ # 解压gtest压缩包 ++ execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${GTEST_ZIP} ++ WORKING_DIRECTORY ${GTEST_DIR} ++ RESULT_VARIABLE UNZIP_RESULT) ++ if(UNZIP_RESULT) ++ message(FATAL_ERROR "Failed to unzip ${GTEST_ZIP}") ++ endif() ++ ++ # 添加gtest子目录 ++ add_subdirectory(${GTEST_DIR}) ++else() ++ message(FATAL_ERROR "gtest zip file not found: ${GTEST_ZIP}") ++endif() + + cmake_minimum_required (VERSION 3.1) + ENABLE_LANGUAGE(CXX) +@@ -112,7 +136,7 @@ + + + +-IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ++IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "OHOS" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + # ========================================================================== + # BETA : package manager for G3Log,. not yet reliable. Use at your own risk + # only tested on Ubuntu and CentOS +diff -urN g3log-1.3_old/test_performance/Performance.cmake g3log-1.3/test_performance/Performance.cmake + +--- g3log-1.3_old/test_unit/Test.cmake 2017-03-30 01:25:23.000000000 +0800 ++++ g3log-1.3/test_unit/Test.cmake 2024-10-09 22:18:16.083246081 +0800 +@@ -64,6 +64,8 @@ + set_target_properties(${test} PROPERTIES COMPILE_FLAGS "-isystem -pthread ") + ENDIF( NOT(MSVC)) + target_link_libraries(${test} g3logger gtest_170_lib) ++ # 添加测试 ++ add_test(NAME ${test} COMMAND ${test}) + ENDFOREACH(test) + + # \ No newline at end of file