Re-reland "[Support] Move HTTP client/server to new LLVMSupportHTTP lib (NFC)" (#186074)
Relocate HTTPClient and HTTPServer from the Debuginfod library to llvm/Support/HTTP so they can be reused by other components. --------- Relanding with fixes in CMakeLists.txt to account for dependency to new LLVMSupportHTTP in tools. Relanding with one more fix in libSupportHTTP that adds it as a component in libLLVM.so --------- Co-authored-by: Alexandre Ganea <aganea@havenstudios.com> Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
This commit is contained in:
parent
d682325961
commit
5eaf19a151
@ -14,6 +14,7 @@ add_lldb_library(lldbPluginSymbolLocatorDebuginfod PLUGIN
|
||||
lldbHost
|
||||
lldbSymbol
|
||||
LLVMDebuginfod
|
||||
LLVMSupportHTTP
|
||||
)
|
||||
|
||||
add_dependencies(lldbPluginSymbolLocatorDebuginfod
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
#include "lldb/Utility/Log.h"
|
||||
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
||||
@ -20,12 +20,11 @@
|
||||
#ifndef LLVM_DEBUGINFOD_DEBUGINFOD_H
|
||||
#define LLVM_DEBUGINFOD_DEBUGINFOD_H
|
||||
|
||||
#include "HTTPServer.h"
|
||||
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Object/BuildID.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/HTTP/HTTPServer.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Mutex.h"
|
||||
#include "llvm/Support/RWMutex.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//===-- llvm/Support/HTTPClient.h - HTTP client library ---------*- C++ -*-===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -12,8 +12,8 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFOD_HTTPCLIENT_H
|
||||
#define LLVM_DEBUGINFOD_HTTPCLIENT_H
|
||||
#ifndef LLVM_SUPPORT_HTTP_HTTPCLIENT_H
|
||||
#define LLVM_SUPPORT_HTTP_HTTPCLIENT_H
|
||||
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
@ -85,4 +85,4 @@ public:
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_DEBUGINFOD_HTTPCLIENT_H
|
||||
#endif // LLVM_SUPPORT_HTTP_HTTPCLIENT_H
|
||||
@ -1,4 +1,4 @@
|
||||
//===-- llvm/Debuginfod/HTTPServer.h - HTTP server library ------*- C++ -*-===//
|
||||
//===--- HTTPServer.h - HTTP server library ---------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -13,8 +13,8 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFOD_HTTPSERVER_H
|
||||
#define LLVM_DEBUGINFOD_HTTPSERVER_H
|
||||
#ifndef LLVM_SUPPORT_HTTP_HTTPSERVER_H
|
||||
#define LLVM_SUPPORT_HTTP_HTTPSERVER_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
@ -130,4 +130,4 @@ public:
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_DEBUGINFOD_HTTPSERVER_H
|
||||
#endif // LLVM_SUPPORT_HTTP_HTTPSERVER_H
|
||||
@ -1,13 +1,3 @@
|
||||
# Link LibCURL if the user wants it
|
||||
if (LLVM_ENABLE_CURL)
|
||||
set(imported_libs CURL::libcurl)
|
||||
endif()
|
||||
|
||||
# Link cpp-httplib if the user wants it
|
||||
if (LLVM_ENABLE_HTTPLIB)
|
||||
set(imported_libs ${imported_libs} httplib::httplib)
|
||||
endif()
|
||||
|
||||
# Make sure pthread is linked if this is a unix host
|
||||
if (CMAKE_HOST_UNIX)
|
||||
set(imported_libs ${imported_libs} ${LLVM_PTHREAD_LIB})
|
||||
@ -18,8 +8,6 @@ endif()
|
||||
add_llvm_library(LLVMDebuginfod
|
||||
BuildIDFetcher.cpp
|
||||
Debuginfod.cpp
|
||||
HTTPClient.cpp
|
||||
HTTPServer.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${LLVM_MAIN_INCLUDE_DIR}/llvm/Debuginfod
|
||||
@ -29,6 +17,7 @@ add_llvm_library(LLVMDebuginfod
|
||||
|
||||
LINK_COMPONENTS
|
||||
Support
|
||||
SupportHTTP
|
||||
Symbolize
|
||||
DebugInfoDWARF
|
||||
BinaryFormat
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
#include "llvm/BinaryFormat/Magic.h"
|
||||
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
||||
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Object/BuildID.h"
|
||||
#include "llvm/Object/ELFObjectFile.h"
|
||||
#include "llvm/Support/CachePruning.h"
|
||||
@ -35,6 +34,7 @@
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/ThreadPool.h"
|
||||
|
||||
@ -135,6 +135,7 @@ if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
|
||||
endif()
|
||||
|
||||
add_subdirectory(BLAKE3)
|
||||
add_subdirectory(HTTP)
|
||||
|
||||
add_llvm_component_library(LLVMSupport
|
||||
ABIBreak.cpp
|
||||
|
||||
20
llvm/lib/Support/HTTP/CMakeLists.txt
Normal file
20
llvm/lib/Support/HTTP/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# Link LibCURL if the user wants it
|
||||
if (LLVM_ENABLE_CURL)
|
||||
set(imported_libs CURL::libcurl)
|
||||
endif()
|
||||
|
||||
# Link cpp-httplib if the user wants it
|
||||
if (LLVM_ENABLE_HTTPLIB)
|
||||
set(imported_libs ${imported_libs} httplib::httplib)
|
||||
endif()
|
||||
|
||||
add_llvm_component_library(LLVMSupportHTTP
|
||||
HTTPClient.cpp
|
||||
HTTPServer.cpp
|
||||
|
||||
LINK_LIBS
|
||||
${imported_libs}
|
||||
|
||||
LINK_COMPONENTS
|
||||
Support
|
||||
)
|
||||
@ -1,4 +1,4 @@
|
||||
//===-- llvm/Debuginfod/HTTPClient.cpp - HTTP client library ----*- C++ -*-===//
|
||||
//===--- HTTPClient.cpp - HTTP client library -----------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -12,11 +12,13 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#ifdef LLVM_ENABLE_CURL
|
||||
#include <curl/curl.h>
|
||||
@ -39,7 +41,7 @@ class HTTPClientCleanup {
|
||||
public:
|
||||
~HTTPClientCleanup() { HTTPClient::cleanup(); }
|
||||
};
|
||||
static const HTTPClientCleanup Cleanup;
|
||||
ManagedStatic<HTTPClientCleanup> Cleanup;
|
||||
|
||||
#ifdef LLVM_ENABLE_CURL
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//===-- llvm/Debuginfod/HTTPServer.cpp - HTTP server library -----*- C++-*-===//
|
||||
//===--- HTTPServer.cpp - HTTP server library -----------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -13,7 +13,8 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debuginfod/HTTPServer.h"
|
||||
#include "llvm/Support/HTTP/HTTPServer.h"
|
||||
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Errc.h"
|
||||
@ -187,12 +188,8 @@ Expected<unsigned> HTTPServer::bind(const char *HostInterface) {
|
||||
return make_error<HTTPServerError>("no httplib");
|
||||
}
|
||||
|
||||
Error HTTPServer::listen() {
|
||||
return make_error<HTTPServerError>("no httplib");
|
||||
}
|
||||
Error HTTPServer::listen() { return make_error<HTTPServerError>("no httplib"); }
|
||||
|
||||
void HTTPServer::stop() {
|
||||
llvm_unreachable("no httplib");
|
||||
}
|
||||
void HTTPServer::stop() { llvm_unreachable("no httplib"); }
|
||||
|
||||
#endif // LLVM_ENABLE_HTTPLIB
|
||||
@ -1,6 +1,7 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
Core
|
||||
Support
|
||||
SupportHTTP
|
||||
Object
|
||||
Coverage
|
||||
ProfileData
|
||||
|
||||
@ -24,13 +24,13 @@
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Debuginfod/BuildIDFetcher.h"
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Object/BuildID.h"
|
||||
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
|
||||
#include "llvm/ProfileData/InstrProfReader.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
|
||||
@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
Option
|
||||
Object
|
||||
Support
|
||||
SupportHTTP
|
||||
)
|
||||
set(LLVM_TARGET_DEFINITIONS Opts.td)
|
||||
tablegen(LLVM Opts.inc -gen-opt-parser-defs)
|
||||
|
||||
@ -19,10 +19,10 @@
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Debuginfod/BuildIDFetcher.h"
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
Option
|
||||
Support
|
||||
SupportHTTP
|
||||
)
|
||||
set(LLVM_TARGET_DEFINITIONS Opts.td)
|
||||
tablegen(LLVM Opts.inc -gen-opt-parser-defs)
|
||||
|
||||
@ -18,10 +18,10 @@
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/ThreadPool.h"
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
Object
|
||||
Option
|
||||
Support
|
||||
SupportHTTP
|
||||
Symbolize
|
||||
TargetParser
|
||||
)
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
|
||||
#include "llvm/Debuginfod/BuildIDFetcher.h"
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Demangle/Demangle.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
@ -66,6 +65,7 @@
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
|
||||
@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
Object
|
||||
ProfileData
|
||||
Support
|
||||
SupportHTTP
|
||||
)
|
||||
|
||||
add_llvm_tool(llvm-profdata
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/Object/Binary.h"
|
||||
#include "llvm/ProfileData/DataAccessProf.h"
|
||||
@ -35,6 +34,7 @@
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/MD5.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
@ -12,6 +12,7 @@ set(LLVM_LINK_COMPONENTS
|
||||
Object
|
||||
Option
|
||||
Support
|
||||
SupportHTTP
|
||||
Symbolize
|
||||
)
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
|
||||
#include "llvm/Debuginfod/BuildIDFetcher.h"
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Option/Arg.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
@ -34,6 +33,7 @@
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/StringSaver.h"
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
add_llvm_unittest(DebuginfodTests
|
||||
HTTPServerTests.cpp
|
||||
DebuginfodTests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(DebuginfodTests PRIVATE
|
||||
LLVMDebuginfod
|
||||
LLVMSupportHTTP
|
||||
LLVMTestingSupport
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
//===-- llvm/unittest/Support/DebuginfodTests.cpp - unit tests ------------===//
|
||||
//===--- DebuginfodTests.cpp - unit tests ---------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -7,8 +7,8 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debuginfod/Debuginfod.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -128,6 +128,7 @@ add_llvm_unittest(SupportTests
|
||||
intrinsics_gen
|
||||
)
|
||||
|
||||
add_subdirectory(HTTP)
|
||||
add_subdirectory(LSP)
|
||||
|
||||
target_link_libraries(SupportTests PRIVATE LLVMTestingSupport)
|
||||
|
||||
8
llvm/unittests/Support/HTTP/CMakeLists.txt
Normal file
8
llvm/unittests/Support/HTTP/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
add_llvm_unittest(SupportHTTPTests
|
||||
HTTPServerTests.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(SupportHTTPTests PRIVATE
|
||||
LLVMSupportHTTP
|
||||
LLVMTestingSupport
|
||||
)
|
||||
@ -1,4 +1,4 @@
|
||||
//===-- llvm/unittest/Support/HTTPServer.cpp - unit tests -------*- C++ -*-===//
|
||||
//===-- HTTPServerTests.cpp - unit tests ----------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
@ -7,9 +7,9 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Debuginfod/HTTPClient.h"
|
||||
#include "llvm/Debuginfod/HTTPServer.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/HTTP/HTTPClient.h"
|
||||
#include "llvm/Support/HTTP/HTTPServer.h"
|
||||
#include "llvm/Support/ThreadPool.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
#include "gmock/gmock.h"
|
||||
@ -237,15 +237,15 @@ TEST_F(HTTPClientServerTest, ClientTimeout) {
|
||||
TEST_F(HTTPClientServerTest, PathMatching) {
|
||||
HTTPServer Server;
|
||||
|
||||
EXPECT_THAT_ERROR(
|
||||
Server.get(R"(/abc/(.*)/(.*))",
|
||||
[&](HTTPServerRequest &Request) {
|
||||
EXPECT_EQ(Request.UrlPath, "/abc/1/2");
|
||||
ASSERT_THAT(Request.UrlPathMatches,
|
||||
testing::ElementsAre("1", "2"));
|
||||
Request.setResponse({200u, "text/plain", Request.UrlPath});
|
||||
}),
|
||||
Succeeded());
|
||||
EXPECT_THAT_ERROR(Server.get(R"(/abc/(.*)/(.*))",
|
||||
[&](HTTPServerRequest &Request) {
|
||||
EXPECT_EQ(Request.UrlPath, "/abc/1/2");
|
||||
ASSERT_THAT(Request.UrlPathMatches,
|
||||
testing::ElementsAre("1", "2"));
|
||||
Request.setResponse(
|
||||
{200u, "text/plain", Request.UrlPath});
|
||||
}),
|
||||
Succeeded());
|
||||
EXPECT_THAT_ERROR(Server.get(UrlPathPattern,
|
||||
[&](HTTPServerRequest &Request) {
|
||||
llvm_unreachable(
|
||||
Loading…
x
Reference in New Issue
Block a user