同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
The following shows how to port the yxml library.
Acquire the source code of yxml from https://github.com/getdnsapi/yxml. The following table lists the directory structure.
Table 1 Directory structure of the source code
The following steps show how to configure and modify the toolchains for cross-compiling the libraries built using CMake to compile executable files for the OpenHarmony platform.
Configure the toolchains.
Replace the original configuration of MakeFile (listed in Table 1) in the root directory of the yxml library with the following clang toolchains configuration.
clang toolchains configuration:
# Set the cross-compilation toolchain and ensure that the path of the toolchain has been added to the PATH environment variable.
CC:=clang
AR:=llvm-ar
# The --target and --sysroot flags must be specified.
CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g --target=arm-liteos -march=armv7-a --sysroot=$(OHOS_ROOT_PATH)prebuilts/lite/sysroot
Original configuration:
CC:=gcc
AR:=ar
CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g
Perform the compilation.
Run a Linux command to enter the directory (listed in Table 1) for storing yxml source files and then run the following command:
make test OHOS_SYSROOT_PATH=...
OHOS_SYSROOT_PATH specifies the absolute path of the directory where sysroot is located. Taking OpenHarmony for example, set OHOS_SYSROOT_PATH to the absolute path of prebuilts/lite/sysroot/.
View the result.
After step 2 is complete, a static library file and test case are generated in the out directory of the yxml library.
Table 2 Directory structure of compiled files
The test procedure for the yxml library is similar to that for the double-conversion library. For details, see Library Test. The following describes how to use the test cases of the yxml library.
Table 3 Directory structure of the test directory
Automatic test script, which cannot be used because OpenHarmony does not support automatic script execution. However, you can refer to this script to conduct a manual test. |
|
The content of the test.sh file is as follows:
#!/bin/sh
for i in *.xml; do
b=`basename $i .xml`
o=${b}.out
t=${b}.test
./test <$i >$t
if [ -n "`diff -q $o $t`" ]; then
echo "Test failed for $i:"
diff -u $o $t
exit 1
fi
done
echo "All tests completed successfully."
The shell of OpenHarmony does not support input and output redirection symbols (< and >). During the test, you need to copy the content in the *.xml file to the shell and press Enter. The output content is displayed in the shell screen.
The following operations are performed based on the assumption that the OpenHarmony environment has been set up and the nfs directory has been mounted and accessed.
Execute the following command:
./test
Copy the content in the *.xml file to shell.
Taking the pi01.xml file in the test directory as an example, copy the following content to shell and press Enter:
<?SomePI abc?><a/>
Check whether the output in the shell is the same as that of the *.out file in the test directory.
The output is as follows:
pistart SomePI
picontent abc
piend
elemstart a
elemend
ok
The output is the same as the pi01.out file in the test directory. The test is passed.
The procedure for adding the yxml library is almost the same as that for adding the double-conversion library, except that the implementation of build.gn and config.gni files. For details, see Adding the Compiled double-conversion Library to the OpenHarmony Project.
import("config.gni")
group("yxml") {
if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
deps = [":make"]
}
}
if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
action("make") {
script = "//third_party/yxml/build_thirdparty.py"
outputs = ["$target_out_dir/log_yxml.txt"]
exec_path = rebase_path(rebase_path("./yxml", root_build_dir))
command = "make clean && $MAKE_COMMAND"
args = [
"--path=$exec_path",
"--command=${command}"
]
}
}
TEST_ENABLE = "YES"
if (TEST_ENABLE == "YES") {
MAKE_COMMAND = "make test OHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/"
} else {
MAKE_COMMAND = "make OHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/"
}
Table 4 Directory structure of the ported library
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。