diff --git a/libzip/BUILD.gn b/libzip/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..934f9cef1dfe8862248211f31aa40cf515dcdaee --- /dev/null +++ b/libzip/BUILD.gn @@ -0,0 +1,522 @@ +# 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_libzip_test = false +} + +config("liblibzip_config") { + include_dirs = [ + "//third_party/libzip/adapted/include", + "//third_party/libzip/adapted/lib", + "//third_party/libzip/libzip/lib", + "//third_party/libzip/libzip/src", + "//third_party/libzip/libzip/examples", + "//third_party/libzip/libzip/regress", + "../zlib", + "../bzip2", + "../zstd", + "../zstd/zstd", + "../zstd/zstd/lib", + "../zstd/zstd/lib/common", + "../zstd/zstd/lib/compress", + "../zstd/zstd/lib/decompress", + "../zstd/zstd/lib/deprecated", + "../zstd/zstd/lib/dictBuilder", + "../zstd/zstd/lib/legacy", + "../xz", + "../xz/xz", + "../xz/adapted", + "../xz/xz/src/liblzma", + "../xz/xz/src/liblzma/api", + "../xz/xz/src/liblzma/lzma", + "../xz/xz/src/liblzma/common", + "../xz/xz/src/liblzma/check", + "../xz/xz/src/liblzma/lz", + "../xz/xz/src/liblzma/rangecoder", + "../xz/xz/src/liblzma/api/lzma", + "../xz/xz/src/liblzma/delta", + "../xz/xz/src/liblzma/simple", + "../xz/xz/src/common", + "../openssl", + "../openssl/crypto", + "../openssl/include", + "../openssl/crypto/modes", + "../openssl/crypto/ec/curve448", + "../openssl/crypto/ec/curve448/arch_32", + ] + + cflags = [ + "-fPIC", + "-fdata-sections", + "-ffunction-sections", + "-funwind-tables", + "-fstack-protector-strong", + "-no-canonical-prefixes", + "-fno-addrsig", + "-Wa", + "-Wformat", + "-Werror=format-security", + "-D__MUSL__", + "-Dzip_EXPORTS", + ] +} + +ohos_shared_library("libzip_shared") { + sources = [ + "//third_party/libzip/adapted/lib/zip_err_str.c", + "//third_party/libzip/libzip/lib/zip_add.c", + "//third_party/libzip/libzip/lib/zip_add_dir.c", + "//third_party/libzip/libzip/lib/zip_add_entry.c", + "//third_party/libzip/libzip/lib/zip_algorithm_bzip2.c", + "//third_party/libzip/libzip/lib/zip_algorithm_deflate.c", + "//third_party/libzip/libzip/lib/zip_algorithm_xz.c", + "//third_party/libzip/libzip/lib/zip_algorithm_zstd.c", + "//third_party/libzip/libzip/lib/zip_buffer.c", + "//third_party/libzip/libzip/lib/zip_close.c", + "//third_party/libzip/libzip/lib/zip_crypto_openssl.c", + "//third_party/libzip/libzip/lib/zip_delete.c", + "//third_party/libzip/libzip/lib/zip_dir_add.c", + "//third_party/libzip/libzip/lib/zip_dirent.c", + "//third_party/libzip/libzip/lib/zip_discard.c", + "//third_party/libzip/libzip/lib/zip_entry.c", + "//third_party/libzip/libzip/lib/zip_error.c", + "//third_party/libzip/libzip/lib/zip_error_clear.c", + "//third_party/libzip/libzip/lib/zip_error_get.c", + "//third_party/libzip/libzip/lib/zip_error_get_sys_type.c", + "//third_party/libzip/libzip/lib/zip_error_strerror.c", + "//third_party/libzip/libzip/lib/zip_error_to_str.c", + "//third_party/libzip/libzip/lib/zip_extra_field.c", + "//third_party/libzip/libzip/lib/zip_extra_field_api.c", + "//third_party/libzip/libzip/lib/zip_fclose.c", + "//third_party/libzip/libzip/lib/zip_fdopen.c", + "//third_party/libzip/libzip/lib/zip_file_add.c", + "//third_party/libzip/libzip/lib/zip_file_error_clear.c", + "//third_party/libzip/libzip/lib/zip_file_error_get.c", + "//third_party/libzip/libzip/lib/zip_file_get_comment.c", + "//third_party/libzip/libzip/lib/zip_file_get_external_attributes.c", + "//third_party/libzip/libzip/lib/zip_file_get_offset.c", + "//third_party/libzip/libzip/lib/zip_file_rename.c", + "//third_party/libzip/libzip/lib/zip_file_replace.c", + "//third_party/libzip/libzip/lib/zip_file_set_comment.c", + "//third_party/libzip/libzip/lib/zip_file_set_encryption.c", + "//third_party/libzip/libzip/lib/zip_file_set_external_attributes.c", + "//third_party/libzip/libzip/lib/zip_file_set_mtime.c", + "//third_party/libzip/libzip/lib/zip_file_strerror.c", + "//third_party/libzip/libzip/lib/zip_fopen.c", + "//third_party/libzip/libzip/lib/zip_fopen_encrypted.c", + "//third_party/libzip/libzip/lib/zip_fopen_index.c", + "//third_party/libzip/libzip/lib/zip_fopen_index_encrypted.c", + "//third_party/libzip/libzip/lib/zip_fread.c", + "//third_party/libzip/libzip/lib/zip_fseek.c", + "//third_party/libzip/libzip/lib/zip_ftell.c", + "//third_party/libzip/libzip/lib/zip_get_archive_comment.c", + "//third_party/libzip/libzip/lib/zip_get_archive_flag.c", + "//third_party/libzip/libzip/lib/zip_get_encryption_implementation.c", + "//third_party/libzip/libzip/lib/zip_get_file_comment.c", + "//third_party/libzip/libzip/lib/zip_get_name.c", + "//third_party/libzip/libzip/lib/zip_get_num_entries.c", + "//third_party/libzip/libzip/lib/zip_get_num_files.c", + "//third_party/libzip/libzip/lib/zip_hash.c", + "//third_party/libzip/libzip/lib/zip_io_util.c", + "//third_party/libzip/libzip/lib/zip_libzip_version.c", + "//third_party/libzip/libzip/lib/zip_memdup.c", + "//third_party/libzip/libzip/lib/zip_name_locate.c", + "//third_party/libzip/libzip/lib/zip_new.c", + "//third_party/libzip/libzip/lib/zip_open.c", + "//third_party/libzip/libzip/lib/zip_pkware.c", + "//third_party/libzip/libzip/lib/zip_progress.c", + "//third_party/libzip/libzip/lib/zip_random_unix.c", + "//third_party/libzip/libzip/lib/zip_rename.c", + "//third_party/libzip/libzip/lib/zip_replace.c", + "//third_party/libzip/libzip/lib/zip_set_archive_comment.c", + "//third_party/libzip/libzip/lib/zip_set_archive_flag.c", + "//third_party/libzip/libzip/lib/zip_set_default_password.c", + "//third_party/libzip/libzip/lib/zip_set_file_comment.c", + "//third_party/libzip/libzip/lib/zip_set_file_compression.c", + "//third_party/libzip/libzip/lib/zip_set_name.c", + "//third_party/libzip/libzip/lib/zip_source_accept_empty.c", + "//third_party/libzip/libzip/lib/zip_source_begin_write.c", + "//third_party/libzip/libzip/lib/zip_source_begin_write_cloning.c", + "//third_party/libzip/libzip/lib/zip_source_buffer.c", + "//third_party/libzip/libzip/lib/zip_source_call.c", + "//third_party/libzip/libzip/lib/zip_source_close.c", + "//third_party/libzip/libzip/lib/zip_source_commit_write.c", + "//third_party/libzip/libzip/lib/zip_source_compress.c", + "//third_party/libzip/libzip/lib/zip_source_crc.c", + "//third_party/libzip/libzip/lib/zip_source_error.c", + "//third_party/libzip/libzip/lib/zip_source_file_common.c", + "//third_party/libzip/libzip/lib/zip_source_file_stdio.c", + "//third_party/libzip/libzip/lib/zip_source_file_stdio_named.c", + "//third_party/libzip/libzip/lib/zip_source_free.c", + "//third_party/libzip/libzip/lib/zip_source_function.c", + "//third_party/libzip/libzip/lib/zip_source_get_file_attributes.c", + "//third_party/libzip/libzip/lib/zip_source_is_deleted.c", + "//third_party/libzip/libzip/lib/zip_source_layered.c", + "//third_party/libzip/libzip/lib/zip_source_open.c", + "//third_party/libzip/libzip/lib/zip_source_pass_to_lower_layer.c", + "//third_party/libzip/libzip/lib/zip_source_pkware_decode.c", + "//third_party/libzip/libzip/lib/zip_source_pkware_encode.c", + "//third_party/libzip/libzip/lib/zip_source_read.c", + "//third_party/libzip/libzip/lib/zip_source_remove.c", + "//third_party/libzip/libzip/lib/zip_source_rollback_write.c", + "//third_party/libzip/libzip/lib/zip_source_seek.c", + "//third_party/libzip/libzip/lib/zip_source_seek_write.c", + "//third_party/libzip/libzip/lib/zip_source_stat.c", + "//third_party/libzip/libzip/lib/zip_source_supports.c", + "//third_party/libzip/libzip/lib/zip_source_tell.c", + "//third_party/libzip/libzip/lib/zip_source_tell_write.c", + "//third_party/libzip/libzip/lib/zip_source_window.c", + "//third_party/libzip/libzip/lib/zip_source_winzip_aes_decode.c", + "//third_party/libzip/libzip/lib/zip_source_winzip_aes_encode.c", + "//third_party/libzip/libzip/lib/zip_source_write.c", + "//third_party/libzip/libzip/lib/zip_source_zip.c", + "//third_party/libzip/libzip/lib/zip_source_zip_new.c", + "//third_party/libzip/libzip/lib/zip_stat.c", + "//third_party/libzip/libzip/lib/zip_stat_index.c", + "//third_party/libzip/libzip/lib/zip_stat_init.c", + "//third_party/libzip/libzip/lib/zip_strerror.c", + "//third_party/libzip/libzip/lib/zip_string.c", + "//third_party/libzip/libzip/lib/zip_unchange.c", + "//third_party/libzip/libzip/lib/zip_unchange_all.c", + "//third_party/libzip/libzip/lib/zip_unchange_archive.c", + "//third_party/libzip/libzip/lib/zip_unchange_data.c", + "//third_party/libzip/libzip/lib/zip_utf-8.c", + "//third_party/libzip/libzip/lib/zip_winzip_aes.c", + ] + + deps = [ + "../bzip2:libbz2", + "../openssl:libcrypto_shared", + "../xz:xz_shared", + "../zlib:shared_libz", + "../zstd:zstd_shared", + ] + + configs = [ ":liblibzip_config" ] + + part_name = "libzip" +} + +config("libzip_config") { + include_dirs = [ + "//third_party/libzip/libzip/src", + "//third_party/libzip/libzip/examples", + "//third_party/libzip/libzip/regress", + "//third_party/libzip//libzip/regress/BEFORE", + "//third_party/libzip/libzip/lib", + "//third_party/libzip/adapted/include", + "//third_party/libzip/adapted/lib", + "../zlib", + "../bzip2", + ] + + cflags_cc = [ + "-Dnonrandomopen_EXPORTS", + "-Dliboverride_EXPORTS", + "-fdata-sections", + "-ffunction-sections", + "-funwind-tables", + "-fstack-protector-strong", + "-no-canonical-prefixes", + "-fno-addrsig", + "-Wa", + "-Wformat", + "-Werror=format-security", + "-D__MUSL__", + "-fPIE", + ] +} + +ohos_shared_library("nonrandomopen") { + sources = [ "//third_party/libzip/libzip/regress/nonrandomopen.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_shared_library("liboverride") { + sources = [ "//third_party/libzip/libzip/regress/liboverride.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("add_from_filep") { + sources = [ "//third_party/libzip/libzip/regress/add_from_filep.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + part_name = "libzip" +} + +ohos_executable("can_clone_file") { + sources = [ "//third_party/libzip/libzip/regress/can_clone_file.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("fopen_unchanged") { + sources = [ "//third_party/libzip/libzip/regress/fopen_unchanged.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("fseek") { + sources = [ "//third_party/libzip/libzip/regress/fseek.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("fuzz_main") { + sources = [ "//third_party/libzip/libzip/regress/fuzz_main.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("nonrandomopentest") { + sources = [ "//third_party/libzip/libzip/regress/nonrandomopentest.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("liboverride-test") { + sources = [ "//third_party/libzip/libzip/regress/liboverride-test.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("fread") { + sources = [ + "//third_party/libzip/libzip/regress/fread.c", + "//third_party/libzip/libzip/src/getopt.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("tryopen") { + sources = [ + "//third_party/libzip/libzip/regress/tryopen.c", + "//third_party/libzip/libzip/src/getopt.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("ziptool_regress") { + sources = [ + "//third_party/libzip/libzip/regress/source_hole.c", + "//third_party/libzip/libzip/regress/ziptool_regress.c", + "//third_party/libzip/libzip/src/getopt.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("hole") { + sources = [ + "//third_party/libzip/libzip/regress/hole.c", + "//third_party/libzip/libzip/regress/source_hole.c", + "//third_party/libzip/libzip/src/getopt.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("add-compressed-data") { + sources = [ "//third_party/libzip/libzip/examples/add-compressed-data.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("autoclose-archive") { + sources = [ "//third_party/libzip/libzip/examples/autoclose-archive.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("in-memory") { + sources = [ "//third_party/libzip/libzip/examples/in-memory.c" ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("zipcmp") { + sources = [ + "//third_party/libzip/libzip/src/diff_output.c", + "//third_party/libzip/libzip/src/getopt.c", + "//third_party/libzip/libzip/src/zipcmp.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ + ":libzip_shared", + "../zlib:shared_libz", + ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("zipmerge") { + sources = [ + "//third_party/libzip/libzip/src/diff_output.c", + "//third_party/libzip/libzip/src/getopt.c", + "//third_party/libzip/libzip/src/zipmerge.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +ohos_executable("ziptool") { + sources = [ + "//third_party/libzip/libzip/src/diff_output.c", + "//third_party/libzip/libzip/src/getopt.c", + "//third_party/libzip/libzip/src/ziptool.c", + ] + + configs = [ ":libzip_config" ] + + deps = [ ":libzip_shared" ] + + defines = [ "PACKAGE_VERSION" ] + + part_name = "libzip" +} + +group("libzip_test") { + if (enable_libzip_test) { + deps = [ + ":add-compressed-data", + ":add_from_filep", + ":autoclose-archive", + ":can_clone_file", + ":fopen_unchanged", + ":fread", + ":fseek", + ":fuzz_main", + ":hole", + ":in-memory", + ":liboverride-test", + ":nonrandomopentest", + ":tryopen", + ":zipcmp", + ":zipmerge", + ":ziptool", + ":ziptool_regress", + ] + } else { + deps = [] + } +} diff --git a/libzip/CMakeLists.txt b/libzip/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2949efe7dd84252f6b4bdde5a9a3bdf028a114c --- /dev/null +++ b/libzip/CMakeLists.txt @@ -0,0 +1,252 @@ +cmake_minimum_required (VERSION 3.12) + +project(LIBZIP VERSION 0.1.0) + +enable_language(C) + +option(ENABLE_OPENSSL "Enable use of OpenSSL" ON) + +option(ENABLE_BZIP2 "Enable use of BZip2" ON) +option(ENABLE_LZMA "Enable use of LZMA" ON) +option(ENABLE_ZSTD "Enable use of Zstandard" ON) + +option(ENABLE_FDOPEN "Enable zip_fdopen, which is not allowed in Microsoft CRT secure libraries" ON) + +option(BUILD_TOOLS "Build tools in the src directory (zipcmp, zipmerge, ziptool)" ON) +option(BUILD_REGRESS "Build regression tests" ON) +option(BUILD_EXAMPLES "Build examples" ON) + +set(TARGET_NAME zip) +set(TARGET_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libzip) +set(TARGET_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/adapted/include) + +set(TARGET_INCLUDE ${TARGET_LIB_PATH}) +set(TARGET_INSTALL_INCLUDEDIR include) +set(TARGET_INSTALL_BINDIR bin) +set(TARGET_INSTALL_LIBDIR lib) + +set(TARGET_LIB ${TARGET_LIB_PATH}/lib/zip_add.c + ${TARGET_LIB_PATH}/lib/zip_add_dir.c + ${TARGET_LIB_PATH}/lib/zip_add_entry.c + ${TARGET_LIB_PATH}/lib/zip_algorithm_deflate.c + ${TARGET_LIB_PATH}/lib/zip_buffer.c + ${TARGET_LIB_PATH}/lib/zip_close.c + ${TARGET_LIB_PATH}/lib/zip_delete.c + ${TARGET_LIB_PATH}/lib/zip_dir_add.c + ${TARGET_LIB_PATH}/lib/zip_dirent.c + ${TARGET_LIB_PATH}/lib/zip_discard.c + ${TARGET_LIB_PATH}/lib/zip_entry.c + ${TARGET_LIB_PATH}/lib/zip_error.c + ${TARGET_LIB_PATH}/lib/zip_error_clear.c + ${TARGET_LIB_PATH}/lib/zip_error_get.c + ${TARGET_LIB_PATH}/lib/zip_error_get_sys_type.c + ${TARGET_LIB_PATH}/lib/zip_error_strerror.c + ${TARGET_LIB_PATH}/lib/zip_error_to_str.c + ${TARGET_LIB_PATH}/lib/zip_extra_field.c + ${TARGET_LIB_PATH}/lib/zip_extra_field_api.c + ${TARGET_LIB_PATH}/lib/zip_fclose.c + ${TARGET_LIB_PATH}/lib/zip_fdopen.c + ${TARGET_LIB_PATH}/lib/zip_file_add.c + ${TARGET_LIB_PATH}/lib/zip_file_error_clear.c + ${TARGET_LIB_PATH}/lib/zip_file_error_get.c + ${TARGET_LIB_PATH}/lib/zip_file_get_comment.c + ${TARGET_LIB_PATH}/lib/zip_file_get_external_attributes.c + ${TARGET_LIB_PATH}/lib/zip_file_get_offset.c + ${TARGET_LIB_PATH}/lib/zip_file_rename.c + ${TARGET_LIB_PATH}/lib/zip_file_replace.c + ${TARGET_LIB_PATH}/lib/zip_file_set_comment.c + ${TARGET_LIB_PATH}/lib/zip_file_set_encryption.c + ${TARGET_LIB_PATH}/lib/zip_file_set_external_attributes.c + ${TARGET_LIB_PATH}/lib/zip_file_set_mtime.c + ${TARGET_LIB_PATH}/lib/zip_file_strerror.c + ${TARGET_LIB_PATH}/lib/zip_fopen.c + ${TARGET_LIB_PATH}/lib/zip_fopen_encrypted.c + ${TARGET_LIB_PATH}/lib/zip_fopen_index.c + ${TARGET_LIB_PATH}/lib/zip_fopen_index_encrypted.c + ${TARGET_LIB_PATH}/lib/zip_fread.c + ${TARGET_LIB_PATH}/lib/zip_fseek.c + ${TARGET_LIB_PATH}/lib/zip_ftell.c + ${TARGET_LIB_PATH}/lib/zip_get_archive_comment.c + ${TARGET_LIB_PATH}/lib/zip_get_archive_flag.c + ${TARGET_LIB_PATH}/lib/zip_get_encryption_implementation.c + ${TARGET_LIB_PATH}/lib/zip_get_file_comment.c + ${TARGET_LIB_PATH}/lib/zip_get_name.c + ${TARGET_LIB_PATH}/lib/zip_get_num_entries.c + ${TARGET_LIB_PATH}/lib/zip_get_num_files.c + ${TARGET_LIB_PATH}/lib/zip_hash.c + ${TARGET_LIB_PATH}/lib/zip_io_util.c + ${TARGET_LIB_PATH}/lib/zip_libzip_version.c + ${TARGET_LIB_PATH}/lib/zip_memdup.c + ${TARGET_LIB_PATH}/lib/zip_name_locate.c + ${TARGET_LIB_PATH}/lib/zip_new.c + ${TARGET_LIB_PATH}/lib/zip_open.c + ${TARGET_LIB_PATH}/lib/zip_pkware.c + ${TARGET_LIB_PATH}/lib/zip_progress.c + ${TARGET_LIB_PATH}/lib/zip_rename.c + ${TARGET_LIB_PATH}/lib/zip_replace.c + ${TARGET_LIB_PATH}/lib/zip_set_archive_comment.c + ${TARGET_LIB_PATH}/lib/zip_set_archive_flag.c + ${TARGET_LIB_PATH}/lib/zip_set_default_password.c + ${TARGET_LIB_PATH}/lib/zip_set_file_comment.c + ${TARGET_LIB_PATH}/lib/zip_set_file_compression.c + ${TARGET_LIB_PATH}/lib/zip_set_name.c + ${TARGET_LIB_PATH}/lib/zip_source_accept_empty.c + ${TARGET_LIB_PATH}/lib/zip_source_begin_write.c + ${TARGET_LIB_PATH}/lib/zip_source_begin_write_cloning.c + ${TARGET_LIB_PATH}/lib/zip_source_buffer.c + ${TARGET_LIB_PATH}/lib/zip_source_call.c + ${TARGET_LIB_PATH}/lib/zip_source_close.c + ${TARGET_LIB_PATH}/lib/zip_source_commit_write.c + ${TARGET_LIB_PATH}/lib/zip_source_compress.c + ${TARGET_LIB_PATH}/lib/zip_source_crc.c + ${TARGET_LIB_PATH}/lib/zip_source_error.c + ${TARGET_LIB_PATH}/lib/zip_source_file_common.c + ${TARGET_LIB_PATH}/lib/zip_source_file_stdio.c + ${TARGET_LIB_PATH}/lib/zip_source_free.c + ${TARGET_LIB_PATH}/lib/zip_source_function.c + ${TARGET_LIB_PATH}/lib/zip_source_get_file_attributes.c + ${TARGET_LIB_PATH}/lib/zip_source_is_deleted.c + ${TARGET_LIB_PATH}/lib/zip_source_layered.c + ${TARGET_LIB_PATH}/lib/zip_source_open.c + ${TARGET_LIB_PATH}/lib/zip_source_pass_to_lower_layer.c + ${TARGET_LIB_PATH}/lib/zip_source_pkware_decode.c + ${TARGET_LIB_PATH}/lib/zip_source_pkware_encode.c + ${TARGET_LIB_PATH}/lib/zip_source_read.c + ${TARGET_LIB_PATH}/lib/zip_source_remove.c + ${TARGET_LIB_PATH}/lib/zip_source_rollback_write.c + ${TARGET_LIB_PATH}/lib/zip_source_seek.c + ${TARGET_LIB_PATH}/lib/zip_source_seek_write.c + ${TARGET_LIB_PATH}/lib/zip_source_stat.c + ${TARGET_LIB_PATH}/lib/zip_source_supports.c + ${TARGET_LIB_PATH}/lib/zip_source_tell.c + ${TARGET_LIB_PATH}/lib/zip_source_tell_write.c + ${TARGET_LIB_PATH}/lib/zip_source_window.c + ${TARGET_LIB_PATH}/lib/zip_source_write.c + ${TARGET_LIB_PATH}/lib/zip_source_zip.c + ${TARGET_LIB_PATH}/lib/zip_source_zip_new.c + ${TARGET_LIB_PATH}/lib/zip_stat.c + ${TARGET_LIB_PATH}/lib/zip_stat_index.c + ${TARGET_LIB_PATH}/lib/zip_stat_init.c + ${TARGET_LIB_PATH}/lib/zip_strerror.c + ${TARGET_LIB_PATH}/lib/zip_string.c + ${TARGET_LIB_PATH}/lib/zip_unchange.c + ${TARGET_LIB_PATH}/lib/zip_unchange_all.c + ${TARGET_LIB_PATH}/lib/zip_unchange_archive.c + ${TARGET_LIB_PATH}/lib/zip_unchange_data.c + ${TARGET_LIB_PATH}/lib/zip_utf-8.c + ${TARGET_LIB_PATH}/lib/zip_source_file_stdio_named.c + ${TARGET_LIB_PATH}/lib/zip_random_unix.c + ${CMAKE_CURRENT_SOURCE_DIR}/adapted/lib/zip_err_str.c) + +set(DEFINES -Dzip_EXPORTS + -fPIC) + +add_library(${TARGET_NAME} ${TARGET_LIB}) + +if(ENABLE_BZIP2) + target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../bzip2) + set(HAVE_LIBBZ2 1) + target_sources(${TARGET_NAME} PRIVATE ${TARGET_LIB_PATH}/lib/zip_algorithm_bzip2.c) + target_link_libraries(${TARGET_NAME} PRIVATE bzip2) +endif() + +if(ENABLE_LZMA) + target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../xz) + set(HAVE_LIBLZMA 1) + target_sources(${TARGET_NAME} PRIVATE ${TARGET_LIB_PATH}/lib/zip_algorithm_xz.c) + target_link_libraries(${TARGET_NAME} PRIVATE liblzma) +endif() + +if(ENABLE_LZMA) + target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../zstd) + set(HAVE_LIBZSTD 1) + target_sources(${TARGET_NAME} PRIVATE ${TARGET_LIB_PATH}/lib/zip_algorithm_zstd.c) + target_link_libraries(${TARGET_NAME} PRIVATE zstd) +endif() + +if(ENABLE_OPENSSL) + target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../openssl + ${CMAKE_CURRENT_SOURCE_DIR}/../openssl/openssl/include + ${CMAKE_CURRENT_SOURCE_DIR}/../openssl/adapted/include) + set(HAVE_CRYPTO 1) + set(HAVE_OPENSSL 1) + target_sources(${TARGET_NAME} PRIVATE ${TARGET_LIB_PATH}/lib/zip_crypto_openssl.c + ${TARGET_LIB_PATH}/lib/zip_winzip_aes.c + ${TARGET_LIB_PATH}/lib/zip_source_winzip_aes_decode.c + ${TARGET_LIB_PATH}/lib/zip_source_winzip_aes_encode.c) + target_link_libraries(${TARGET_NAME} PRIVATE crypto) +endif() + +target_link_libraries(zip PRIVATE z) +target_include_directories(${TARGET_NAME} PUBLIC ${TARGET_INCLUDE_PATH} + ${TARGET_LIB_PATH}/examples + ${TARGET_LIB_PATH}/src + ${TARGET_LIB_PATH}/lib + ${TARGET_LIB_PATH}/regress) +target_compile_options(${TARGET_NAME} PUBLIC ${DEFINES}) + +if(BUILD_REGRESS) +set(TEST_PROGRAMS + add_from_filep + can_clone_file + fopen_unchanged + fseek + fuzz_main + nonrandomopentest + liboverride-test +) + +set(GETOPT_USERS + fread + tryopen +) + +set(HOLE_USERS + hole + ziptool_regress +) +set(ZIP_PROGRAMS ${TEST_PROGRAMS} ${GETOPT_USERS} ${HOLE_USERS}) + +foreach(PROGRAM ${ZIP_PROGRAMS}) + add_executable(${PROGRAM} ${TARGET_LIB_PATH}/regress/${PROGRAM}.c) + target_link_libraries(${PROGRAM} PUBLIC ${TARGET_NAME}) + target_include_directories(${PROGRAM} PRIVATE BEFORE ${TARGET_LIB_PATH}/lib ${PROJECT_BINARY_DIR} ${TARGET_INCLUDE_PATH}) +endforeach() + +foreach(PROGRAM ${GETOPT_USERS} ${HOLE_USERS}) + target_sources(${PROGRAM} PRIVATE ${TARGET_LIB_PATH}/src/getopt.c) + target_include_directories(${PROGRAM} PRIVATE BEFORE ${TARGET_LIB_PATH}/src) +endforeach() +foreach(PROGRAM ${HOLE_USERS}) + target_sources(${PROGRAM} PRIVATE ${TARGET_LIB_PATH}/regress/source_hole.c) +endforeach() +target_include_directories(ziptool_regress PRIVATE BEFORE ${TARGET_LIB_PATH}/src) +set(DL_USERS + nonrandomopen + liboverride +) + +foreach(PROGRAM ${DL_USERS}) + add_library(${PROGRAM} MODULE ${TARGET_LIB_PATH}/regress/${PROGRAM}.c) + target_include_directories(${PROGRAM} PRIVATE BEFORE ${TARGET_LIB_PATH}/lib ${PROJECT_BINARY_DIR} ${TARGET_INCLUDE_PATH}) +endforeach() +endif() + +if(BUILD_EXAMPLES) +foreach(PROGRAM add-compressed-data autoclose-archive in-memory) + add_executable(${PROGRAM} ${TARGET_LIB_PATH}/examples/${PROGRAM}.c) + target_link_libraries(${PROGRAM} ${TARGET_NAME}) + target_include_directories(${PROGRAM} PRIVATE BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}) +endforeach() +endif() + +if(BUILD_TOOLS) +foreach(PROGRAM zipcmp zipmerge ziptool) + add_executable(${PROGRAM} ${TARGET_LIB_PATH}/src/${PROGRAM}.c) + target_link_libraries(${PROGRAM} PRIVATE ${TARGET_NAME}) + target_include_directories(${PROGRAM} PRIVATE BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}) + target_sources(${PROGRAM} PRIVATE ${TARGET_LIB_PATH}/src/getopt.c) +endforeach() +target_sources(zipcmp PRIVATE ${TARGET_LIB_PATH}/src/diff_output.c) +target_link_libraries(zipcmp PRIVATE z) +endif() \ No newline at end of file diff --git a/libzip/README.OpenSource b/libzip/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..dddb2f98a4e8fe674d67e71358d9c7d4704e8da3 --- /dev/null +++ b/libzip/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "libzip", + "License": "BSD license", + "License File": "LICENSE", + "Version Number": "v1.9.2", + "Owner": "nih-at", + "Upstream URL": "https://github.com/nih-at/libzip.git", + "Description": "This is libzip, a C library for reading, creating, and modifying zip and zip64 archives." + } +] diff --git a/libzip/README_zh.md b/libzip/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..baaeddf50f44f2d327e9a2d972662a1c252a870c --- /dev/null +++ b/libzip/README_zh.md @@ -0,0 +1,16 @@ +# libzip三方库说明 +## 功能简介 +本软件是参照开源软件 [libzip](https://github.com/nih-at/libzip) 的CMakeLists.txt 重新编辑了适合在OpenHarmony上使用的CMakeLists.txt, +libzip是一个用于读取、创建和修改zip存档的C库。文件可以从数据缓冲区、文件或直接从其他zip档案复制的压缩数据中添加。 + +## 使用约束 +- ROM版本:OpenHarmony-v3.2-Beta1 + +- 三方库版本:v1.9.2 + +- 当前适配的功能:读取,创建和修改的C库 zip 存档。 + +- [libzip License](https://github.com/nih-at/libzip/blob/main/LICENSE) +## 集成方式 ++ [系统Rom包集成](docs/rom_integrate.md) ++ [系统Hap包集成](docs/hap_integrate.md) diff --git a/libzip/adapted/include/config.h b/libzip/adapted/include/config.h new file mode 100644 index 0000000000000000000000000000000000000000..0c69f0b5a29dcc7ed8675ce52b83e5327989a6f6 --- /dev/null +++ b/libzip/adapted/include/config.h @@ -0,0 +1,65 @@ +#ifndef HAD_CONFIG_H +#define HAD_CONFIG_H +#ifndef _HAD_ZIPCONF_H +#include "zipconf.h" +#endif +/* BEGIN DEFINES */ +#define ENABLE_FDOPEN +/* #undef HAVE___PROGNAME */ +/* #undef HAVE__CLOSE */ +/* #undef HAVE__DUP */ +#define HAVE__FDOPEN +/* #undef HAVE__FILENO */ +/* #undef HAVE__SETMODE */ +/* #undef HAVE__SNPRINTF */ +/* #undef HAVE__STRDUP */ +/* #undef HAVE__STRICMP */ +/* #undef HAVE__STRTOI64 */ +/* #undef HAVE__STRTOUI64 */ +/* #undef HAVE__UMASK */ +/* #undef HAVE__UNLINK */ +/* #undef HAVE_ARC4RANDOM */ +/* #undef HAVE_CLONEFILE */ +/* #undef HAVE_COMMONCRYPTO */ +#define HAVE_CRYPTO +#define HAVE_FICLONERANGE +#define HAVE_FILENO +#define HAVE_FCHMOD +#define HAVE_FSEEKO +#define HAVE_FTELLO +/* #undef HAVE_GETPROGNAME */ +/* #undef HAVE_GNUTLS */ +#define HAVE_LIBBZ2 +#define HAVE_LIBLZMA +#define HAVE_LIBZSTD +#define HAVE_LOCALTIME_R +/* #undef HAVE_MBEDTLS */ +/* #undef HAVE_MKSTEMP */ +#define HAVE_NULLABLE +#define HAVE_OPENSSL +/* #undef HAVE_SETMODE */ +#define HAVE_SNPRINTF +#define HAVE_STRCASECMP +#define HAVE_STRDUP +/* #undef HAVE_STRICMP */ +#define HAVE_STRTOLL +#define HAVE_STRTOULL +/* #undef HAVE_STRUCT_TM_TM_ZONE */ +#define HAVE_STDBOOL_H +#define HAVE_STRINGS_H +#define HAVE_UNISTD_H +/* #undef HAVE_WINDOWS_CRYPTO */ +#define SIZEOF_OFF_T 8 +#define SIZEOF_SIZE_T 8 +/* #undef HAVE_DIRENT_H */ +/* #undef HAVE_FTS_H */ +/* #undef HAVE_NDIR_H */ +/* #undef HAVE_SYS_DIR_H */ +/* #undef HAVE_SYS_NDIR_H */ +/* #undef WORDS_BIGENDIAN */ +#define HAVE_SHARED +/* END DEFINES */ +#define PACKAGE "libzip" +#define VERSION "1.9.2" + +#endif /* HAD_CONFIG_H */ diff --git a/libzip/adapted/include/zipconf.h b/libzip/adapted/include/zipconf.h new file mode 100644 index 0000000000000000000000000000000000000000..d36f47aee80016ee4fbc008f4d4f8bbcaba4b232 --- /dev/null +++ b/libzip/adapted/include/zipconf.h @@ -0,0 +1,50 @@ +#ifndef _HAD_ZIPCONF_H +#define _HAD_ZIPCONF_H + +/* + zipconf.h -- platform specific include file + + This file was generated automatically by CMake + based on ../cmake-zipconf.h.in. + */ + +#define LIBZIP_VERSION "1.9.2" +#define LIBZIP_VERSION_MAJOR 1 +#define LIBZIP_VERSION_MINOR 9 +#define LIBZIP_VERSION_MICRO 2 + +#define ZIP_STATIC + + + +#if !defined(__STDC_FORMAT_MACROS) +#define __STDC_FORMAT_MACROS 1 +#endif +#include + +typedef int8_t zip_int8_t; +typedef uint8_t zip_uint8_t; +typedef int16_t zip_int16_t; +typedef uint16_t zip_uint16_t; +typedef int32_t zip_int32_t; +typedef uint32_t zip_uint32_t; +typedef int64_t zip_int64_t; +typedef uint64_t zip_uint64_t; + +#define ZIP_INT8_MIN (-ZIP_INT8_MAX-1) +#define ZIP_INT8_MAX 0x7f +#define ZIP_UINT8_MAX 0xff + +#define ZIP_INT16_MIN (-ZIP_INT16_MAX-1) +#define ZIP_INT16_MAX 0x7fff +#define ZIP_UINT16_MAX 0xffff + +#define ZIP_INT32_MIN (-ZIP_INT32_MAX-1L) +#define ZIP_INT32_MAX 0x7fffffffL +#define ZIP_UINT32_MAX 0xffffffffLU + +#define ZIP_INT64_MIN (-ZIP_INT64_MAX-1LL) +#define ZIP_INT64_MAX 0x7fffffffffffffffLL +#define ZIP_UINT64_MAX 0xffffffffffffffffULL + +#endif /* zipconf.h */ diff --git a/libzip/adapted/lib/zip_err_str.c b/libzip/adapted/lib/zip_err_str.c new file mode 100644 index 0000000000000000000000000000000000000000..5cda90ffa1ef4a164045d8157b53310ada64d967 --- /dev/null +++ b/libzip/adapted/lib/zip_err_str.c @@ -0,0 +1,59 @@ +/* + This file was generated automatically by CMake + from zip.h and zipint.h; make changes there. +*/ + +#include "zipint.h" + +#define L ZIP_ET_LIBZIP +#define N ZIP_ET_NONE +#define S ZIP_ET_SYS +#define Z ZIP_ET_ZLIB + +#define E ZIP_DETAIL_ET_ENTRY +#define G ZIP_DETAIL_ET_GLOBAL + +const struct _zip_err_info _zip_err_str[] = { + { N, "No error" }, + { N, "Multi-disk zip archives not supported" }, + { S, "Renaming temporary file failed" }, + { S, "Closing zip archive failed" }, + { S, "Seek error" }, + { S, "Read error" }, + { S, "Write error" }, + { N, "CRC error" }, + { N, "Containing zip archive was closed" }, + { N, "No such file" }, + { N, "File already exists" }, + { S, "Can't open file" }, + { S, "Failure to create temporary file" }, + { Z, "Zlib error" }, + { N, "Malloc failure" }, + { N, "Entry has been changed" }, + { N, "Compression method not supported" }, + { N, "Premature end of file" }, + { N, "Invalid argument" }, + { N, "Not a zip archive" }, + { N, "Internal error" }, + { L, "Zip archive inconsistent" }, + { S, "Can't remove file" }, + { N, "Entry has been deleted" }, + { N, "Encryption method not supported" }, + { N, "Read-only archive" }, + { N, "No password provided" }, + { N, "Wrong password provided" }, + { N, "Operation not supported" }, + { N, "Resource still in use" }, + { S, "Tell error" }, + { N, "Compressed data invalid" }, + { N, "Operation cancelled" }, + { N, "Unexpected length of data" }, + { N, "Not allowed in torrentzip" }, +}; + +const int _zip_err_str_count = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]); + +const struct _zip_err_info _zip_err_details[] = { +}; + +const int _zip_err_details_count = sizeof(_zip_err_details)/sizeof(_zip_err_details[0]); diff --git a/libzip/bundle.json b/libzip/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..6a10ce591cd929c08a58ea384cc1da2914f26c85 --- /dev/null +++ b/libzip/bundle.json @@ -0,0 +1,38 @@ +{ + "name": "@ohos/libzip", + "description": "This is libzip, a C library for reading, creating, and modifying zip and zip64 archives. Files can be added from data buffers, files, or compressed data copied directly from other zip archives. ", + "version": "0.1.0", + "license": "Dieter Baron and Thomas Klausner", + "publishAs": "code-segment", + "segment": { + "destPath": "third_party/libzip" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "libzip", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": [ + "//third_party/libzip:libzip_shared", + "//third_party/libzip:nonrandomopen", + "//third_party/libzip:liboverride", + "//third_party/libzip:libzip_test" + ], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/libzip/docs/hap_integrate.md b/libzip/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..89e694dd623926838e993378f83c53a8d358ccc2 --- /dev/null +++ b/libzip/docs/hap_integrate.md @@ -0,0 +1,54 @@ +# libzip如何集成到应用hap +## 准备应用工程 +本库是基于DevEco Studio 3.1 Beta1版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) 。 +### 准备应用开发环境 +开发环境的准备参考:[开发环境准备](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) +### 增加构建脚本及配置文件 +- 下载本仓库,并解压 + ``` + cd ~/ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/libzip #三方库libzip 的目录结构如下 + ├── adapted #存放三方库相关文档的文件夹 + ├── docs #存放三方库相关文档的文件夹 + ├── test #存放三方库test的文件夹 + ├── CmakeLists.txt #构建脚本,支持hap包集成 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将 libzip 拷贝至工程xxxx/entry/src/main/cpp/thirdparty目录下 +### 准备三方库源码 +- 三方库下载地址:[libzip](https://github.com/nih-at/libzip), 版本:v1.9.2 + 解压后修改库文件名为libzip,拷贝至工程xxxx/entry/src/main/cpp/thirdparty/libzip目录下 +## 应用中使用三方库 +- 将三方库加入工程中,目录结构如下 + ``` + demo/entry/src/main/cpp + ├── thirdparty #三方库存放目录 + │ ├──libzip #三方库libzip + ├── CMakeLists.txt #工程目录的构建脚本 + ├── ..... #工程目录的其他文件 + ``` +- 在工程顶级CMakeLists.txt中引入三方库,增加如下代码 + ``` + include_directories(thirdparty/libzip/libzip/lib) + add_subdirectory(thirdparty/libzip) #引入子目录下的CMakeLists.txt + target_link_libraries(工程库名 PUBLIC zip) #工程依赖三方库libzip + ``` +## 编译工程 +编译工程,安装应用可以参考 [应用的安装和运行](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md#%E5%AE%89%E8%A3%85%E8%B0%83%E8%AF%95) + +## 运行效果 +- 在 [libzip](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/tree/master/libzip) 中,运行效果如下图 + ![演示1](pic/hap1.jpeg) + ![演示2](pic/hap2.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#%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87deveco-studio%E5%BC%80%E5%8F%91%E4%B8%80%E4%B8%AAnapi%E5%B7%A5%E7%A8%8B) + diff --git a/libzip/docs/pic/hap1.jpeg b/libzip/docs/pic/hap1.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..6e51f1d59804068a6b6317e4e559b9ea6dd5758d Binary files /dev/null and b/libzip/docs/pic/hap1.jpeg differ diff --git a/libzip/docs/pic/hap2.png b/libzip/docs/pic/hap2.png new file mode 100644 index 0000000000000000000000000000000000000000..a23ff6ac15f63daf2506bf2a0bb1400db8f88d15 Binary files /dev/null and b/libzip/docs/pic/hap2.png differ diff --git a/libzip/docs/pic/rom.png b/libzip/docs/pic/rom.png new file mode 100644 index 0000000000000000000000000000000000000000..1777393a1d70ca1fc03d4d7d4fa66cb8c67dae86 Binary files /dev/null and b/libzip/docs/pic/rom.png differ diff --git a/libzip/docs/pic/rom1.png b/libzip/docs/pic/rom1.png new file mode 100644 index 0000000000000000000000000000000000000000..eb11d3cf1a2141b4628d3757c6b075f4eb23db81 Binary files /dev/null and b/libzip/docs/pic/rom1.png differ diff --git a/libzip/docs/rom_integrate.md b/libzip/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..a60c2bf0442ea7849a4353122231f1b0e1ac3ad9 --- /dev/null +++ b/libzip/docs/rom_integrate.md @@ -0,0 +1,115 @@ +# libzip如何集成到系统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/libzip #三方库libzip的目录结构如下 + ├── adapted #存放三方库适配需要的代码文件 + ├── docs #存放三方库相关文档的文件夹 + ├── test #存放三方库test的文件夹 + ├── BUILD.gn #构建脚本,支持rom包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将三方库拷贝到OpenHarmony源码的third_party目录下 + ``` + cp ~/tpc_c_cplusplus/libzip ~/openharmony/third_party -rf + ``` +### 准备三方库源码 +``` +cd ~/openharmony/third_party/libzip #进入三方库目录 +git clone https://github.com/nih-at/libzip.git #下载三方库源码 +``` +## 系统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子系统下面新增libzip组件。 + +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "libzip", + "features": [] + } + ] + } + +``` +## 系统Rom中引入三方库测试程序 +如果需要编译测试用例,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件,对应组件的features中打开编译选项,如下 +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "libzip", + "features": ["enable_libzip_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/libzip 目录下,同时也打包到了镜像中 +## 运行效果 +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 +- 首先将hdc_std工具编译出来 + 工具编译出来所在路径out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + + ``` + hb set #源码根目录下使用hb set 选择产品ohos-sdk + hb build #然后编译 + ``` +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 +- 在Windows创建libzip文件,获取[libzip](https://github.com/nih-at/libzip) 原库目录下regress的test文件,将原生库测试需要的所有文件拷贝到windows下,并一起放到libzip文件中。 +- 将adapted/include/config.h放到libzip文件中,修改regress的test文件的NiHTest.pm文件,将 "$self->{top_builddir}/config.h" 改为"/data/libzip/config.h"。 如图:![如图](pic/rom1.png) +- 在开发板上配置 [perl](https://gitee.com/han_jin_fei/lycium/tree/master/CItools) 工具和将toybox替换为 [busybox](https://gitee.com/han_jin_fei/lycium/tree/master/CItools) ,[工具下载与操作方法](https://gitee.com/han_jin_fei/lycium/tree/master/CItools#ci-%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA) 。 +- 将libzip文件推送到开发板,在windows命令行进行如下操作 + ``` + hdc_std shell mount -oremount,rw / #修改系统权限为可读写 + hdc_std file send D:\xxx\libzip /data/ #将文件包推入开发板 + hdc_std shell #进入开发板 + #cd /data/libzip #进入libzip目录下, + #chmod -R 777 ./* #给libzip目录下文件的读写权限,执行test命令.txt文件的命令 + #注意需要将库拷贝到/system/lib 或者/system/lib64目录下 + ``` +- 运行测试程序 + 运行测试用例,结果如下图 + ![result](pic/rom.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 diff --git "a/libzip/test/test\345\221\275\344\273\244.txt" "b/libzip/test/test\345\221\275\344\273\244.txt" new file mode 100644 index 0000000000000000000000000000000000000000..d52f11a9d98cfb13ee8b1c71515f2e93e526833d --- /dev/null +++ "b/libzip/test/test\345\221\275\344\273\244.txt" @@ -0,0 +1,162 @@ +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_dir.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_buffer.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_file.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_file_duplicate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_file_twice_duplicate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_file_unchange.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_filep.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_stdin.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_zip_closed.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_zip_deflated.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_zip_deflated2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_zip_partial_deflated.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_zip_partial_stored.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_from_zip_stored.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_stored.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./add_stored_in_memory.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./buffer-fragment-read.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./buffer-fragment-write.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./cancel_45.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./cancel_90.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./check_torrentzip_fail.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./check_torrentzip_success.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./clone-buffer-add.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./clone-buffer-delete.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./clone-buffer-replace.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./clone-fs-add.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./clone-fs-delete.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./clone-fs-replace.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./cm-default.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./convert_to_torrentzip.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./count_entries.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./create_empty_keep.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-correct-password-aes128.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-correct-password-aes192.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-correct-password-aes256.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-correct-password-pkware-2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-correct-password-pkware.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-no-password-aes256.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-wrong-password-aes128.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-wrong-password-aes192.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-wrong-password-aes256.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-wrong-password-pkware-2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./decrypt-wrong-password-pkware.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_add_same.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_invalid.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_last.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_last_keep.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_multiple_last.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_multiple_partial.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./delete_renamed_rename.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encrypt.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-nonrandom-aes128.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-nonrandom-aes192.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-nonrandom-aes256.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-nonrandom-pkware-2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-nonrandom-pkware.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-remove.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./encryption-stat.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_add.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_add_multiple.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_count.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_count_by_id.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_count_ignore_zip64.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_delete.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_delete_by_id.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_field_align.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_get.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_get_by_id.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_set.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_set_modify_c.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./extra_set_modify_l.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fdopen_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./file_comment_encmismatch.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fopen_multiple.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fopen_multiple_reopen.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fopen_unchanged.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fread.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fseek_deflated.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fseek_fail.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./fseek_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./get_comment.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./junk_at_end.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./junk_at_start.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./name_locate-cp437.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./name_locate-utf8.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./name_locate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_cons_extrabytes.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_empty.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_empty_2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_extrabytes.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_file_count.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_filename_duplicate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_filename_duplicate_consistency.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_filename_duplicate_empty.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_filename_duplicate_empty_consistency.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_filename_empty.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_incons.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_many_fail.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_many_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_multidisk.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_new_but_exists.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_new_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_nonarchive.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_nosuchfile.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_too_short.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_truncate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_zip64_3mf.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./open_zip64_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./preload.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./progress.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./read_seek_read.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_ascii.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_cp437.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_deleted.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_fail.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_ok.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_utf8.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./rename_utf8_encmismatch.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./reopen.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./reopen_partial.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./reopen_partial_rest.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_comment_all.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_comment_localonly.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_comment_removeglobal.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_comment_revert.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_bzip2_to_deflate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_deflate_to_bzip2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_deflate_to_deflate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_deflate_to_store.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_lzma_no_eos_to_store.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_lzma_to_store.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_store_to_bzip2.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_store_to_deflate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_store_to_lzma.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_store_to_store.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_store_to_xz.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_store_to_zstd.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_unknown.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_xz_to_store.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_compression_zstd_to_store.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_file_dostime.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_file_mtime.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./set_file_mtime_pkware.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_cp437_guess.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_cp437_raw.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_cp437_strict.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_fileorder.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_streamed.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_streamed_zip64.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_utf8_guess.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_utf8_raw.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_utf8_strict.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_utf8_unmarked_strict.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./stat_index_zip64.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./truncate_empty_keep.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./unchange-delete-namelocate.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./utf-8-standardization.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./zip-in-archive-comment.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./zip64_creation.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./zip64_stored_creation.test" +perl ./runtest.in "-v" "--bin-sub-directory" "" "./zipcmp_zip_dir.test"