From f0c6587d899dfec676631716823839df31908991 Mon Sep 17 00:00:00 2001 From: Weihang Ding <798047000@qq.com> Date: Fri, 29 Sep 2023 14:36:59 +0800 Subject: [PATCH] [libimobiledevice] Add tools feature (#33872) * [libimobiledevice] Add tools feature * Update version database * Remove tools from default-features * Update version database --- ports/libimobiledevice/001_fix_msvc.patch | 161 ----------- .../libimobiledevice/004_fix_tools_msvc.patch | 273 ++++++++++++++++++ ports/libimobiledevice/CMakeLists.txt | 97 ++++++- ports/libimobiledevice/portfile.cmake | 34 +++ ports/libimobiledevice/vcpkg.json | 12 +- versions/baseline.json | 2 +- versions/l-/libimobiledevice.json | 5 + 7 files changed, 414 insertions(+), 170 deletions(-) create mode 100644 ports/libimobiledevice/004_fix_tools_msvc.patch diff --git a/ports/libimobiledevice/001_fix_msvc.patch b/ports/libimobiledevice/001_fix_msvc.patch index 7da854c607..bea25f00ef 100644 --- a/ports/libimobiledevice/001_fix_msvc.patch +++ b/ports/libimobiledevice/001_fix_msvc.patch @@ -164,164 +164,3 @@ index ccb7c4b..f0b832e 100644 #include #include "sbservices.h" -diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c -index 5694c12..d360cd3 100644 ---- a/tools/idevicebackup.c -+++ b/tools/idevicebackup.c -@@ -50,7 +50,9 @@ - #else - #error No supported crypto library enabled - #endif -+#ifndef _MSC_VER - #include -+#endif - #include - #include - -diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c -index c73b269..ffb35d1 100644 ---- a/tools/idevicebackup2.c -+++ b/tools/idevicebackup2.c -@@ -31,9 +31,13 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include -+#ifndef _MSC_VER - #include -+#endif - #include - #include - #include -diff --git a/tools/idevicebtlogger.c b/tools/idevicebtlogger.c -index 8de6b22..8fbf40d 100644 ---- a/tools/idevicebtlogger.c -+++ b/tools/idevicebtlogger.c -@@ -31,7 +31,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include - #include - #include -diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c -index 09bd537..f75ad9d 100644 ---- a/tools/idevicecrashreport.c -+++ b/tools/idevicecrashreport.c -@@ -29,7 +29,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include - #ifndef WIN32 - #include -diff --git a/tools/idevicedebug.c b/tools/idevicedebug.c -index 36c594e..9c11781 100644 ---- a/tools/idevicedebug.c -+++ b/tools/idevicedebug.c -@@ -30,8 +30,12 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif -+#ifndef _MSC_VER - #include -+#endif - #include - - #ifdef WIN32 -diff --git a/tools/idevicedevmodectl.c b/tools/idevicedevmodectl.c -index ba9b935..8e28e4b 100644 ---- a/tools/idevicedevmodectl.c -+++ b/tools/idevicedevmodectl.c -@@ -30,7 +30,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include - #ifndef WIN32 - #include -diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c -index f551b6c..fe9e1c1 100644 ---- a/tools/ideviceimagemounter.c -+++ b/tools/ideviceimagemounter.c -@@ -32,7 +32,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include - #include - #include -diff --git a/tools/idevicename.c b/tools/idevicename.c -index 69b76f6..cb8c9a6 100644 ---- a/tools/idevicename.c -+++ b/tools/idevicename.c -@@ -27,7 +27,9 @@ - - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include - #include - #ifndef WIN32 -diff --git a/tools/idevicepair.c b/tools/idevicepair.c -index 94d3f04..129c409 100644 ---- a/tools/idevicepair.c -+++ b/tools/idevicepair.c -@@ -31,7 +31,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #ifdef WIN32 - #include - #include -diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c -index 0e694c7..a4ca37d 100644 ---- a/tools/idevicescreenshot.c -+++ b/tools/idevicescreenshot.c -@@ -31,7 +31,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #ifndef WIN32 - #include - #endif -diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c -index 5600be2..69b7b03 100644 ---- a/tools/idevicesyslog.c -+++ b/tools/idevicesyslog.c -@@ -31,7 +31,9 @@ - #include - #include - #include -+#ifndef _MSC_VER - #include -+#endif - #include - - #ifdef WIN32 diff --git a/ports/libimobiledevice/004_fix_tools_msvc.patch b/ports/libimobiledevice/004_fix_tools_msvc.patch new file mode 100644 index 0000000000..395eb1d6dc --- /dev/null +++ b/ports/libimobiledevice/004_fix_tools_msvc.patch @@ -0,0 +1,273 @@ +diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c +index 5694c12..77fd81f 100644 +--- a/tools/idevicebackup.c ++++ b/tools/idevicebackup.c +@@ -50,7 +50,9 @@ + #else + #error No supported crypto library enabled + #endif ++#ifndef _MSC_VER + #include ++#endif + #include + #include + +@@ -68,6 +70,18 @@ + #define LOCK_ATTEMPTS 50 + #define LOCK_WAIT 200000 + ++#ifdef _MSC_VER ++static void usleep(__int64 usec) { ++ HANDLE timer; ++ LARGE_INTEGER ft; ++ ft.QuadPart = -(10*usec); ++ timer = CreateWaitableTimer(NULL, TRUE, NULL); ++ SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); ++ WaitForSingleObject(timer, INFINITE); ++ CloseHandle(timer); ++} ++#endif ++ + #ifdef WIN32 + #include + #define sleep(x) Sleep(x*1000) +diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c +index c73b269..33157c9 100644 +--- a/tools/idevicebackup2.c ++++ b/tools/idevicebackup2.c +@@ -31,9 +31,13 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #include ++#ifndef _MSC_VER + #include ++#endif + #include + #include + #include +@@ -54,6 +58,62 @@ + #define LOCK_ATTEMPTS 50 + #define LOCK_WAIT 200000 + ++#ifdef _MSC_VER ++static void usleep(__int64 usec) { ++ HANDLE timer; ++ LARGE_INTEGER ft; ++ ft.QuadPart = -(10*usec); ++ timer = CreateWaitableTimer(NULL, TRUE, NULL); ++ SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); ++ WaitForSingleObject(timer, INFINITE); ++ CloseHandle(timer); ++} ++#ifndef ISSLASH ++#define ISSLASH(C) ((C) == '/' || (C) == '\\') ++#endif ++#ifndef FILESYSTEM_PREFIX_LEN ++#define FILESYSTEM_PREFIX_LEN(Filename) 0 ++#endif ++static char *basename(char const *name) { ++ char const *base = name + FILESYSTEM_PREFIX_LEN(name); ++ char const *p; ++ ++ for (p = base; *p; p++) { ++ if (ISSLASH(*p)) { ++ do p++; ++ while (ISSLASH(*p)); ++ ++ if (!*p) { ++ if (ISSLASH(*base)) ++ base = p - 1; ++ break; ++ } ++ base = p; ++ } ++ } ++ ++ return (char *) base; ++} ++static size_t dirlen(char const *path) { ++ size_t prefix_length = FILESYSTEM_PREFIX_LEN(path); ++ size_t length; ++ for (length = basename(path) - path; prefix_length < length; length--) ++ if (!ISSLASH(path[length - 1])) ++ return length; ++ return prefix_length + ISSLASH(path[prefix_length]); ++} ++static char *dirname(char const *path) { ++ size_t length = dirlen(path); ++ int append_dot = (length == FILESYSTEM_PREFIX_LEN(path)); ++ char *newpath = (char *) malloc(length + append_dot + 1); ++ memcpy(newpath, path, length); ++ if (append_dot) ++ newpath[length++] = '.'; ++ newpath[length] = 0; ++ return newpath; ++} ++#endif ++ + #ifdef WIN32 + #include + #include +diff --git a/tools/idevicebtlogger.c b/tools/idevicebtlogger.c +index 8de6b22..8fbf40d 100644 +--- a/tools/idevicebtlogger.c ++++ b/tools/idevicebtlogger.c +@@ -31,7 +31,9 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #include + #include + #include +diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c +index 09bd537..9f53b30 100644 +--- a/tools/idevicecrashreport.c ++++ b/tools/idevicecrashreport.c +@@ -29,7 +29,14 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#else ++#define S_IFIFO _S_IFIFO ++#define S_IFBLK 0x3000 ++#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) ++#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) ++#endif + #include + #ifndef WIN32 + #include +diff --git a/tools/idevicedebug.c b/tools/idevicedebug.c +index 36c594e..9c11781 100644 +--- a/tools/idevicedebug.c ++++ b/tools/idevicedebug.c +@@ -30,8 +30,12 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif ++#ifndef _MSC_VER + #include ++#endif + #include + + #ifdef WIN32 +diff --git a/tools/idevicedevmodectl.c b/tools/idevicedevmodectl.c +index ba9b935..8e28e4b 100644 +--- a/tools/idevicedevmodectl.c ++++ b/tools/idevicedevmodectl.c +@@ -30,7 +30,9 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #include + #ifndef WIN32 + #include +diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c +index f551b6c..26bb80c 100644 +--- a/tools/ideviceimagemounter.c ++++ b/tools/ideviceimagemounter.c +@@ -32,9 +32,13 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #include ++#ifndef _MSC_VER + #include ++#endif + #include + #ifndef WIN32 + #include +diff --git a/tools/idevicename.c b/tools/idevicename.c +index 69b76f6..cb8c9a6 100644 +--- a/tools/idevicename.c ++++ b/tools/idevicename.c +@@ -27,7 +27,9 @@ + + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #include + #include + #ifndef WIN32 +diff --git a/tools/idevicepair.c b/tools/idevicepair.c +index 94d3f04..129c409 100644 +--- a/tools/idevicepair.c ++++ b/tools/idevicepair.c +@@ -31,7 +31,9 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #ifdef WIN32 + #include + #include +diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c +index 4080a28..f64e2c4 100644 +--- a/tools/ideviceprovision.c ++++ b/tools/ideviceprovision.c +@@ -42,6 +42,14 @@ + #include + #endif + ++#ifdef _MSC_VER ++#include ++#ifndef _S_ISTYPE ++#define _S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask)) ++#define S_ISDIR(mode) _S_ISTYPE((mode), _S_IFDIR) ++#endif ++#endif ++ + #include + #include + #include +diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c +index 0e694c7..6f4b1c5 100644 +--- a/tools/idevicescreenshot.c ++++ b/tools/idevicescreenshot.c +@@ -31,7 +31,11 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#else ++#define F_OK 0 ++#endif + #ifndef WIN32 + #include + #endif +diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c +index 5600be2..69b7b03 100644 +--- a/tools/idevicesyslog.c ++++ b/tools/idevicesyslog.c +@@ -31,7 +31,9 @@ + #include + #include + #include ++#ifndef _MSC_VER + #include ++#endif + #include + + #ifdef WIN32 diff --git a/ports/libimobiledevice/CMakeLists.txt b/ports/libimobiledevice/CMakeLists.txt index 9b42052a94..e8980cfcdb 100644 --- a/ports/libimobiledevice/CMakeLists.txt +++ b/ports/libimobiledevice/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.15) project(libimobiledevice C) +option(BUILD_TOOLS "Build tools." OFF) + include(GNUInstallDirs) file(GLOB_RECURSE LIBIMOBILEDEVICE_SOURCE src/*.c src/*.h) @@ -36,13 +38,11 @@ find_package(unofficial-libimobiledevice-glue CONFIG REQUIRED) find_package(unofficial-libusbmuxd CONFIG REQUIRED) find_package(OpenSSL REQUIRED) -add_library(libimobiledevice ${LIBIMOBILEDEVICE_SOURCE} ${LIBIMOBILEDEVICE_COMMON_SOURCE} ${ED25519_HEADER} ${LIBSRP6A_SHA512_HEADER}) -target_include_directories(libimobiledevice - PRIVATE - "$" - "$" - PUBLIC - "$" +add_library(libimobiledevice ${LIBIMOBILEDEVICE_SOURCE} ${LIBIMOBILEDEVICE_COMMON_SOURCE}) +target_include_directories(libimobiledevice PUBLIC + "$" + "$" + "$" ) target_compile_definitions(libimobiledevice PRIVATE ${DEFINITIONS}) target_link_libraries(libimobiledevice @@ -98,3 +98,86 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}/libimobiledevice-1.0.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) + +if(BUILD_TOOLS) + if(WIN32) + find_package(unofficial-getopt-win32 REQUIRED) + endif() + + function(add_tool name source) + add_executable("${name}" "${source}" ${LIBIMOBILEDEVICE_COMMON_SOURCE}) + target_compile_definitions("${name}" PRIVATE + -DPACKAGE_VERSION="2.0.2" + -DPACKAGE_URL="https://github.com/libimobiledevice/libusbmuxd" + -DPACKAGE_BUGREPORT="https://github.com/libimobiledevice/libusbmuxd/issues" + -DHAVE_OPENSSL + ) + target_link_libraries("${name}" PRIVATE + libimobiledevice + unofficial::libimobiledevice-glue::libimobiledevice-glue + unofficial::libusbmuxd::libusbmuxd + OpenSSL::SSL + OpenSSL::Crypto + ) + if(WIN32) + target_compile_definitions("${name}" PRIVATE + -D_CRT_SECURE_NO_WARNINGS + -DWIN32_LEAN_AND_MEAN + -DWIN32 + ) + target_link_libraries("${name}" PRIVATE unofficial::getopt-win32::getopt Ws2_32) + endif() + if(UNIX) + target_compile_definitions("${name}" PRIVATE + -DHAVE_VASPRINTF + -DHAVE_ASPRINTF + ) + endif() + endfunction(add_tool) + + add_tool(idevice_id "tools/idevice_id.c") + add_tool(idevicebackup "tools/idevicebackup.c") + add_tool(idevicebackup2 "tools/idevicebackup2.c") + add_tool(idevicebtlogger "tools/idevicebtlogger.c") + add_tool(idevicecrashreport "tools/idevicecrashreport.c") + add_tool(idevicedate "tools/idevicedate.c") + add_tool(idevicedebug "tools/idevicedebug.c") + add_tool(idevicedebugserverproxy "tools/idevicedebugserverproxy.c") + add_tool(idevicedevmodectl "tools/idevicedevmodectl.c") + add_tool(idevicediagnostics "tools/idevicediagnostics.c") + add_tool(ideviceenterrecovery "tools/ideviceenterrecovery.c") + add_tool(ideviceimagemounter "tools/ideviceimagemounter.c") + add_tool(ideviceinfo "tools/ideviceinfo.c") + add_tool(idevicename "tools/idevicename.c") + add_tool(idevicenotificationproxy "tools/idevicenotificationproxy.c") + add_tool(idevicepair "tools/idevicepair.c") + add_tool(ideviceprovision "tools/ideviceprovision.c") + add_tool(idevicescreenshot "tools/idevicescreenshot.c") + add_tool(idevicesetlocation "tools/idevicesetlocation.c") + add_tool(idevicesyslog "tools/idevicesyslog.c") + + install( + TARGETS + idevice_id + idevicebackup + idevicebackup2 + idevicebtlogger + idevicecrashreport + idevicedate + idevicedebug + idevicedebugserverproxy + idevicedevmodectl + idevicediagnostics + ideviceenterrecovery + ideviceimagemounter + ideviceinfo + idevicename + idevicenotificationproxy + idevicepair + ideviceprovision + idevicescreenshot + idevicesetlocation + idevicesyslog + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) +endif() diff --git a/ports/libimobiledevice/portfile.cmake b/ports/libimobiledevice/portfile.cmake index df145747e5..81a788ff75 100644 --- a/ports/libimobiledevice/portfile.cmake +++ b/ports/libimobiledevice/portfile.cmake @@ -8,18 +8,52 @@ vcpkg_from_github( 001_fix_msvc.patch 002_fix_static_build.patch 003_fix_api.patch + 004_fix_tools_msvc.patch ) file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") file(COPY "${CMAKE_CURRENT_LIST_DIR}/exports.def" DESTINATION "${SOURCE_PATH}") +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + tools BUILD_TOOLS +) + vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} ) vcpkg_cmake_install() vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-${PORT}) vcpkg_fixup_pkgconfig() +if("tools" IN_LIST FEATURES) + vcpkg_copy_tools( + TOOL_NAMES + idevice_id + idevicebackup + idevicebackup2 + idevicebtlogger + idevicecrashreport + idevicedate + idevicedebug + idevicedebugserverproxy + idevicedevmodectl + idevicediagnostics + ideviceenterrecovery + ideviceimagemounter + ideviceinfo + idevicename + idevicenotificationproxy + idevicepair + ideviceprovision + idevicescreenshot + idevicesetlocation + idevicesyslog + AUTO_CLEAN + ) +endif() file(READ "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake" cmake_config) file(WRITE "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake" diff --git a/ports/libimobiledevice/vcpkg.json b/ports/libimobiledevice/vcpkg.json index 7460bbca3f..a288fe627a 100644 --- a/ports/libimobiledevice/vcpkg.json +++ b/ports/libimobiledevice/vcpkg.json @@ -1,6 +1,7 @@ { "name": "libimobiledevice", "version-date": "2023-07-05", + "port-version": 1, "description": "A cross-platform protocol library to communicate with iOS devices", "homepage": "http://www.libimobiledevice.org", "license": "LGPL-2.1-or-later", @@ -19,5 +20,14 @@ "name": "vcpkg-cmake-config", "host": true } - ] + ], + "features": { + "tools": { + "description": "build command line tool", + "supports": "!android & !ios & !xbox", + "dependencies": [ + "getopt" + ] + } + } } diff --git a/versions/baseline.json b/versions/baseline.json index 6e1fc8e6d1..575dd6778d 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -4282,7 +4282,7 @@ }, "libimobiledevice": { "baseline": "2023-07-05", - "port-version": 0 + "port-version": 1 }, "libimobiledevice-glue": { "baseline": "2023-05-13", diff --git a/versions/l-/libimobiledevice.json b/versions/l-/libimobiledevice.json index 4766ab9ac9..7704d200eb 100644 --- a/versions/l-/libimobiledevice.json +++ b/versions/l-/libimobiledevice.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "cdbf91c1b491bd8230042a4c90a3cb3a5baa2e2e", + "version-date": "2023-07-05", + "port-version": 1 + }, { "git-tree": "b7b8456460bdd58cd90cd74a468c6e16a2053f36", "version-date": "2023-07-05",