diff --git a/en/device-dev/porting/porting-thirdparty-cmake.md b/en/device-dev/porting/porting-thirdparty-cmake.md index a505a85d630b92ab4a53fea2a20897f03a1a6016..162a7ccfde71c0dda881ee1beadaec331c6b262a 100755 --- a/en/device-dev/porting/porting-thirdparty-cmake.md +++ b/en/device-dev/porting/porting-thirdparty-cmake.md @@ -5,9 +5,9 @@ The following shows how to port the double-conversion library. ## Source Code Acquisition -Acquire the source code of double-conversion from [https://github.com/google/double-conversion](https://github.com/google/double-conversion). The following table lists the directory structure. +Acquire the source code of double-conversion from [https://github.com/google/double-conversion](https://github.com/google/double-conversion). The following table lists the directory structure. -**Table 1** Directory structure of the source code +**Table 1** Directory structure of the source code | Directory | Description | | -------- | -------- | @@ -35,7 +35,7 @@ Cross-compile the double-conversion library by modifying the toolchain to genera ### Compilation Reference -The [README.md](https://github.com/google/double-conversion/blob/master/README.md) file in the code repository details the procedures for compiling the double-conversion library using CMake as well as the testing methods. This document focuses on the building, compilation, and testing of the library. If you have any questions during library porting, refer to the **README.md** file. For porting of other third-party libraries that can be independently built with CMake, you can refer to the compilation guides provided by the libraries. +The [README.md](https://github.com/google/double-conversion/blob/master/README.md) file in the code repository details the procedures for compiling the double-conversion library using CMake as well as the testing methods. This document focuses on the building, compilation, and testing of the library. If you have any questions during library porting, refer to the **README.md** file. For porting of other third-party libraries that can be independently built with CMake, you can refer to the compilation guides provided by the libraries. ### Cross-Compilation Settings @@ -79,11 +79,12 @@ The following steps show how to configure and modify the toolchains for cross-co make -j ``` - **OHOS\_SYSROOT\_PATH** specifies the absolute path where **sysroot** is located. For OpenHarmony, set **OHOS\_SYSROOT\_PATH** to the absolute path of the **out/hispark\__xxx_/ipcamera\_hispark\__xxx_/sysroot** directory. This directory is generated after full compilation is complete. Therefore, complete full compilation before porting. + **OHOS\_SYSROOT\_PATH** specifies the absolute path where **sysroot** is located. For OpenHarmony, set **OHOS\_SYSROOT\_PATH** to the absolute path of the **out/hispark\__xxx_/ipcamera\_hispark\__xxx_/sysroot** directory. This directory is generated after full compilation is complete. Therefore, complete full compilation before porting. 3. View the result. - After step 2 is complete, a static library file and test cases are generated in the **build** directory. - + +After step 2 is complete, a static library file and test cases are generated in the **build** directory. + **Table 2** Directory structure of compiled files | Directory | Description | @@ -105,19 +106,19 @@ The following steps show how to configure and modify the toolchains for cross-co 1. Set up the OpenHarmony environment. - Using Hi3516D V300 as an example, compile the OpenHarmony image and burn it to the development board. For details, see [Developing the First Example Program Running on Hi3518](../quick-start/quickstart-lite-steps-hi3516-running.md). + Using Hi3516D V300 as an example, compile the OpenHarmony image and burn it to the development board. For details, see [Developing the First Example Program Running on Hi3518](../quick-start/quickstart-lite-steps-hi3516-running.md). The following screen is displayed after a successful login to the OS. - **Figure 1** Successful startup of OpenHarmony + **Figure 1** Successful startup of OpenHarmony ![](figures/successful-startup-of-openharmony.png "successful-startup-of-openharmony") -2. Mount the **nfs** directory and put the executable file **cctest** into the **test** directory \(listed in [Table 2](#table1452412391911)\) to the **nfs** directory. +2. Mount the **nfs** directory and put the executable file **cctest** into the **test** directory \(listed in [Table 2](#table1452412391911)\) to the **nfs** directory. 3. Perform the test cases. - If the double-conversion library is not cross-compiled, you can execute the test cases by running the **make test** command and obtain the result via CMake. However, this command is not applicable to the library after cross-compilation. This way, you can perform the test cases by executing the generated test case files. + If the double-conversion library is not cross-compiled, you can execute the test cases by running the **make test** command and obtain the result via CMake. However, this command is not applicable to the library after cross-compilation. This way, you can perform the test cases by executing the generated test case files. - - After the **nfs** directory is successfully mounted, run the following command to list all items in the test cases: + - After the **nfs** directory is successfully mounted, run the following command to list all items in the test cases: ``` cd nfs @@ -152,7 +153,7 @@ The following steps show how to configure and modify the toolchains for cross-co ... ``` - - Run the following command to test **test-bignum**: + - Run the following command to test **test-bignum**: ``` @@ -171,9 +172,9 @@ The following steps show how to configure and modify the toolchains for cross-co 1. Copy the double-conversion library to the OpenHarmony project. - Copy this library that can be cross-compiled to the **third\_party** directory of OpenHarmony. To avoid modifying the **BUILD.gn** file in the directory of the third-party library to be ported, add a directory to store adaptation files, including **BUILD.gn**, **build\_thirdparty.py**, and **config.gni**, for converting GN to CMake building. + Copy this library that can be cross-compiled to the **third\_party** directory of OpenHarmony. To avoid modifying the **BUILD.gn** file in the directory of the third-party library to be ported, add a directory to store adaptation files, including **BUILD.gn**, **build\_thirdparty.py**, and **config.gni**, for converting GN to CMake building. - **Table 3** Directory structure of the ported library + **Table 3** Directory structure of the ported library | Directory | Description | | -------- | -------- | @@ -207,15 +208,15 @@ The following steps show how to configure and modify the toolchains for cross-co } ``` - - The newly added **config.gni** file is used to configure the library in the following example implementation. For other third-party libraries that can be independently compiled using CMake, you only need to change the configuration of **CMAKE\_FLAG** when porting them to OpenHarmony. + - The newly added **config.gni** file is used to configure the library in the following example implementation. For other third-party libraries that can be independently compiled using CMake, you only need to change the configuration of **CMAKE\_FLAG** when porting them to OpenHarmony. ``` #CMAKE_FLAG: config compile feature CMAKE_FLAG = "-DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=11" - - #toolchain: follow up-layer, depend on $ohos_build_compiler + + #toolchain: follow up-layer,depend on $ohos_build_compiler if (ohos_build_compiler == "clang") { - CMAKE_TOOLCHAIN_FLAG = "- DOHOS_SYSROOT_PATH=${root_out_dir}sysroot/" + CMAKE_TOOLCHAIN_FLAG = "-DOHOS_SYSROOT_PATH=${root_out_dir}sysroot" } else { CMAKE_TOOLCHAIN_FLAG = "" } @@ -224,54 +225,54 @@ The following steps show how to configure and modify the toolchains for cross-co CMAKE_TOOLS_PATH = "setting CMake tools path..." ``` - - The following shows the implementation of the newly added **build\_thirdparty.py** file. For other third-party libraries that can be independently compiled using CMake, you can port them to OpenHarmony without modifications. + - The following shows the implementation of the newly added **build\_thirdparty.py** file. For other third-party libraries that can be independently compiled using CMake, you can port them to OpenHarmony without modifications. - - ``` - import os - import sys - from subprocess import Popen - import argparse - import shlex - - def cmd_exec(command): - cmd = shlex.split(command) - proc = Popen(cmd) - proc.wait() - ret_code = proc.returncode - if ret_code != 0: - raise Exception("{} failed, return code is {}".format(cmd, ret_code)) - - def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--path', help='Build path.') - parser.add_argument('--command', help='Build command.') - parser.add_argument('--enable', help='enable python.', nargs='*') - args = parser.parse_args() - - if args.enable: - if args.enable[0] == 'false': - return - if args.path: - curr_dir = os.getcwd() - os.chdir(args.path) - if args.command: - if '&&' in args.command: - command = args.command.split('&&') - for data in command: - cmd_exec(data) - else: - cmd_exec(args.command) - os.chdir(curr_dir) - - if __name__ == '__main__': - sys.exit(main()) - ``` + ``` + import os + import sys + from subprocess import Popen + import argparse + import shlex + + def cmd_exec(command): + cmd = shlex.split(command) + proc = Popen(cmd) + proc.wait() + ret_code = proc.returncode + if ret_code != 0: + raise Exception("{} failed, return code is {}".format(cmd, ret_code)) + + def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--path', help='Build path.') + parser.add_argument('--command', help='Build command.') + parser.add_argument('--enable', help='enable python.', nargs='*') + args = parser.parse_args() + + if args.enable: + if args.enable[0] == 'false': + return + + if args.path: + curr_dir = os.getcwd() + os.chdir(args.path) + if args.command: + if '&&' in args.command: + command = args.command.split('&&') + for data in command: + cmd_exec(data) + else: + cmd_exec(args.command) + os.chdir(curr_dir) + + if __name__ == '__main__': + sys.exit(main()) + ``` - Add a configuration item in the configuration file to control compiling of the library. By default, library compilation is disabled. - For example, add the following configuration to the **//build/lite/ohos\_var.gni** file: + For example, add the following configuration to the **//build/lite/ohos\_var.gni** file: ``` declare_args() { @@ -284,7 +285,7 @@ The following steps show how to configure and modify the toolchains for cross-co Execute the following command: ``` -hb build -T //third_party/double-conversion:double-conversion + hb build -T //third_party/double-conversion:double-conversion ``` If the compilation is successful, a static library file and test cases will be generated in the [build](#li15717101715249) directory. diff --git a/en/device-dev/porting/porting-thirdparty-makefile.md b/en/device-dev/porting/porting-thirdparty-makefile.md index 6c64a5ce974c525069df4e710753a0f2c54df594..7e03361cca8141192c10a8950b3d637c4d9b5db5 100644 --- a/en/device-dev/porting/porting-thirdparty-makefile.md +++ b/en/device-dev/porting/porting-thirdparty-makefile.md @@ -1,90 +1,36 @@ -# Porting a Library Built Using Makefile +# Porting a Library Built Using Makefile The following shows how to port the yxml library. -## Source Code Acquisition - -Acquire the source code of yxml from [the open-source repository](https://github.com/getdnsapi/yxml). The following table lists the directory structure. - -**Table 1** Directory structure of the source code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Directory

-

Description

-

yxml/bench/

-

Benchmark-related code

-

yxml/test/

-

Input and output files as well as scripts of the test cases

-

yxml/Makefile

-

File for organizing compilation

-

yxml/.gitattributes

-

-

-

yxml/.gitignore

-

-

-

yxml/COPYING

-

-

-

yxml/yxml.c

-

-

-

yxml/yxml.c.in

-

-

-

yxml/yxml-gen.pl

-

-

-

yxml/yxml.h

-

-

-

yxml/yxml.md

-

-

-

yxml/yxml-states

-

-

-
- -## Cross-Compilation Settings +## Source Code Acquisition + +Acquire the source code of yxml from [the open-source repository](https://github.com/getdnsapi/yxml). The following table lists the directory structure. + +**Table 1** Directory structure of the source code + +| Directory | Description | +| ------------------- | ----------------------------------------------------------- | +| yxml/bench/ | Benchmark-related code | +| yxml/test/ | Input and output files as well as scripts of the test cases | +| yxml/Makefile | File for organizing compilation | +| yxml/.gitattributes | - | +| yxml/.gitignore | - | +| yxml/COPYING | - | +| yxml/yxml.c | - | +| yxml/yxml.c.in | - | +| yxml/yxml-gen.pl | - | +| yxml/yxml.h | - | +| yxml/yxml.md | - | +| yxml/yxml-states | - | + + +## Cross-Compilation Settings 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. 1. Configure the toolchains. - Replace the original configuration of MakeFile \(listed in [Table 1](#table16520154171813)\) in the root directory of the yxml library with the following clang toolchains configuration. + 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: @@ -98,86 +44,52 @@ The following steps show how to configure and modify the toolchains for cross-co Original configuration: - ``` - CC:=gcc - AR:=ar - CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g - ``` + + ``` + CC:=gcc + AR:=ar + CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g + ``` 2. Perform the compilation. - Run a Linux command to enter the directory \(listed in [Table 1](#table16520154171813)\) for storing yxml source files and then run the following command: + 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=... + ``` - ``` - make test OHOS_SYSROOT_PATH=... - ``` - - **OHOS\_SYSROOT\_PATH** specifies the absolute path of the directory where **sysroot** is located. For OpenHarmony, set **OHOS\_SYSROOT\_PATH** to the absolute path of the **out/hispark\__xxx_/ipcamera\_hispark\__xxx_/sysroot** directory. This directory is generated after full compilation is complete. Therefore, complete full compilation before porting. + **OHOS\_SYSROOT\_PATH** specifies the absolute path of the directory where **sysroot** is located. For OpenHarmony, set **OHOS\_SYSROOT\_PATH** to the absolute path of the **out/hispark\__xxx_/ipcamera\_hispark\__xxx_/sysroot** directory. This directory is generated after full compilation is complete. Therefore, complete full compilation before porting. 3. 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 - - - - - - - - - - - - - -

Directory

-

Description

-

openHarmony/third_party/yxml/yxml/out/lib/

-

Static library file

-

openHarmony/third_party/yxml/yxml/out/test/

-

Test cases as well as the input and output files

-
- - -## Library Test - -The test procedure for the yxml library is similar to that for the double-conversion library. For details, see the procedure described in [Porting a Library Built Using CMake](porting-thirdparty-cmake.md#section6686144293611). The following describes how to use the test cases of the yxml library. - -**Table 3** Directory structure of the test directory - - - - - - - - - - - - - - - - - - - -

Directory

-

Description

-

openHarmony/third_party/yxml/yxml/out/test/test.sh

-

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.

-

openHarmony/third_party/yxml/yxml/out/test/test

-

Executable file for testing.

-

openHarmony/third_party/yxml/yxml/out/test/*.xml

-

Input test file.

-

openHarmony/third_party/yxml/yxml/out/test/*.out

-

Expected output file.

-
- -The content of the **test.sh** file is as follows: + 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 + + | Directory | Description | + | ------------------------------------------- | ------------------------------------------------ | + | OpenHarmony/third_party/yxml/yxml/out/lib/ | Static library file. | + | OpenHarmony/third_party/yxml/yxml/out/test/ | Test cases as well as the input and output files. | + + + + + +## Library Test + +The test procedure for the yxml library is similar to that for the double-conversion library. For details, see the procedure described in [Porting a Library Built Using CMake](../porting/porting-thirdparty-cmake.md). The following describes how to use the test cases of the yxml library. + +**Table 3** Directory structure of the test directory + +| Directory | Description | +| -------------------------------------------------- | ------------------------------------------------------------ | +| OpenHarmony/third_party/yxml/yxml/out/test/test.sh | 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. | +| OpenHarmony/third_party/yxml/yxml/out/test/test | Executable file for testing. | +| OpenHarmony/third_party/yxml/yxml/out/test/\*.xml | Input test file. | +| OpenHarmony/third_party/yxml/yxml/out/test/\*.out | Expected output file. | + +The content of the **test.sh** file is as follows: ``` #!/bin/sh @@ -195,9 +107,9 @@ 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 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. +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. 1. Execute the following command: @@ -205,15 +117,15 @@ The following operations are performed based on the assumption that the OpenHarm ./test ``` -2. Copy the content in the **_\*_.xml** file to shell. +2. Copy the content in the **_\*_.xml** file to shell. - Taking the **pi01.xml** file in the [test](#table115941423164318) directory as an example, copy the following content to shell and press **Enter**: + Taking the **pi01.xml** file in the [test](#table115941423164318) directory as an example, copy the following content to shell and press **Enter**: - ``` - - ``` + ``` + + ``` -3. Check whether the output in the shell is the same as that of the **_\*_.out** file in the [test](#table115941423164318) directory. +3. Check whether the output in the shell is the same as that of the **_\*_.out** file in the [test](#table115941423164318) directory. The output is as follows: @@ -226,14 +138,14 @@ The following operations are performed based on the assumption that the OpenHarm ok ``` - The output is the same as the **pi01.out** file in the [test](#table115941423164318) directory. The test is passed. + The output is the same as the **pi01.out** file in the **test** directory listed in Table 3. In this case, the test is passed. -## Adding the Compiled yxml Library to the OpenHarmony Project +## Adding the Compiled yxml Library to the OpenHarmony Project -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 the procedure described in [Porting a Library Built Using CMake](porting-thirdparty-cmake.md#section1651053153715). +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 the procedure described in [Porting a Library Built Using CMake](porting-thirdparty-cmake.md#section1651053153715). -- The implementation of the newly added **BUILD.gn** file in the yxml library is as follows: +- The implementation of the newly added **BUILD.gn** file in the yxml library is as follows: ``` import("config.gni") @@ -270,35 +182,13 @@ if (TEST_ENABLE == "YES") { - The following table lists the directory structure of the OpenHarmony project. -**Table 4** Directory structure of the ported library - - - - - - - - - - - - - - - - - - - -

Directory

-

Description

-

openHarmony/third_party/yxml/BUILD.gn

-

GN file for adding the third-party library to the OpenHarmony project

-

openHarmony/third_party/yxml/build_thirdparty.py

-

Script file for GN to call the shell command to convert compilation from GN to Makefile.

-

openHarmony/third_party/yxml/config.gni

-

Third-party library compilation configuration file, which can be modified to determine whether the test cases will be used during the building

-

openHarmony/third_party/yxml/yxml/

-

Directory of the third-party library to be ported

-
+**Table 4** Directory structure of the ported library + +| Directory | Description | +| ----------------------------------------------- | ------------------------------------------------------------ | +| OpenHarmony/third_party/yxml/BUILD.gn | GN file for adding the third-party library to the OpenHarmony project. | +| OpenHarmony/third_party/yxml/build_thirdparty.py | Script file for GN to call the **shell** command to convert compilation from GN to Makefile. | +| OpenHarmony/third_party/yxml/config.gni | Third-party library compilation configuration file, which can be modified to determine whether the test cases will be used during the building. | +| OpenHarmony/third_party/yxml/yxml/ | Directory of the third-party library to be ported. | +