diff --git a/rapidjson/BUILD.gn b/rapidjson/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8ffd0218e5c634d6110cc8bc2ba0bf1f6096c9a0 --- /dev/null +++ b/rapidjson/BUILD.gn @@ -0,0 +1,271 @@ +# Copyright (c) 2021 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. + +import("//build/ohos.gni") + +declare_args() { + enable_rapidjson_test = false +} + +config("rapidjson-config") { + cflags_cc = [ + "-Wno-incompatible-pointer-types", + "-Werror", + "-Wno-strict-prototypes", + "-Wimplicit-function-declaration", + "-fexceptions" + ] + + cflags = [ + "-Wno-incompatible-pointer-types", + "-Werror", + "-Wno-strict-prototypes", + "-Wimplicit-function-declaration", + "-fexceptions" + ] +} + +config("gtest_private_config") { + visibility = [ ":*" ] + include_dirs = [ "./thirdparty/gtest/googletest" ] +} + +config("gtest_config") { + include_dirs = [ "./thirdparty/gtest/googletest/include" ] + if (is_mingw) { + cflags_cc = [ + "-Wno-unused-const-variable", + "-Wno-unused-private-field", + ] + } +} +if(enable_rapidjson_test){ +static_library("rapidjson_gtest") { + public = [ + "googletest/include/gtest/gtest-spi.h", + "googletest/include/gtest/gtest.h", + ] + sources = [ + "./thirdparty/gtest/googletest/include/gtest/gtest-death-test.h", + "./thirdparty/gtest/googletest/include/gtest/gtest-message.h", + "./thirdparty/gtest/googletest/include/gtest/gtest-param-test.h", + "./thirdparty/gtest/googletest/include/gtest/gtest-printers.h", + "./thirdparty/gtest//include/gtest/gtest-test-part.h", + "./thirdparty/gtest/googletest/include/gtest/gtest-typed-test.h", + "./thirdparty/gtest/googletest/include/gtest/gtest_pred_impl.h", + "./thirdparty/gtest/googletest/include/gtest/gtest_prod.h", + "./thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-port.h", + "./thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-printers.h", + "./thirdparty/gtest/googletest/include/gtest/internal/custom/gtest.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-death-test-internal.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-filepath.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-internal.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-port-arch.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-port.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-string.h", + "./thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h", + "./thirdparty/gtest/googletest/src/gtest-all.cc", + "./thirdparty/gtest/googletest/src/gtest-death-test.cc", + "./thirdparty/gtest/googletest/src/gtest-filepath.cc", + "./thirdparty/gtest/googletest/src/gtest-internal-inl.h", + "./thirdparty/gtest/googletest/src/gtest-port.cc", + "./thirdparty/gtest/googletest/src/gtest-printers.cc", + "./thirdparty/gtest/googletest/src/gtest-test-part.cc", + "./thirdparty/gtest/googletest/src/gtest-typed-test.cc", + "./thirdparty/gtest/googletest/src/gtest.cc", + ] + sources -= [ "./thirdparty/gtest/googletest/src/gtest-all.cc" ] + public_configs = [ ":gtest_config" ] + configs += [ ":gtest_private_config" ] + configs -= [ "//build/config/coverage:default_coverage" ] +} +} + +if(enable_rapidjson_test){ +static_library("rapidjson_gtest_main") { + sources = [ "./thirdparty/gtest/googletest/src/gtest_main.cc" ] + public_deps = [ ":rapidjson_gtest" ] + configs -= [ "//build/config/coverage:default_coverage" ] +} +} + +config("gmock_private_config") { + visibility = [ ":*" ] + include_dirs = [ "./thirdparty/gtest/googlemock" ] +} + +config("gmock_config") { + include_dirs = [ "./thirdparty/gtest/googlemock/include" ] + + cflags_cc = [ + # The MOCK_METHODn() macros do not specify "override", which triggers this + # warning in users: "error: 'Method' overrides a member function but is not + # marked 'override' [-Werror,-Winconsistent-missing-override]". Suppress + # these warnings until https://github.com/google/googletest/issues/533 is + # fixed. + "-Wno-inconsistent-missing-override", + ] +} + +if(enable_rapidjson_test){ +static_library("rapidjson_gmock") { + public = [ "./thirdparty/gtest/googlemock/include/gmock/gmock.h" ] + sources = [ + "./thirdparty/gtest/googlemock/include/gmock/gmock-actions.h", + "./thirdparty/gtest/googlemock/include/gmock/gmock-cardinalities.h", + "./thirdparty/gtest/googlemock/include/gmock/gmock-function-mocker.h", + "./thirdparty/gtest/googlemock/include/gmock/gmock-more-actions.h", + "./thirdparty/gtest/googlemock/include/gmock/gmock-more-matchers.h", + "./thirdparty/gtest/googlemock/include/gmock/gmock-nice-strict.h", + "./thirdparty/gtest/googlemock/include/gmock/gmock-spec-builders.h", + "./thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h", + "./thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-port.h", + "./thirdparty/gtest/googlemock/include/gmock/internal/gmock-internal-utils.h", + "./thirdparty/gtest/googlemock/include/gmock/internal/gmock-port.h", + "./thirdparty/gtest/googlemock/include/gmock/internal/gmock-pp.h", + "./thirdparty/gtest/googlemock/src/gmock-all.cc", + "./thirdparty/gtest/googlemock/src/gmock-cardinalities.cc", + "./thirdparty/gtest/googlemock/src/gmock-internal-utils.cc", + "./thirdparty/gtest/googlemock/src/gmock-spec-builders.cc", + "./thirdparty/gtest/googlemock/src/gmock.cc", + ] + sources -= [ "./thirdparty/gtest/googlemock/src/gmock-all.cc" ] + public_configs = [ ":gmock_config" ] + configs += [ ":gmock_private_config" ] + configs -= [ "//build/config/coverage:default_coverage" ] + deps = [ ":rapidjson_gtest" ] +} +} + +if(enable_rapidjson_test){ +static_library("rapidjson_gmock_main") { + sources = [ "./thirdparty/gtest/googlemock/src/gmock_main.cc" ] + public_deps = [ + ":rapidjson_gmock", + ":rapidjson_gtest", + ] + configs -= [ "//build/config/coverage:default_coverage" ] +} +} + +if(enable_rapidjson_test){ +ohos_static_library("namespacetest"){ + sources = ["./test/unittest/namespacetest.cpp"] + include_dirs = [ + "./include", + ".", + "./test", + "./thirdparty/gtest/googletest/include" + ] + + deps = [ + ":rapidjson_gtest", + ":rapidjson_gtest_main", + ] + + configs = [":rapidjson-config"] + part_name = "rapidjson" +} +} + +if(enable_rapidjson_test){ +ohos_static_library("archivertest"){ + sources = ["./example/archiver/archiver.cpp", + "./example/archiver/archivertest.cpp"] + include_dirs = [ + "./include", + "./include/rapidjson", + ] + + deps = [ + ":rapidjson_gtest", + ":rapidjson_gtest_main", + ] + + configs = [":rapidjson-config"] + part_name = "rapidjson" +} +} + + +if(enable_rapidjson_test){ +list = ["capitalize", "condense", "filterkey", "filterkeydom", "jsonx", + "lookaheadparser","messagereader","parsebyparts","pretty", + "prettyauto","schemavalidator","serialize","simpledom", + "simplereader","simplepullreader","simplewriter","sortkeys","tutorial"] + foreach(i, list){ + ohos_executable(i){ + sources = [ + "./example/" + i + "/" + i + ".cpp" + ] + + include_dirs = [ + "./include" + ] + + configs = [":rapidjson-config"] + part_name = "rapidjson" +} +} +} + + +if(enable_rapidjson_test){ +ohos_executable("unittest"){ + sources = [ + "./test/unittest/allocatorstest.cpp", + "./test/unittest/bigintegertest.cpp", + "./test/unittest/clzlltest.cpp", + "./test/unittest/cursorstreamwrappertest.cpp", + "./test/unittest/dtoatest.cpp", + "./test/unittest/writertest.cpp", + "./test/unittest/encodingstest.cpp", + "./test/unittest/filestreamtest.cpp", + "./test/unittest/fwdtest.cpp", + "./test/unittest/istreamwrappertest.cpp", + "./test/unittest/namespacetest.cpp", + "./test/unittest/ostreamwrappertest.cpp", + "./test/unittest/platformtest.cpp", + "./test/unittest/pointertest.cpp", + "./test/unittest/prettywritertest.cpp", + "./test/unittest/readertest.cpp", + "./test/unittest/regextest.cpp", + "./test/unittest/schematest.cpp", + "./test/unittest/simdtest.cpp", + "./test/unittest/strfunctest.cpp", + "./test/unittest/stringbuffertest.cpp", + "./test/unittest/strtodtest.cpp", + "./test/unittest/unittest.cpp", + "./test/unittest/uritest.cpp", + "./test/unittest/valuetest.cpp", + "./test/unittest/documenttest.cpp", + "./test/unittest/encodedstreamtest.cpp" + ] + + include_dirs = [ + "./include", + ".", + "./test", + "./thirdparty/gtest/googletest/include" + ] + + deps = [ + ":rapidjson_gtest", + ":rapidjson_gtest_main" + ] + + configs = [":rapidjson-config"] + part_name = "rapidjson" +} +} diff --git a/rapidjson/README.OpenSource b/rapidjson/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..5f57c7a49df002036fd527133a3a89adadcc874e --- /dev/null +++ b/rapidjson/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "rapidjson", + "License": "MIT license", + "License File": "LICENSE", + "Version Number": "v1.1.0", + "Owner": "Tencent", + "Upstream URL": "https://github.com/Tencent/rapidjson.git", + "Description": "A fast JSON parser/generator for C++ with both SAX/DOM style API" + } +] diff --git a/rapidjson/README_zh.md b/rapidjson/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..8d1ca9cd34338c7f493916b46f6f304777da7320 --- /dev/null +++ b/rapidjson/README_zh.md @@ -0,0 +1,10 @@ +# rapidjson三方库说明 +## 功能简介 +RapidJson是一个跨平台的c++的json的解析器和生成器。 +## 使用约束 +- ROM版本:OpenHarmony-v3.2-Beta1 +- 三方库版本:v1.1.0 +- 当前适配的功能:支持json数据的解析和生成。 +- [MIT license](https://github.com/Tencent/rapidjson/blob/master/license.txt) +## 集成方式 ++ [系统Rom包集成](docs/rom_integrate.md) diff --git a/rapidjson/bundle.json b/rapidjson/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..25df091ccf9b6151fa31b9c736c882f4895e73cc --- /dev/null +++ b/rapidjson/bundle.json @@ -0,0 +1,57 @@ +{ + "name": "@ohos/rapidjson", + "description": "A fast JSON parser/generator for C++ with both SAX/DOM style API", + "version": "v1.1.0", + "license": "MIT license", + "publishAs": "", + "segment": { + "destPath": "third_party/rapidjson" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "rapidjson", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": ["standard"], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": ["//third_party/rapidjson:rapidjson_gtest", + "//third_party/rapidjson:rapidjson_gtest_main", + "//third_party/rapidjson:rapidjson_gmock", + "//third_party/rapidjson:rapidjson_gmock_main", + "//third_party/rapidjson:namespacetest", + "//third_party/rapidjson:archivertest", + "//third_party/rapidjson:capitalize", + "//third_party/rapidjson:condense", + "//third_party/rapidjson:filterkey", + "//third_party/rapidjson:filterkeydom", + "//third_party/rapidjson:jsonx", + "//third_party/rapidjson:lookaheadparser", + "//third_party/rapidjson:messagereader", + "//third_party/rapidjson:parsebyparts", + "//third_party/rapidjson:pretty", + "//third_party/rapidjson:prettyauto", + "//third_party/rapidjson:schemavalidator", + "//third_party/rapidjson:serialize", + "//third_party/rapidjson:simpledom", + "//third_party/rapidjson:simplereader", + "//third_party/rapidjson:simplepullreader", + "//third_party/rapidjson:simplewriter", + "//third_party/rapidjson:sortkeys", + "//third_party/rapidjson:tutorial", + "//third_party/rapidjson:unittest"], + "inner_kits": [], + "test": [] + } + } +} diff --git a/rapidjson/docs/pic/result.png b/rapidjson/docs/pic/result.png new file mode 100644 index 0000000000000000000000000000000000000000..beb5898ab532d621290f844e999d87bd692ff1b9 Binary files /dev/null and b/rapidjson/docs/pic/result.png differ diff --git a/rapidjson/docs/rom_integrate.md b/rapidjson/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..b8fbfba91b22f2316c452bc86f94a27cf9f6b88e --- /dev/null +++ b/rapidjson/docs/rom_integrate.md @@ -0,0 +1,112 @@ +# rapidjson如何集成到系统Rom +## 准备源码工程 +本库是基于OpenHarmony-v3.2-Beta1版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +### 准备系统Rom源码 +系统源码获取请参考:[OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta2/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md) +### 增加构建脚本及配置文件 +- 下载本仓库代码 + ``` + cd ~ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/rapidjson #三方库rapidjson的目录结构如下 + ├── adapted #存放三方库适配需要的代码文件 + ├── docs #存放三方库相关文档的文件夹 + ├── BUILD.gn #构建脚本,支持rom包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将三方库拷贝到OpenHarmony源码的third_party目录下 + ``` + cp ~/tpc_c_cplusplus/rapidjson ~/openharmony/third_party -rf + ``` +### 准备三方库源码 +``` +cd ~/openharmony/third_party/rapidjson #进入三方库目录 +git clone https://github.com/Tencent/rapidjson.git #下载三方库源码 +git git submodule update --init #更新依赖的三方库代码 +``` +## 系统Rom中引入三方库 +准备完三方库代码后,我们需要将三方库加入到编译构建体系中。标准系统编译构建可以参考文档[标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) +我们默认三方库是属于OpenHarmony的thirdparty子系统,如果需要自己定义子系统参考文档[如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +新增需要编译的组件,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件中,新增需要编译的组件,如下代码段所示,在thirdparty子系统下面新增rapidjson组件,由于rapidjson是头文件库,所以并不会生成.a和.so文件,特此说明。 + +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "rapidjson", + "features": [] + } + ] + } + +``` +## 系统Rom中引入三方库测试程序 +如果需要编译测试用例,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件,对应组件的features中打开编译选项,如下 +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "rapidjson", + "features": ["enable_rapidjson_test=true"] + } + ] + } +``` +## 编译工程 +在OpenHarmony源码根目录下 +``` +cd ~/openharmony +``` +- 选择平台 + ``` + hb set #hb set 命令会列出所有可选平台,这里我们选择rk3568 + ``` +- 执行编译 + ``` + hb build --target-cpu arm #编译32位系统 + hb build --target-cpu arm64 #编译64位系统 + ``` +- 生成文件的路径,可执行文件和库文件都在out/rk3568/thirdparty/rapidjson 目录下,同时也打包到了镜像中 +## 运行效果 +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 +- 首先将hdc_std工具编译出来 + 工具编译出来所在路径out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + + ``` + hb set #源码根目录下使用hb set 选择产品ohos-sdk + hb build #然后编译 + ``` +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 +- 将原生库测试需要的所有文件打包成rapidjson.tar,并拷贝到windows下 +- 将文件推送到开发板,在windows命令行进行如下操作 + ``` + hdc_std shell mount -oremount,rw / #修改系统权限为可读写 + hdc_std file send rapidjson.tar / #将文件包推入开发板 + hdc_std shell #进入开发板 + tar xvf rapidjson.tar #解压 + #注意需要将库拷贝到/system/lib 或者/system/lib64目录下 + ``` +- 运行测试程序 + 测试用例非常多,这里演示其中几个用例,如下图 + ![result](pic/result.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) +- [如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +- [标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) \ No newline at end of file