diff --git a/devel/adb/Makefile b/devel/adb/Makefile new file mode 100644 index 0000000..0a49ca4 --- /dev/null +++ b/devel/adb/Makefile @@ -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 \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 \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 \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 diff --git a/devel/adb/distinfo b/devel/adb/distinfo new file mode 100644 index 0000000..9052053 --- /dev/null +++ b/devel/adb/distinfo @@ -0,0 +1,2 @@ +SHA256 (android-tools-35.0.1.tar.xz) = UNnnzoljfQ4vNkWMoqO6P0O/GWnz+izYwO72ig4XutE= +SIZE (android-tools-35.0.1.tar.xz) = 21841324 diff --git a/devel/adb/files/adb_usb_openbsd.cpp b/devel/adb/files/adb_usb_openbsd.cpp new file mode 100644 index 0000000..eeaee52 --- /dev/null +++ b/devel/adb/files/adb_usb_openbsd.cpp @@ -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 + +#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; } diff --git a/devel/adb/files/fastboot_usb_libusb.cpp b/devel/adb/files/fastboot_usb_libusb.cpp new file mode 100644 index 0000000..67093a9 --- /dev/null +++ b/devel/adb/files/fastboot_usb_libusb.cpp @@ -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 +#include +#include +#include + +#include +#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(data), + static_cast(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( + reinterpret_cast(data)), + static_cast(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 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 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(info.serial_number), + sizeof(info.serial_number)); + } + if (id->iInterface) { + libusb_get_string_descriptor_ascii( + h, id->iInterface, + reinterpret_cast(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( + 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; +} diff --git a/devel/adb/patches/patch-vendor_CMakeLists_adb_txt b/devel/adb/patches/patch-vendor_CMakeLists_adb_txt new file mode 100644 index 0000000..2796e53 --- /dev/null +++ b/devel/adb/patches/patch-vendor_CMakeLists_adb_txt @@ -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) diff --git a/devel/adb/patches/patch-vendor_CMakeLists_fastboot_txt b/devel/adb/patches/patch-vendor_CMakeLists_fastboot_txt new file mode 100644 index 0000000..ec70bae --- /dev/null +++ b/devel/adb/patches/patch-vendor_CMakeLists_fastboot_txt @@ -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() diff --git a/devel/adb/patches/patch-vendor_CMakeLists_libandroidfw_txt b/devel/adb/patches/patch-vendor_CMakeLists_libandroidfw_txt new file mode 100644 index 0000000..57d08df --- /dev/null +++ b/devel/adb/patches/patch-vendor_CMakeLists_libandroidfw_txt @@ -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 diff --git a/devel/adb/patches/patch-vendor_CMakeLists_mke2fs_txt b/devel/adb/patches/patch-vendor_CMakeLists_mke2fs_txt new file mode 100644 index 0000000..24cde47 --- /dev/null +++ b/devel/adb/patches/patch-vendor_CMakeLists_mke2fs_txt @@ -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 diff --git a/devel/adb/patches/patch-vendor_CMakeLists_txt b/devel/adb/patches/patch-vendor_CMakeLists_txt new file mode 100644 index 0000000..42b4c4a --- /dev/null +++ b/devel/adb/patches/patch-vendor_CMakeLists_txt @@ -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) diff --git a/devel/adb/patches/patch-vendor_adb_client_usb_libusb_cpp b/devel/adb/patches/patch-vendor_adb_client_usb_libusb_cpp new file mode 100644 index 0000000..02f7a96 --- /dev/null +++ b/devel/adb/patches/patch-vendor_adb_client_usb_libusb_cpp @@ -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 + #endif + ++#include + #include + #include + #include +@@ -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 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. diff --git a/devel/adb/patches/patch-vendor_adb_sysdeps_h b/devel/adb/patches/patch-vendor_adb_sysdeps_h new file mode 100644 index 0000000..4c2030a --- /dev/null +++ b/devel/adb/patches/patch-vendor_adb_sysdeps_h @@ -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 + #include + #include ++#ifdef __OpenBSD__ ++#include ++#endif + #include + #include + #include +@@ -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. diff --git a/devel/adb/patches/patch-vendor_core_libutils_include_utils_Condition_h b/devel/adb/patches/patch-vendor_core_libutils_include_utils_Condition_h new file mode 100644 index 0000000..3ba8b06 --- /dev/null +++ b/devel/adb/patches/patch-vendor_core_libutils_include_utils_Condition_h @@ -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); diff --git a/devel/adb/patches/patch-vendor_core_libutils_include_utils_Mutex_h b/devel/adb/patches/patch-vendor_core_libutils_include_utils_Mutex_h new file mode 100644 index 0000000..94b2075 --- /dev/null +++ b/devel/adb/patches/patch-vendor_core_libutils_include_utils_Mutex_h @@ -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 { diff --git a/devel/adb/patches/patch-vendor_e2fsprogs_lib_config_h b/devel/adb/patches/patch-vendor_e2fsprogs_lib_config_h new file mode 100644 index 0000000..07424d0 --- /dev/null +++ b/devel/adb/patches/patch-vendor_e2fsprogs_lib_config_h @@ -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 + diff --git a/devel/adb/patches/patch-vendor_extras_libjsonpb_parse_jsonpb_cpp b/devel/adb/patches/patch-vendor_extras_libjsonpb_parse_jsonpb_cpp new file mode 100644 index 0000000..a714545 --- /dev/null +++ b/devel/adb/patches/patch-vendor_extras_libjsonpb_parse_jsonpb_cpp @@ -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 MessageToJsonString(const Message& message) { + std::unique_ptr resolver( + NewTypeResolverForDescriptorPool(kTypeUrlPrefix, DescriptorPool::generated_pool())); + +- google::protobuf::util::JsonOptions options; ++ google::protobuf::util::JsonPrintOptions options; + options.add_whitespace = true; + + std::string json; diff --git a/devel/adb/patches/patch-vendor_extras_partition_tools_lpdump_cc b/devel/adb/patches/patch-vendor_extras_partition_tools_lpdump_cc new file mode 100644 index 0000000..a30db01 --- /dev/null +++ b/devel/adb/patches/patch-vendor_extras_partition_tools_lpdump_cc @@ -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 + #include ++#include + #include + #include + #include +-#include + #include + #include + diff --git a/devel/adb/patches/patch-vendor_libbase_file_cpp b/devel/adb/patches/patch-vendor_libbase_file_cpp new file mode 100644 index 0000000..358189e --- /dev/null +++ b/devel/adb/patches/patch-vendor_libbase_file_cpp @@ -0,0 +1,62 @@ +Index: vendor/libbase/file.cpp +--- vendor/libbase/file.cpp.orig ++++ vendor/libbase/file.cpp +@@ -26,6 +26,9 @@ + #include + #include + #include ++#ifdef __OpenBSD__ ++#include ++#endif + #include + + #include +@@ -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 buf(len); ++ if (sysctl(mib, 4, buf.data(), &len, nullptr, 0) != -1) { ++ char* argv0 = reinterpret_cast(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 diff --git a/devel/adb/patches/patch-vendor_libbase_include_android-base_endian_h b/devel/adb/patches/patch-vendor_libbase_include_android-base_endian_h new file mode 100644 index 0000000..7dd4406 --- /dev/null +++ b/devel/adb/patches/patch-vendor_libbase_include_android-base_endian_h @@ -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 + ++#elif defined(__OpenBSD__) ++#include ++#define htonq(x) htobe64(x) ++#define ntohq(x) be64toh(x) ++ + #elif defined(__GLIBC__) || defined(ANDROID_HOST_MUSL) || defined(__linux__) + + /* glibc and musl's are like bionic's . */ diff --git a/devel/adb/patches/patch-vendor_libbase_include_android-base_off64_t_h b/devel/adb/patches/patch-vendor_libbase_include_android-base_off64_t_h new file mode 100644 index 0000000..a15f19b --- /dev/null +++ b/devel/adb/patches/patch-vendor_libbase_include_android-base_off64_t_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 diff --git a/devel/adb/patches/patch-vendor_libbase_logging_cpp b/devel/adb/patches/patch-vendor_libbase_logging_cpp new file mode 100644 index 0000000..e69b92d --- /dev/null +++ b/devel/adb/patches/patch-vendor_libbase_logging_cpp @@ -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; diff --git a/devel/adb/patches/patch-vendor_libbase_threads_cpp b/devel/adb/patches/patch-vendor_libbase_threads_cpp new file mode 100644 index 0000000..fd5b982 --- /dev/null +++ b/devel/adb/patches/patch-vendor_libbase_threads_cpp @@ -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) diff --git a/devel/adb/patches/patch-vendor_logging_liblog_logger_write_cpp b/devel/adb/patches/patch-vendor_logging_liblog_logger_write_cpp new file mode 100644 index 0000000..79fd210 --- /dev/null +++ b/devel/adb/patches/patch-vendor_logging_liblog_logger_write_cpp @@ -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; diff --git a/devel/adb/patches/patch-vendor_selinux_libselinux_src_label_file_h b/devel/adb/patches/patch-vendor_selinux_libselinux_src_label_file_h new file mode 100644 index 0000000..9b7f1d3 --- /dev/null +++ b/devel/adb/patches/patch-vendor_selinux_libselinux_src_label_file_h @@ -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 + + #include ++#ifndef __OpenBSD__ + #include ++#endif + + /* + * regex.h/c were introduced to hold all dependencies on the regular diff --git a/devel/adb/patches/patch-vendor_selinux_libsepol_src_private_h b/devel/adb/patches/patch-vendor_selinux_libsepol_src_private_h new file mode 100644 index 0000000..f5dc4c2 --- /dev/null +++ b/devel/adb/patches/patch-vendor_selinux_libsepol_src_private_h @@ -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 + + +-#ifdef __APPLE__ ++#if defined(__APPLE__) || defined(__OpenBSD__) + #include + #include + #else +@@ -13,9 +13,15 @@ + #include + #endif + ++#ifdef __OpenBSD__ ++#define bswap_16 bswap16 ++#define bswap_32 bswap32 ++#define bswap_64 bswap64 ++#endif ++ + #include + +-#ifdef __APPLE__ ++#if defined(__APPLE__) || defined(__OpenBSD__) + #define __BYTE_ORDER BYTE_ORDER + #define __LITTLE_ENDIAN LITTLE_ENDIAN + #endif diff --git a/devel/adb/pkg/DESCR b/devel/adb/pkg/DESCR new file mode 100644 index 0000000..dc33e89 --- /dev/null +++ b/devel/adb/pkg/DESCR @@ -0,0 +1,2 @@ +Android Debug Bridge (adb) is a command line tool for communicating with Android +emulators and devices. diff --git a/devel/adb/pkg/PLIST b/devel/adb/pkg/PLIST new file mode 100644 index 0000000..ba9c0b9 --- /dev/null +++ b/devel/adb/pkg/PLIST @@ -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