[libimobiledevice] Add tools feature (#33872)

* [libimobiledevice] Add tools feature

* Update version database

* Remove tools from default-features

* Update version database
This commit is contained in:
Weihang Ding 2023-09-29 14:36:59 +08:00 committed by GitHub
parent e7809cf36a
commit f0c6587d89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 414 additions and 170 deletions

View File

@ -164,164 +164,3 @@ index ccb7c4b..f0b832e 100644
#include <plist/plist.h>
#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 <unistd.h>
+#endif
#include <ctype.h>
#include <time.h>
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 <errno.h>
#include <stdlib.h>
#include <signal.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <dirent.h>
+#ifndef _MSC_VER
#include <libgen.h>
+#endif
#include <ctype.h>
#include <time.h>
#include <getopt.h>
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 <errno.h>
#include <signal.h>
#include <stdlib.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <getopt.h>
#include <assert.h>
#include <fcntl.h>
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <getopt.h>
#ifndef WIN32
#include <signal.h>
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 <stdlib.h>
#include <string.h>
#include <time.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
+#ifndef _MSC_VER
#include <libgen.h>
+#endif
#include <getopt.h>
#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 <string.h>
#include <getopt.h>
#include <sys/stat.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <errno.h>
#ifndef WIN32
#include <signal.h>
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 <string.h>
#include <getopt.h>
#include <errno.h>
+#ifndef _MSC_VER
#include <libgen.h>
+#endif
#include <time.h>
#include <sys/time.h>
#include <inttypes.h>
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 <stdio.h>
#include <string.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <stdlib.h>
#include <getopt.h>
#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 <stdlib.h>
#include <getopt.h>
#include <ctype.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#ifdef WIN32
#include <windows.h>
#include <conio.h>
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 <getopt.h>
#include <errno.h>
#include <time.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#ifndef WIN32
#include <signal.h>
#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 <errno.h>
#include <signal.h>
#include <stdlib.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <getopt.h>
#ifdef WIN32

View File

@ -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 <unistd.h>
+#endif
#include <ctype.h>
#include <time.h>
@@ -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 <windows.h>
#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 <errno.h>
#include <stdlib.h>
#include <signal.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <dirent.h>
+#ifndef _MSC_VER
#include <libgen.h>
+#endif
#include <ctype.h>
#include <time.h>
#include <getopt.h>
@@ -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 <windows.h>
#include <conio.h>
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 <errno.h>
#include <signal.h>
#include <stdlib.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <getopt.h>
#include <assert.h>
#include <fcntl.h>
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#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 <getopt.h>
#ifndef WIN32
#include <signal.h>
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 <stdlib.h>
#include <string.h>
#include <time.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
+#ifndef _MSC_VER
#include <libgen.h>
+#endif
#include <getopt.h>
#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 <string.h>
#include <getopt.h>
#include <sys/stat.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <errno.h>
#ifndef WIN32
#include <signal.h>
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 <string.h>
#include <getopt.h>
#include <errno.h>
+#ifndef _MSC_VER
#include <libgen.h>
+#endif
#include <time.h>
+#ifndef _MSC_VER
#include <sys/time.h>
+#endif
#include <inttypes.h>
#ifndef WIN32
#include <signal.h>
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 <stdio.h>
#include <string.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <stdlib.h>
#include <getopt.h>
#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 <stdlib.h>
#include <getopt.h>
#include <ctype.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#ifdef WIN32
#include <windows.h>
#include <conio.h>
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 <arpa/inet.h>
#endif
+#ifdef _MSC_VER
+#include <Winsock2.h>
+#ifndef _S_ISTYPE
+#define _S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
+#define S_ISDIR(mode) _S_ISTYPE((mode), _S_IFDIR)
+#endif
+#endif
+
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
#include <libimobiledevice/misagent.h>
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 <getopt.h>
#include <errno.h>
#include <time.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#else
+#define F_OK 0
+#endif
#ifndef WIN32
#include <signal.h>
#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 <errno.h>
#include <signal.h>
#include <stdlib.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <getopt.h>
#ifdef WIN32

View File

@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
PUBLIC
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
add_library(libimobiledevice ${LIBIMOBILEDEVICE_SOURCE} ${LIBIMOBILEDEVICE_COMMON_SOURCE})
target_include_directories(libimobiledevice PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
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()

View File

@ -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"

View File

@ -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"
]
}
}
}

View File

@ -4282,7 +4282,7 @@
},
"libimobiledevice": {
"baseline": "2023-07-05",
"port-version": 0
"port-version": 1
},
"libimobiledevice-glue": {
"baseline": "2023-05-13",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "cdbf91c1b491bd8230042a4c90a3cb3a5baa2e2e",
"version-date": "2023-07-05",
"port-version": 1
},
{
"git-tree": "b7b8456460bdd58cd90cd74a468c6e16a2053f36",
"version-date": "2023-07-05",