add adb 35.0.1
This commit is contained in:
parent
a5b8d40661
commit
e4feabd11d
88
devel/adb/Makefile
Normal file
88
devel/adb/Makefile
Normal file
@ -0,0 +1,88 @@
|
||||
COMMENT = Android debugging tools
|
||||
|
||||
V = 35.0.1
|
||||
DISTNAME = android-tools-${V}
|
||||
PKGNAME = adb-${V}
|
||||
|
||||
CATEGORIES = devel
|
||||
|
||||
HOMEPAGE = https://developer.android.com/tools/help/adb.html
|
||||
|
||||
SITES = https://github.com/nmeum/android-tools/releases/download/${V}/
|
||||
|
||||
EXTRACT_SUFX = .tar.xz
|
||||
|
||||
# Apache License v2.0
|
||||
PERMIT_PACKAGE = Yes
|
||||
|
||||
WANTLIB += c brotlicommon brotlidec brotlienc lz4 pcre2-8
|
||||
WANTLIB += pthread protobuf usb-1.0 z zstd
|
||||
|
||||
LIB_DEPENDS = archivers/brotli \
|
||||
archivers/lz4 \
|
||||
archivers/zstd \
|
||||
devel/libusb1 \
|
||||
devel/pcre2 \
|
||||
devel/protobuf
|
||||
|
||||
MODULES = devel/cmake
|
||||
|
||||
BUILD_DEPENDS = lang/go
|
||||
|
||||
RUN_DEPENDS = lang/python/3
|
||||
|
||||
CONFIGURE_ARGS = -DANDROID_TOOLS_PATCH_VENDOR=OFF \
|
||||
-DCMAKE_INSTALL_PREFIX=${PREFIX}
|
||||
|
||||
# Go (boringssl err_data_generate.go) needs a writable cache dir
|
||||
MAKE_ENV += GOCACHE=/tmp/adb-gocache
|
||||
|
||||
NO_TEST = Yes
|
||||
|
||||
# Create OpenBSD compat stubs for Linux-specific headers not in the tarball.
|
||||
post-patch:
|
||||
mkdir -p ${WRKSRC}/vendor/compat/sys ${WRKSRC}/vendor/compat/linux
|
||||
printf '/* OpenBSD stub: major/minor/makedev are in sys/types.h */\n' \
|
||||
> ${WRKSRC}/vendor/compat/sys/sysmacros.h
|
||||
printf '#pragma once\n#include <sys/types.h>\n' \
|
||||
>> ${WRKSRC}/vendor/compat/sys/sysmacros.h
|
||||
printf '/* OpenBSD stub for linux/capability.h */\n#pragma once\n' \
|
||||
> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#include <stdint.h>\ntypedef uint32_t __u32;\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define _LINUX_CAPABILITY_VERSION_3 0x20080522\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define _LINUX_CAPABILITY_U32S_3 2\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define VFS_CAP_REVISION_1 0x01000000\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define VFS_CAP_REVISION_2 0x02000000\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define VFS_CAP_REVISION_3 0x03000000\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define VFS_CAP_REVISION_MASK 0xff000000\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '#define VFS_CAP_FLAGS_EFFECTIVE 0x000001\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf 'struct vfs_cap_data { __u32 magic_etc; struct { __u32 permitted, inheritable; } data[2]; };\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf 'struct vfs_ns_cap_data { __u32 magic_etc; struct { __u32 permitted, inheritable; } data[2]; __u32 rootid; };\n' \
|
||||
>> ${WRKSRC}/vendor/compat/linux/capability.h
|
||||
printf '/* OpenBSD compat: add mempcpy (GNU extension) via #include_next wrapper */\n' \
|
||||
> ${WRKSRC}/vendor/compat/string.h
|
||||
printf '#pragma once\n#include_next <string.h>\n' \
|
||||
>> ${WRKSRC}/vendor/compat/string.h
|
||||
printf '#ifndef mempcpy\n' \
|
||||
>> ${WRKSRC}/vendor/compat/string.h
|
||||
printf 'static inline void *mempcpy(void *dst, const void *src, size_t n) {\n' \
|
||||
>> ${WRKSRC}/vendor/compat/string.h
|
||||
printf '\treturn (char *)memcpy(dst, src, n) + n;\n' \
|
||||
>> ${WRKSRC}/vendor/compat/string.h
|
||||
printf '}\n#endif\n' \
|
||||
>> ${WRKSRC}/vendor/compat/string.h
|
||||
cp ${FILESDIR}/fastboot_usb_libusb.cpp \
|
||||
${WRKSRC}/vendor/core/fastboot/usb_libusb.cpp
|
||||
cp ${FILESDIR}/adb_usb_openbsd.cpp \
|
||||
${WRKSRC}/vendor/adb/client/usb_openbsd.cpp
|
||||
|
||||
.include <bsd.port.mk>
|
||||
2
devel/adb/distinfo
Normal file
2
devel/adb/distinfo
Normal file
@ -0,0 +1,2 @@
|
||||
SHA256 (android-tools-35.0.1.tar.xz) = UNnnzoljfQ4vNkWMoqO6P0O/GWnz+izYwO72ig4XutE=
|
||||
SIZE (android-tools-35.0.1.tar.xz) = 21841324
|
||||
25
devel/adb/files/adb_usb_openbsd.cpp
Normal file
25
devel/adb/files/adb_usb_openbsd.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* OpenBSD stub implementations of the old-style adb USB API (usb_handle*).
|
||||
*
|
||||
* These are never called because should_use_libusb() always returns true on
|
||||
* OpenBSD, but the linker requires them to resolve symbols referenced from
|
||||
* adb/client/transport_usb.cpp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "client/usb.h"
|
||||
|
||||
struct usb_handle {};
|
||||
|
||||
void usb_init() {}
|
||||
void usb_cleanup() {}
|
||||
|
||||
int usb_write(usb_handle*, const void*, int) { return -1; }
|
||||
int usb_read(usb_handle*, void*, int) { return -1; }
|
||||
int usb_close(usb_handle*) { return -1; }
|
||||
void usb_reset(usb_handle*) {}
|
||||
void usb_kick(usb_handle*) {}
|
||||
size_t usb_get_max_packet_size(usb_handle*) { return 512; }
|
||||
170
devel/adb/files/fastboot_usb_libusb.cpp
Normal file
170
devel/adb/files/fastboot_usb_libusb.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* USB transport for fastboot using libusb-1.0.
|
||||
* Used on OpenBSD (and other platforms without Linux usbfs).
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
|
||||
#include <android-base/macros.h>
|
||||
#include "usb.h"
|
||||
|
||||
static libusb_context* g_ctx = nullptr;
|
||||
|
||||
class LibUsbTransport : public UsbTransport {
|
||||
public:
|
||||
LibUsbTransport(libusb_device_handle* h, uint8_t ep_in, uint8_t ep_out,
|
||||
int ifc_num, uint32_t ms_timeout)
|
||||
: handle_(h), ep_in_(ep_in), ep_out_(ep_out),
|
||||
ifc_num_(ifc_num), ms_timeout_(ms_timeout) {}
|
||||
~LibUsbTransport() override { Close(); }
|
||||
|
||||
ssize_t Read(void* data, size_t len) override {
|
||||
int transferred = 0;
|
||||
int r = libusb_bulk_transfer(handle_, ep_in_,
|
||||
reinterpret_cast<unsigned char*>(data),
|
||||
static_cast<int>(len), &transferred,
|
||||
ms_timeout_);
|
||||
if (r == 0 || r == LIBUSB_ERROR_TIMEOUT)
|
||||
return transferred;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t Write(const void* data, size_t len) override {
|
||||
int transferred = 0;
|
||||
int r = libusb_bulk_transfer(handle_, ep_out_,
|
||||
const_cast<unsigned char*>(
|
||||
reinterpret_cast<const unsigned char*>(data)),
|
||||
static_cast<int>(len), &transferred,
|
||||
ms_timeout_);
|
||||
if (r == 0)
|
||||
return transferred;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Close() override {
|
||||
if (handle_) {
|
||||
libusb_release_interface(handle_, ifc_num_);
|
||||
libusb_close(handle_);
|
||||
handle_ = nullptr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Reset() override {
|
||||
if (handle_)
|
||||
return libusb_reset_device(handle_) ? -1 : 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private:
|
||||
libusb_device_handle* handle_;
|
||||
uint8_t ep_in_, ep_out_;
|
||||
int ifc_num_;
|
||||
uint32_t ms_timeout_;
|
||||
DISALLOW_COPY_AND_ASSIGN(LibUsbTransport);
|
||||
};
|
||||
|
||||
std::unique_ptr<UsbTransport> usb_open(ifc_match_func callback,
|
||||
uint32_t timeout_ms) {
|
||||
if (!g_ctx) {
|
||||
if (libusb_init(&g_ctx) != 0)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
libusb_device** devs;
|
||||
ssize_t cnt = libusb_get_device_list(g_ctx, &devs);
|
||||
if (cnt < 0)
|
||||
return nullptr;
|
||||
|
||||
std::unique_ptr<UsbTransport> result;
|
||||
|
||||
for (ssize_t i = 0; i < cnt && !result; i++) {
|
||||
libusb_device* dev = devs[i];
|
||||
struct libusb_device_descriptor desc;
|
||||
|
||||
if (libusb_get_device_descriptor(dev, &desc) != 0)
|
||||
continue;
|
||||
|
||||
struct libusb_config_descriptor* config;
|
||||
if (libusb_get_active_config_descriptor(dev, &config) != 0)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < (int)config->bNumInterfaces && !result; j++) {
|
||||
const struct libusb_interface* ifc = &config->interface[j];
|
||||
for (int k = 0; k < ifc->num_altsetting && !result; k++) {
|
||||
const struct libusb_interface_descriptor* id = &ifc->altsetting[k];
|
||||
|
||||
usb_ifc_info info = {};
|
||||
info.dev_vendor = desc.idVendor;
|
||||
info.dev_product = desc.idProduct;
|
||||
info.dev_class = desc.bDeviceClass;
|
||||
info.dev_subclass = desc.bDeviceSubClass;
|
||||
info.dev_protocol = desc.bDeviceProtocol;
|
||||
info.ifc_class = id->bInterfaceClass;
|
||||
info.ifc_subclass = id->bInterfaceSubClass;
|
||||
info.ifc_protocol = id->bInterfaceProtocol;
|
||||
|
||||
uint8_t ep_in = 0, ep_out = 0;
|
||||
for (int e = 0; e < (int)id->bNumEndpoints; e++) {
|
||||
const struct libusb_endpoint_descriptor* ep = &id->endpoint[e];
|
||||
if ((ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) !=
|
||||
LIBUSB_TRANSFER_TYPE_BULK)
|
||||
continue;
|
||||
if (ep->bEndpointAddress & LIBUSB_ENDPOINT_IN) {
|
||||
ep_in = ep->bEndpointAddress;
|
||||
info.has_bulk_in = 1;
|
||||
} else {
|
||||
ep_out = ep->bEndpointAddress;
|
||||
info.has_bulk_out = 1;
|
||||
}
|
||||
}
|
||||
|
||||
libusb_device_handle* h;
|
||||
if (libusb_open(dev, &h) != 0)
|
||||
continue;
|
||||
|
||||
info.writable = 1;
|
||||
if (desc.iSerialNumber) {
|
||||
libusb_get_string_descriptor_ascii(
|
||||
h, desc.iSerialNumber,
|
||||
reinterpret_cast<unsigned char*>(info.serial_number),
|
||||
sizeof(info.serial_number));
|
||||
}
|
||||
if (id->iInterface) {
|
||||
libusb_get_string_descriptor_ascii(
|
||||
h, id->iInterface,
|
||||
reinterpret_cast<unsigned char*>(info.interface),
|
||||
sizeof(info.interface));
|
||||
}
|
||||
snprintf(info.device_path, sizeof(info.device_path),
|
||||
"usb:%d:%d", libusb_get_bus_number(dev),
|
||||
libusb_get_device_address(dev));
|
||||
|
||||
if (callback(&info) == 0 && ep_in && ep_out) {
|
||||
if (libusb_claim_interface(h, id->bInterfaceNumber) == 0) {
|
||||
result = std::make_unique<LibUsbTransport>(
|
||||
h, ep_in, ep_out, id->bInterfaceNumber,
|
||||
timeout_ms);
|
||||
} else {
|
||||
libusb_close(h);
|
||||
}
|
||||
} else {
|
||||
libusb_close(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
libusb_free_config_descriptor(config);
|
||||
}
|
||||
|
||||
libusb_free_device_list(devs, 1);
|
||||
return result;
|
||||
}
|
||||
22
devel/adb/patches/patch-vendor_CMakeLists_adb_txt
Normal file
22
devel/adb/patches/patch-vendor_CMakeLists_adb_txt
Normal file
@ -0,0 +1,22 @@
|
||||
Index: vendor/CMakeLists.adb.txt
|
||||
--- vendor/CMakeLists.adb.txt.orig
|
||||
+++ vendor/CMakeLists.adb.txt
|
||||
@@ -43,6 +43,9 @@ set(libadb_SOURCES
|
||||
if(APPLE)
|
||||
list(APPEND libadb_SOURCES
|
||||
adb/client/usb_osx.cpp)
|
||||
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
+ list(APPEND libadb_SOURCES
|
||||
+ adb/client/usb_openbsd.cpp)
|
||||
else()
|
||||
list(APPEND libadb_SOURCES
|
||||
adb/client/usb_linux.cpp)
|
||||
@@ -129,7 +132,7 @@ set(libcutils_SOURCES
|
||||
core/libcutils/strlcpy.c
|
||||
core/libcutils/trace-host.cpp)
|
||||
|
||||
-if (NOT APPLE AND NOT WIN32)
|
||||
+if (NOT APPLE AND NOT WIN32 AND NOT (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD"))
|
||||
list(APPEND libcutils_SOURCES
|
||||
core/libcutils/canned_fs_config.cpp
|
||||
core/libcutils/fs_config.cpp)
|
||||
31
devel/adb/patches/patch-vendor_CMakeLists_fastboot_txt
Normal file
31
devel/adb/patches/patch-vendor_CMakeLists_fastboot_txt
Normal file
@ -0,0 +1,31 @@
|
||||
Index: vendor/CMakeLists.fastboot.txt
|
||||
--- vendor/CMakeLists.fastboot.txt.orig
|
||||
+++ vendor/CMakeLists.fastboot.txt
|
||||
@@ -119,6 +119,9 @@ set(fastboot_SOURCES
|
||||
if(APPLE)
|
||||
list(APPEND fastboot_SOURCES
|
||||
core/fastboot/usb_osx.cpp)
|
||||
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
+ list(APPEND fastboot_SOURCES
|
||||
+ core/fastboot/usb_libusb.cpp)
|
||||
else()
|
||||
list(APPEND fastboot_SOURCES
|
||||
core/fastboot/usb_linux.cpp)
|
||||
@@ -136,10 +139,16 @@ target_compile_definitions(fastboot PRIVATE
|
||||
target_link_libraries(fastboot
|
||||
libsparse libzip libcutils liblog liblp libutil
|
||||
libbase libext4 libselinux libsepol libdiagnoseusb crypto
|
||||
- z PkgConfig::libpcre2-8 Threads::Threads dl)
|
||||
+ z PkgConfig::libpcre2-8 Threads::Threads)
|
||||
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
+ target_link_libraries(fastboot dl)
|
||||
+endif()
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(fastboot
|
||||
"-framework CoreFoundation"
|
||||
"-framework IOKit")
|
||||
+endif()
|
||||
+if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
+ target_link_libraries(fastboot PkgConfig::libusb-1.0)
|
||||
endif()
|
||||
@ -0,0 +1,9 @@
|
||||
Index: vendor/CMakeLists.libandroidfw.txt
|
||||
--- vendor/CMakeLists.libandroidfw.txt.orig
|
||||
+++ vendor/CMakeLists.libandroidfw.txt
|
||||
@@ -1,4 +1,4 @@
|
||||
-add_library(libandroidfw STATIC
|
||||
+add_library(libandroidfw EXCLUDE_FROM_ALL STATIC
|
||||
base/libs/androidfw/ApkAssets.cpp
|
||||
base/libs/androidfw/Asset.cpp
|
||||
base/libs/androidfw/AssetDir.cpp
|
||||
12
devel/adb/patches/patch-vendor_CMakeLists_mke2fs_txt
Normal file
12
devel/adb/patches/patch-vendor_CMakeLists_mke2fs_txt
Normal file
@ -0,0 +1,12 @@
|
||||
Index: vendor/CMakeLists.mke2fs.txt
|
||||
--- vendor/CMakeLists.mke2fs.txt.orig
|
||||
+++ vendor/CMakeLists.mke2fs.txt
|
||||
@@ -130,7 +130,7 @@ target_include_directories("${ANDROID_MKE2FS_NAME}" PR
|
||||
e2fsprogs/lib)
|
||||
|
||||
# fails to build due to https://android-review.googlesource.com/c/platform/system/core/+/2760169
|
||||
-if(NOT APPLE)
|
||||
+if(NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
add_executable(e2fsdroid
|
||||
e2fsprogs/contrib/android/e2fsdroid.c
|
||||
e2fsprogs/contrib/android/basefs_allocator.c
|
||||
50
devel/adb/patches/patch-vendor_CMakeLists_txt
Normal file
50
devel/adb/patches/patch-vendor_CMakeLists_txt
Normal file
@ -0,0 +1,50 @@
|
||||
Index: vendor/CMakeLists.txt
|
||||
--- vendor/CMakeLists.txt.orig
|
||||
+++ vendor/CMakeLists.txt
|
||||
@@ -16,6 +16,17 @@ if(APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DARWIN_C_SOURCE -D__DARWIN_C_LEVEL=__DARWIN_C_FULL")
|
||||
endif()
|
||||
|
||||
+if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE")
|
||||
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_BSD_SOURCE")
|
||||
+ add_compile_definitions(off64_t=off_t lseek64=lseek ftruncate64=ftruncate
|
||||
+ pread64=pread pwrite64=pwrite mmap64=mmap)
|
||||
+ include_directories(BEFORE
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/compat
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/e2fsprogs/lib
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/e2fsprogs/lib/ext2fs)
|
||||
+endif()
|
||||
+
|
||||
# Different versions of clang require a different set of flags for -ftrivial-auto-var-init
|
||||
# Simplify this contruct once old clang version support is dropped
|
||||
include(CheckCXXCompilerFlag)
|
||||
@@ -105,7 +116,9 @@ include(CMakeLists.libandroidfw.txt)
|
||||
include(CMakeLists.adb.txt)
|
||||
include(CMakeLists.sparse.txt)
|
||||
include(CMakeLists.fastboot.txt)
|
||||
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
include(CMakeLists.f2fstools.txt)
|
||||
+endif()
|
||||
include(CMakeLists.mke2fs.txt)
|
||||
include(CMakeLists.partition.txt)
|
||||
include(CMakeLists.mkbootimg.txt)
|
||||
@@ -124,13 +137,15 @@ install(TARGETS
|
||||
lpflash
|
||||
lpmake
|
||||
lpunpack
|
||||
- make_f2fs
|
||||
- sload_f2fs
|
||||
simg2img
|
||||
ext2simg
|
||||
DESTINATION bin)
|
||||
|
||||
-if(NOT APPLE)
|
||||
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
+ install(TARGETS make_f2fs sload_f2fs DESTINATION bin)
|
||||
+endif()
|
||||
+
|
||||
+if(NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
||||
install(TARGETS
|
||||
e2fsdroid
|
||||
DESTINATION bin)
|
||||
63
devel/adb/patches/patch-vendor_adb_client_usb_libusb_cpp
Normal file
63
devel/adb/patches/patch-vendor_adb_client_usb_libusb_cpp
Normal file
@ -0,0 +1,63 @@
|
||||
Index: vendor/adb/client/usb_libusb.cpp
|
||||
--- vendor/adb/client/usb_libusb.cpp.orig
|
||||
+++ vendor/adb/client/usb_libusb.cpp
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
+#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
@@ -1042,7 +1043,50 @@ void usb_init() {
|
||||
LIBUSB_CLASS_PER_INTERFACE, hotplug_callback, nullptr, nullptr);
|
||||
|
||||
if (rc != LIBUSB_SUCCESS) {
|
||||
- LOG(FATAL) << "failed to register libusb hotplug callback";
|
||||
+ LOG(WARNING) << "libusb hotplug not supported (" << libusb_error_name(rc)
|
||||
+ << "), falling back to polling";
|
||||
+ // Spawn a polling thread to detect USB devices without hotplug.
|
||||
+ std::thread([]() {
|
||||
+ adb_thread_setname("libusb poll");
|
||||
+ std::vector<libusb_device*> known;
|
||||
+ for (;;) {
|
||||
+ libusb_device** list = nullptr;
|
||||
+ ssize_t n = libusb_get_device_list(nullptr, &list);
|
||||
+ if (n >= 0) {
|
||||
+ for (ssize_t i = 0; i < n; ++i) {
|
||||
+ libusb_device* dev = list[i];
|
||||
+ if (std::find(known.begin(), known.end(), dev) == known.end()) {
|
||||
+ libusb_ref_device(dev);
|
||||
+ device_connected(dev);
|
||||
+ known.push_back(dev);
|
||||
+ }
|
||||
+ }
|
||||
+ for (auto it = known.begin(); it != known.end(); ) {
|
||||
+ bool present = false;
|
||||
+ for (ssize_t i = 0; i < n; ++i) {
|
||||
+ if (list[i] == *it) { present = true; break; }
|
||||
+ }
|
||||
+ if (!present) {
|
||||
+ device_disconnected(*it);
|
||||
+ libusb_unref_device(*it);
|
||||
+ it = known.erase(it);
|
||||
+ } else {
|
||||
+ ++it;
|
||||
+ }
|
||||
+ }
|
||||
+ libusb_free_device_list(list, 1);
|
||||
+ adb_notify_device_scan_complete();
|
||||
+ }
|
||||
+ std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
+ }
|
||||
+ }).detach();
|
||||
+ std::thread([]() {
|
||||
+ adb_thread_setname("libusb");
|
||||
+ while (true) {
|
||||
+ libusb_handle_events(nullptr);
|
||||
+ }
|
||||
+ }).detach();
|
||||
+ return;
|
||||
}
|
||||
|
||||
// Spawn a thread for libusb_handle_events.
|
||||
26
devel/adb/patches/patch-vendor_adb_sysdeps_h
Normal file
26
devel/adb/patches/patch-vendor_adb_sysdeps_h
Normal file
@ -0,0 +1,26 @@
|
||||
Index: vendor/adb/sysdeps.h
|
||||
--- vendor/adb/sysdeps.h.orig
|
||||
+++ vendor/adb/sysdeps.h
|
||||
@@ -409,6 +409,9 @@ size_t ParseCompleteUTF8(const char* first, const char
|
||||
#include <netinet/tcp.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
+#ifdef __OpenBSD__
|
||||
+#include <pthread_np.h>
|
||||
+#endif
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
@@ -652,6 +655,12 @@ inline int adb_socket_get_local_port(borrowed_fd fd) {
|
||||
static inline int adb_thread_setname(const std::string& name) {
|
||||
#ifdef __APPLE__
|
||||
return pthread_setname_np(name.c_str());
|
||||
+#elif defined(__OpenBSD__)
|
||||
+ char buf[16];
|
||||
+ strncpy(buf, name.c_str(), sizeof(buf) - 1);
|
||||
+ buf[sizeof(buf) - 1] = 0;
|
||||
+ pthread_set_name_np(pthread_self(), buf);
|
||||
+ return 0;
|
||||
#else
|
||||
// Both bionic and glibc's pthread_setname_np fails rather than truncating long strings.
|
||||
// glibc doesn't have strlcpy, so we have to fake it.
|
||||
@ -0,0 +1,15 @@
|
||||
Index: vendor/core/libutils/include/utils/Condition.h
|
||||
--- vendor/core/libutils/include/utils/Condition.h.orig
|
||||
+++ vendor/core/libutils/include/utils/Condition.h
|
||||
@@ -103,9 +103,11 @@ inline Condition::Condition(int type) {
|
||||
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
|
||||
#endif
|
||||
|
||||
+#ifndef __OpenBSD__
|
||||
if (type == SHARED) {
|
||||
pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||
}
|
||||
+#endif
|
||||
|
||||
pthread_cond_init(&mCond, &attr);
|
||||
pthread_condattr_destroy(&attr);
|
||||
@ -0,0 +1,13 @@
|
||||
Index: vendor/core/libutils/include/utils/Mutex.h
|
||||
--- vendor/core/libutils/include/utils/Mutex.h.orig
|
||||
+++ vendor/core/libutils/include/utils/Mutex.h
|
||||
@@ -169,7 +169,9 @@ inline Mutex::Mutex(int type, __attribute__((unused))
|
||||
if (type == SHARED) {
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
+#ifndef __OpenBSD__
|
||||
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||
+#endif
|
||||
pthread_mutex_init(&mMutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
} else {
|
||||
9
devel/adb/patches/patch-vendor_e2fsprogs_lib_config_h
Normal file
9
devel/adb/patches/patch-vendor_e2fsprogs_lib_config_h
Normal file
@ -0,0 +1,9 @@
|
||||
Index: vendor/e2fsprogs/lib/config.h
|
||||
--- vendor/e2fsprogs/lib/config.h.orig
|
||||
+++ vendor/e2fsprogs/lib/config.h
|
||||
@@ -1,4 +1,4 @@
|
||||
-#ifndef __APPLE__
|
||||
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
|
||||
#define HAVE_MALLOC_H 1
|
||||
#endif
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
Index: vendor/extras/libjsonpb/parse/jsonpb.cpp
|
||||
--- vendor/extras/libjsonpb/parse/jsonpb.cpp.orig
|
||||
+++ vendor/extras/libjsonpb/parse/jsonpb.cpp
|
||||
@@ -33,14 +33,14 @@ using google::protobuf::util::TypeResolver;
|
||||
static constexpr char kTypeUrlPrefix[] = "type.googleapis.com";
|
||||
|
||||
std::string GetTypeUrl(const Message& message) {
|
||||
- return std::string(kTypeUrlPrefix) + "/" + message.GetDescriptor()->full_name();
|
||||
+ return std::string(kTypeUrlPrefix) + "/" + std::string(message.GetDescriptor()->full_name());
|
||||
}
|
||||
|
||||
ErrorOr<std::string> MessageToJsonString(const Message& message) {
|
||||
std::unique_ptr<TypeResolver> resolver(
|
||||
NewTypeResolverForDescriptorPool(kTypeUrlPrefix, DescriptorPool::generated_pool()));
|
||||
|
||||
- google::protobuf::util::JsonOptions options;
|
||||
+ google::protobuf::util::JsonPrintOptions options;
|
||||
options.add_whitespace = true;
|
||||
|
||||
std::string json;
|
||||
@ -0,0 +1,15 @@
|
||||
Index: vendor/extras/partition_tools/lpdump.cc
|
||||
--- vendor/extras/partition_tools/lpdump.cc.orig
|
||||
+++ vendor/extras/partition_tools/lpdump.cc
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
#include <getopt.h>
|
||||
#include <inttypes.h>
|
||||
+#include <sys/types.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
-#include <sys/types.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
62
devel/adb/patches/patch-vendor_libbase_file_cpp
Normal file
62
devel/adb/patches/patch-vendor_libbase_file_cpp
Normal file
@ -0,0 +1,62 @@
|
||||
Index: vendor/libbase/file.cpp
|
||||
--- vendor/libbase/file.cpp.orig
|
||||
+++ vendor/libbase/file.cpp
|
||||
@@ -26,6 +26,9 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
+#ifdef __OpenBSD__
|
||||
+#include <sys/sysctl.h>
|
||||
+#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -508,6 +511,48 @@ std::string GetExecutablePath() {
|
||||
return path;
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
abort();
|
||||
+#elif defined(__OpenBSD__)
|
||||
+ // Try /proc/curproc/file if procfs is mounted.
|
||||
+ {
|
||||
+ std::string path;
|
||||
+ if (android::base::Readlink("/proc/curproc/file", &path) && !path.empty()) {
|
||||
+ return path;
|
||||
+ }
|
||||
+ }
|
||||
+ // Fall back to sysctl(KERN_PROC_ARGV) to recover argv[0] and resolve it.
|
||||
+ {
|
||||
+ int mib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV};
|
||||
+ size_t len = 0;
|
||||
+ if (sysctl(mib, 4, nullptr, &len, nullptr, 0) != -1 && len > 0) {
|
||||
+ std::vector<char> buf(len);
|
||||
+ if (sysctl(mib, 4, buf.data(), &len, nullptr, 0) != -1) {
|
||||
+ char* argv0 = reinterpret_cast<char**>(buf.data())[0];
|
||||
+ if (argv0 != nullptr) {
|
||||
+ if (argv0[0] == '/') {
|
||||
+ return argv0; // Already absolute.
|
||||
+ }
|
||||
+ // Search PATH directories for argv0.
|
||||
+ if (const char* path_env = getenv("PATH")) {
|
||||
+ const char* p = path_env;
|
||||
+ while (*p) {
|
||||
+ const char* q = strchr(p, ':');
|
||||
+ size_t dirlen = q ? (size_t)(q - p) : strlen(p);
|
||||
+ std::string full(p, dirlen);
|
||||
+ full += '/';
|
||||
+ full += argv0;
|
||||
+ char resolved[PATH_MAX];
|
||||
+ if (realpath(full.c_str(), resolved) != nullptr) {
|
||||
+ return resolved;
|
||||
+ }
|
||||
+ p += dirlen;
|
||||
+ if (*p == ':') ++p;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return "";
|
||||
#else
|
||||
#error unknown OS
|
||||
#endif
|
||||
@ -0,0 +1,15 @@
|
||||
Index: vendor/libbase/include/android-base/endian.h
|
||||
--- vendor/libbase/include/android-base/endian.h.orig
|
||||
+++ vendor/libbase/include/android-base/endian.h
|
||||
@@ -25,6 +25,11 @@
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
+#elif defined(__OpenBSD__)
|
||||
+#include <sys/endian.h>
|
||||
+#define htonq(x) htobe64(x)
|
||||
+#define ntohq(x) be64toh(x)
|
||||
+
|
||||
#elif defined(__GLIBC__) || defined(ANDROID_HOST_MUSL) || defined(__linux__)
|
||||
|
||||
/* glibc and musl's <endian.h> are like bionic's <sys/endian.h>. */
|
||||
@ -0,0 +1,13 @@
|
||||
Index: vendor/libbase/include/android-base/off64_t.h
|
||||
--- vendor/libbase/include/android-base/off64_t.h.orig
|
||||
+++ vendor/libbase/include/android-base/off64_t.h
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
-#if defined(__APPLE__)
|
||||
-/** Mac OS has always had a 64-bit off_t, so it doesn't have off64_t. */
|
||||
+#if defined(__APPLE__) || defined(__OpenBSD__)
|
||||
+/** Mac OS and OpenBSD have always had a 64-bit off_t, so they don't have off64_t. */
|
||||
typedef off_t off64_t;
|
||||
#endif
|
||||
12
devel/adb/patches/patch-vendor_libbase_logging_cpp
Normal file
12
devel/adb/patches/patch-vendor_libbase_logging_cpp
Normal file
@ -0,0 +1,12 @@
|
||||
Index: vendor/libbase/logging.cpp
|
||||
--- vendor/libbase/logging.cpp.orig
|
||||
+++ vendor/libbase/logging.cpp
|
||||
@@ -62,7 +62,7 @@ namespace android {
|
||||
namespace base {
|
||||
|
||||
// BSD-based systems like Android/macOS have getprogname(). Others need us to provide one.
|
||||
-#if !defined(__APPLE__) && !defined(__BIONIC__)
|
||||
+#if !defined(__APPLE__) && !defined(__BIONIC__) && !defined(__OpenBSD__)
|
||||
static const char* getprogname() {
|
||||
#ifdef _WIN32
|
||||
static bool first = true;
|
||||
12
devel/adb/patches/patch-vendor_libbase_threads_cpp
Normal file
12
devel/adb/patches/patch-vendor_libbase_threads_cpp
Normal file
@ -0,0 +1,12 @@
|
||||
Index: vendor/libbase/threads.cpp
|
||||
--- vendor/libbase/threads.cpp.orig
|
||||
+++ vendor/libbase/threads.cpp
|
||||
@@ -37,6 +37,8 @@ uint64_t GetThreadId() {
|
||||
uint64_t tid;
|
||||
pthread_threadid_np(NULL, &tid);
|
||||
return tid;
|
||||
+#elif defined(__OpenBSD__)
|
||||
+ return (uint64_t)getthrid();
|
||||
#elif defined(__linux__)
|
||||
return syscall(__NR_gettid);
|
||||
#elif defined(_WIN32)
|
||||
@ -0,0 +1,12 @@
|
||||
Index: vendor/logging/liblog/logger_write.cpp
|
||||
--- vendor/logging/liblog/logger_write.cpp.orig
|
||||
+++ vendor/logging/liblog/logger_write.cpp
|
||||
@@ -120,7 +120,7 @@ void __android_log_close() {
|
||||
}
|
||||
|
||||
// BSD-based systems like Android/macOS have getprogname(). Others need us to provide one.
|
||||
-#if !defined(__APPLE__) && !defined(__BIONIC__)
|
||||
+#if !defined(__APPLE__) && !defined(__BIONIC__) && !defined(__OpenBSD__)
|
||||
static const char* getprogname() {
|
||||
#ifdef _WIN32
|
||||
static bool first = true;
|
||||
@ -0,0 +1,13 @@
|
||||
Index: vendor/selinux/libselinux/src/label_file.h
|
||||
--- vendor/selinux/libselinux/src/label_file.h.orig
|
||||
+++ vendor/selinux/libselinux/src/label_file.h
|
||||
@@ -6,7 +6,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
+#ifndef __OpenBSD__
|
||||
#include <sys/xattr.h>
|
||||
+#endif
|
||||
|
||||
/*
|
||||
* regex.h/c were introduced to hold all dependencies on the regular
|
||||
@ -0,0 +1,29 @@
|
||||
Index: vendor/selinux/libsepol/src/private.h
|
||||
--- vendor/selinux/libsepol/src/private.h.orig
|
||||
+++ vendor/selinux/libsepol/src/private.h
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <sepol/policydb/policydb.h>
|
||||
|
||||
|
||||
-#ifdef __APPLE__
|
||||
+#if defined(__APPLE__) || defined(__OpenBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <machine/endian.h>
|
||||
#else
|
||||
@@ -13,9 +13,15 @@
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
+#ifdef __OpenBSD__
|
||||
+#define bswap_16 bswap16
|
||||
+#define bswap_32 bswap32
|
||||
+#define bswap_64 bswap64
|
||||
+#endif
|
||||
+
|
||||
#include <errno.h>
|
||||
|
||||
-#ifdef __APPLE__
|
||||
+#if defined(__APPLE__) || defined(__OpenBSD__)
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#endif
|
||||
2
devel/adb/pkg/DESCR
Normal file
2
devel/adb/pkg/DESCR
Normal file
@ -0,0 +1,2 @@
|
||||
Android Debug Bridge (adb) is a command line tool for communicating with Android
|
||||
emulators and devices.
|
||||
29
devel/adb/pkg/PLIST
Normal file
29
devel/adb/pkg/PLIST
Normal file
@ -0,0 +1,29 @@
|
||||
@bin bin/adb
|
||||
@bin bin/append2simg
|
||||
bin/avbtool
|
||||
@bin bin/ext2simg
|
||||
@bin bin/fastboot
|
||||
@bin bin/img2simg
|
||||
@bin bin/lpadd
|
||||
@bin bin/lpdump
|
||||
@bin bin/lpflash
|
||||
@bin bin/lpmake
|
||||
@bin bin/lpunpack
|
||||
bin/mkbootimg
|
||||
bin/mkdtboimg
|
||||
@bin bin/mke2fs.android
|
||||
bin/repack_bootimg
|
||||
@bin bin/simg2img
|
||||
bin/unpack_bootimg
|
||||
share/android-tools/
|
||||
share/android-tools/completions/
|
||||
share/android-tools/completions/adb
|
||||
share/android-tools/completions/fastboot
|
||||
share/android-tools/mkbootimg/
|
||||
share/android-tools/mkbootimg/gki/
|
||||
share/android-tools/mkbootimg/gki/generate_gki_certificate.py
|
||||
share/android-tools/mkbootimg/mkbootimg.py
|
||||
share/bash-completion/
|
||||
share/bash-completion/completions/
|
||||
share/bash-completion/completions/adb
|
||||
share/bash-completion/completions/fastboot
|
||||
Loading…
x
Reference in New Issue
Block a user