diff --git a/thirdparty/lua-cjson/HPKBUILD b/thirdparty/lua-cjson/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..570454d6df27fc5e53e0aad86919c31ad72163df --- /dev/null +++ b/thirdparty/lua-cjson/HPKBUILD @@ -0,0 +1,92 @@ +# Copyright (c) 2024 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: xuxingguo <554249301@qq.com> +# Maintainer: xuxingguo <554249301@qq.com> + +pkgname=lua-cjson +pkgver=2.1.0 +pkgrel=0 +pkgdesc="The Lua CJSON module provides JSON support for Lua." +url="https://github.com/mpx/lua-cjson" +archs=("armeabi-v7a" "arm64-v8a") +license=("MIT License") +depends=(lua) +makedepends=() +source="https://github.com/mpx/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +downloadpackage=true +autounpack=true +buildtools="make" + +builddir=$pkgname-${pkgver} +packagename=$builddir.tar.gz + +source envset.sh + +prepare() { + cp -rf $builddir $builddir-$ARCH-build/ + if [ $ARCH == "armeabi-v7a" ];then + setarm32ENV + elif [ $ARCH == "arm64-v8a" ];then + setarm64ENV + else + echo "$ARCH not support" + return -1 + fi +} + +build() { + $MAKE PREFIX=$LYCIUM_ROOT/usr/lua/$ARCH -j4 -C $builddir-$ARCH-build VERBOSE=1 > \ + $builddir-$ARCH-build/$build.log 2>&1 + ret=$? + return $ret +} + +package() { + # Makefile 没有提供install,只能copy + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/include + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib + + find ./$builddir-$ARCH-build -name '*.so' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ \; + find ./$builddir-$ARCH-build -name '*.h' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/include/ \; + find ./ -name 'lua' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ \; + find ./ -name 'tests' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ \; + + # lua-5.4.6版本全局的unpack函数已经被移除了,改为table.unpack + sed -i '192s/unpack/table.unpack/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/lua/cjson/util.lua + sed -i '222s/unpack/table.unpack/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/lua/cjson/util.lua + sed -i '229s/unpack/table.unpack/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/lua/cjson/util.lua + sed -i '231s/unpack/table.unpack/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/lua/cjson/util.lua + + # lua-5.4.6版本已修复pcall模块导致的输出'?'问题,测试用例需要同步修改 + sed -i '362s/?/cjson.encode_number_precision/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '365s/?/cjson.encode_number_precision/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '368s/?/cjson.encode_keep_buffer/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '371s/?/cjson.encode_max_depth/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '374s/?/cjson.decode_max_depth/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '377s/?/cjson.encode_invalid_numbers/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '380s/?/cjson.decode_invalid_numbers/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '383s/?/cjson.encode_sparse_array/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua + sed -i '396s/?/cjson.safe.encode/g' ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua +} + +check() { + echo "The test must be on an OpenHarmony device!" +} + +# 清理环境 +cleanbuild(){ + rm -rf $builddir-armeabi-v7a-build $builddir-arm64-v8a-build + rm -rf $builddir # $packagename +} diff --git a/thirdparty/lua-cjson/HPKCHECK b/thirdparty/lua-cjson/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..3daad1b6b4eb8b969add48f844975e454f582733 --- /dev/null +++ b/thirdparty/lua-cjson/HPKCHECK @@ -0,0 +1,42 @@ +# Copyright (c) 2024 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: xuxingguo <554249301@qq.com> +# Maintainer: xuxingguo <554249301@qq.com> + +source HPKBUILD > /dev/null 2>&1 # 导入HPKBUILD文件 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +# 在OH环境执行测试的接口 +openharmonycheck() { + res=0 + cd ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib + + # 使用lua-5.4.6完成测试 + mkdir -p /usr/local/lib/lua/5.4/cjson + cp ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/lua/cjson/util.lua /usr/local/lib/lua/5.4/cjson/ + cp ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/*.so /usr/local/lib/lua/5.4/ + cp ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/octets-escaped.dat . + + # Decode all UTF-16 escapes测试项需要utf8.dat,该文件是通过genutf8.pl脚本生成的,如果不支持Perl脚本则需要手动上传资源文件 + ${LYCIUM_ROOT}/../lycium/usr/lua-cjson/${ARCH}/ib/tests/genutf8.pl + cp ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/utf8.dat . + + ${LYCIUM_ROOT}/../lycium/usr/lua/${ARCH}/bin/lua ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/tests/test.lua > ${logfile} 2>&1 + res=$? + rm -rf /usr/local/lib + rm -rf octets-escaped.dat + rm -rf utf8.dat + cd $OLDPWD + return $ress +} diff --git a/thirdparty/lua-cjson/OAT.xml b/thirdparty/lua-cjson/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..eeb1f946d683c0b81976cd06522096062a6901b9 --- /dev/null +++ b/thirdparty/lua-cjson/OAT.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/thirdparty/lua-cjson/README.OpenSource b/thirdparty/lua-cjson/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..b6e6e35870a1cc89f000da40aa7ebf36e7f16103 --- /dev/null +++ b/thirdparty/lua-cjson/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "lua-cjson", + "License": "MIT license", + "License File": "LICENSE", + "Version Number": "v2.1.0", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://github.com/mpx/lua-cjson", + "Description": "Lua CJSON is a fast JSON encoding/parsing module for Lua." + } +] \ No newline at end of file diff --git a/thirdparty/lua-cjson/README_zh.md b/thirdparty/lua-cjson/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..98dab113a42c10074c5754689daf031c1857370e --- /dev/null +++ b/thirdparty/lua-cjson/README_zh.md @@ -0,0 +1,11 @@ +# lua-cjson三方库说明 +## 功能简介 +lua-cjson用于完成Lua值与Json值的相互转换(编码及解码) +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:v2.1.0 +- 当前适配的功能:支持Lua值与Json值的相互转换,lua-cjson要求编码格式为UTF8,不支持UTF-16和UTF-32 + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/lua-cjson/SHA512SUM b/thirdparty/lua-cjson/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..d978ace47712493dcf963e41832f608eb7f04e95 --- /dev/null +++ b/thirdparty/lua-cjson/SHA512SUM @@ -0,0 +1 @@ +e420fc26992c4fe92fcd3a973d5af7f9f24e5b4ee3141c8a208c0e11749a6bafc5329636d8059688aa014d42a1898930cb7d5d170dc428f493622b24a17b5cd6 lua-cjson-2.1.0.tar.gz diff --git a/thirdparty/lua-cjson/docs/hap_integrate.md b/thirdparty/lua-cjson/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..31c5d0a61cbc1c5eafa3a7f3f9143382e887d983 --- /dev/null +++ b/thirdparty/lua-cjson/docs/hap_integrate.md @@ -0,0 +1,79 @@ +# lua-cjson 集成到应用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/lua-cjson #三方库lua-cjson的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md #三方库简介 + ``` + +- 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh lua-cjson + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + lua-cjson/arm64-v8a lua-cjson/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的头文件拷贝到该目录下,将编译生成的三方库拷贝到工程的libs目录下,如下图所示: +   + +  ![thirdparty_install_dir](pic/lua-cjson_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```shell + #将三方库加入工程中 + target_link_libraries(entry PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/cjson.so) + #将三方库的头文件加入工程中 + target_include_directories(entry PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/lua-cjson/include) + ``` + +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试 + +进入到构建目录执行(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) +```shell + ../../../lua/${ARCH}/bin/lua tests/tests.lua #执行测试用例 +``` + ![lua-cjson_test](pic/lua-cjson_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) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) \ No newline at end of file diff --git a/thirdparty/lua-cjson/docs/pic/lua-cjson_install_dir.png b/thirdparty/lua-cjson/docs/pic/lua-cjson_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..0e3d855f1951f2dd4d1f90abe7d3a334b72ea84e Binary files /dev/null and b/thirdparty/lua-cjson/docs/pic/lua-cjson_install_dir.png differ diff --git a/thirdparty/lua-cjson/docs/pic/lua_cjson_test.png b/thirdparty/lua-cjson/docs/pic/lua_cjson_test.png new file mode 100644 index 0000000000000000000000000000000000000000..9a8f99bbac7d94a39d0076f73a28b39d431de34b Binary files /dev/null and b/thirdparty/lua-cjson/docs/pic/lua_cjson_test.png differ