VoidBuildSystem CI / 1 · Requirements (push) Successful in 6s
VoidBuildSystem CI / 2C · Windows native build (debug) (push) Failing after 1m32s
VoidBuildSystem CI / 2C · Windows native build (sanitizers) (push) Failing after 18s
VoidBuildSystem CI / 2C · Windows native build (relwithdebinfo) (push) Failing after 3m4s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 6m20s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 6m32s
VoidBuildSystem CI / 3C · Windows native test (debug) (push) Failing after 1m45s
VoidBuildSystem CI / 2B · Windows Wine build (sanitizers) (push) Successful in 6m55s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 6m59s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 6m59s
VoidBuildSystem CI / 3C · Windows native test (sanitizers) (push) Failing after 15s
VoidBuildSystem CI / 3C · Windows native test (relwithdebinfo) (push) Failing after 1m47s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m4s
VoidBuildSystem CI / 4B · Windows package (debug) (push) Successful in 1m6s
VoidBuildSystem CI / 4B · Windows package (sanitizers) (push) Successful in 12s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m2s
VoidBuildSystem CI / 4B · Windows package (relwithdebinfo) (push) Successful in 1m44s
VoidBuildSystem CI / 3B · Windows Wine test (sanitizers) (push) Successful in 3m16s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 3m21s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m45s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m54s
VoidBuildSystem CI / 4A · Linux package (debug) (push) Skipped
VoidBuildSystem CI / 4A · Linux package (relwithdebinfo) (push) Skipped
VoidBuildSystem CI / 4A · Linux package (sanitizers) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 3m42s
Bump VoidLibrary to 482a3ea (Windows target support: qualified Configuration/Crypto/System/Archive, Windows DirectoryWatcher, TempDir/TempFile, process pipes) and port VBS's own host backends: - Toolchain: Windows/macOS host names and architectures without uname. - Platform FileOps: Win32 stat metadata, CreateFileW+LockFileEx file locks (Void FileLock is POSIX-only, Void/Library#66), no-op directory fsync, GetModuleFileNameW executable path, mtime via std::filesystem, and a file-copy fallback for the compdb alias. - ProcessSupervisor: Windows PATH/PATHEXT resolution and no POSIX waitpid reaping (job objects own descendants). - Snapshot: directory listing through std::filesystem on Windows. - Remote cache/registry client/CDash: curl or Winsock-based HTTP on Windows (Void::Net is not qualified there yet). - Daemon: explicit unsupported errors on Windows (named-pipe transport is Track C3); the registry service stays POSIX-only and is excluded from the Windows build. - StateStore/Sbom/Main/Graph: portable stat, time and path handling. Verified: MinGW-w64 GCC 16.2 builds vbs, vbs_describe, vbs_benchmarks and the sdk/core/v1/selfhost test executables; vbs runs under Wine and the SDK suite passes 17/17. The Linux suite stays green (8/8).
315 lines
12 KiB
C++
315 lines
12 KiB
C++
#include <Void/Build/Report/Cdash.hpp>
|
|
|
|
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
|
#include <Void/Core/Scope.hpp>
|
|
#include <Void/System/Types.hpp>
|
|
#include <Void/Text/Str.hpp>
|
|
#include <Void/Text/Url.hpp>
|
|
|
|
#include <array>
|
|
#include <cerrno>
|
|
#include <chrono>
|
|
#include <cstdio>
|
|
#include <ctime>
|
|
#include <format>
|
|
#if defined(_WIN32)
|
|
#include <windows.h>
|
|
#else
|
|
#include <netdb.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#if defined(VBS_HAS_VOID_NET)
|
|
#include <Void/Net/Http.hpp>
|
|
#endif
|
|
|
|
namespace Void::Build::Report {
|
|
namespace {
|
|
|
|
Void::Result::Error make_error(std::string msg) {
|
|
return Void::System::make_system_error(Void::System::SystemErrorCode::invalid_argument,
|
|
std::move(msg));
|
|
}
|
|
|
|
std::string xml_escape(std::string_view text) {
|
|
std::string out;
|
|
out.reserve(text.size());
|
|
for (const char c : text) {
|
|
switch (c) {
|
|
case '&':
|
|
out += "&";
|
|
break;
|
|
case '<':
|
|
out += "<";
|
|
break;
|
|
case '>':
|
|
out += ">";
|
|
break;
|
|
case '"':
|
|
out += """;
|
|
break;
|
|
case '\'':
|
|
out += "'";
|
|
break;
|
|
default:
|
|
if (static_cast<unsigned char>(c) >= 0x20 || c == '\n' || c == '\t') {
|
|
out.push_back(c);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
std::string utc_timestamp() {
|
|
const auto now = std::chrono::system_clock::now();
|
|
const std::time_t seconds = std::chrono::system_clock::to_time_t(now);
|
|
std::tm tm{};
|
|
#if defined(_WIN32)
|
|
::gmtime_s(&tm, &seconds);
|
|
#else
|
|
::gmtime_r(&seconds, &tm);
|
|
#endif
|
|
return std::format("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}", tm.tm_year + 1900,
|
|
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
}
|
|
|
|
std::string host_name() {
|
|
#if defined(_WIN32)
|
|
char buffer[256]{};
|
|
DWORD size = static_cast<DWORD>(sizeof(buffer) - 1);
|
|
if (::GetComputerNameA(buffer, &size) != 0) {
|
|
return buffer;
|
|
}
|
|
return "localhost";
|
|
#else
|
|
char buffer[256]{};
|
|
if (::gethostname(buffer, sizeof(buffer) - 1) == 0) {
|
|
return buffer;
|
|
}
|
|
return "localhost";
|
|
#endif
|
|
}
|
|
|
|
} // namespace
|
|
|
|
std::string render_cdash_test_xml(const CdashReportOptions &options) {
|
|
const std::string site = options.site_name.empty() ? host_name() : options.site_name;
|
|
const std::string timestamp = utc_timestamp();
|
|
std::string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
|
xml += std::format("<Site BuildName=\"{}\" BuildStamp=\"{}\" Name=\"{}\" Generator=\"{}\" "
|
|
"OperatingSystem=\"{}\" Hostname=\"{}\">\n",
|
|
xml_escape(options.build_name), xml_escape(options.build_stamp),
|
|
xml_escape(site), xml_escape(options.generator), xml_escape(options.os_name),
|
|
xml_escape(site));
|
|
xml += " <Testing>\n";
|
|
xml += " <StartDateTime>" + timestamp + "</StartDateTime>\n";
|
|
xml += " <StartTestTime>0</StartTestTime>\n";
|
|
xml += " <TestList>\n";
|
|
for (const auto &test : options.tests) {
|
|
xml += std::format(" <Test Status=\"{}\">\n", test.passed ? "passed" : "failed");
|
|
xml += " <Name>" + xml_escape(test.name) + "</Name>\n";
|
|
xml += " <Path>.</Path>\n";
|
|
xml += " <FullName>" + xml_escape(test.name) + "</FullName>\n";
|
|
xml += " <Command>vbs-test</Command>\n";
|
|
xml += " <WorkingDirectory>.</WorkingDirectory>\n";
|
|
xml += " <Output>" + xml_escape(test.output) + "</Output>\n";
|
|
xml += " <Result>" + std::string{test.passed ? "passed" : "failed"} + "</Result>\n";
|
|
xml += std::format(" <ElapsedTime>{:.3f}</ElapsedTime>\n", test.elapsed_seconds);
|
|
xml += " </Test>\n";
|
|
}
|
|
xml += " </TestList>\n";
|
|
xml += " <EndDateTime>" + timestamp + "</EndDateTime>\n";
|
|
xml += " <EndTestTime>0</EndTestTime>\n";
|
|
xml += " <ElapsedMinutes>0</ElapsedMinutes>\n";
|
|
xml += " </Testing>\n";
|
|
xml += "</Site>\n";
|
|
return xml;
|
|
}
|
|
|
|
CdashSubmission build_cdash_submission(const CdashReportOptions &options,
|
|
std::string_view project) {
|
|
constexpr std::string_view boundary = "vbs-cdash-boundary";
|
|
const std::string xml = render_cdash_test_xml(options);
|
|
CdashSubmission submission;
|
|
submission.content_type = std::format("multipart/form-data; boundary={}", boundary);
|
|
const auto add_field = [&](std::string_view name, std::string_view value) {
|
|
submission.body += "--" + std::string{boundary} + "\r\n";
|
|
submission.body +=
|
|
"Content-Disposition: form-data; name=\"" + std::string{name} + "\"\r\n\r\n";
|
|
submission.body += value;
|
|
submission.body += "\r\n";
|
|
};
|
|
add_field("type", "Test");
|
|
add_field("project", project);
|
|
add_field("build", options.build_name);
|
|
submission.body += "--" + std::string{boundary} + "\r\n";
|
|
submission.body +=
|
|
"Content-Disposition: form-data; name=\"content\"; filename=\"Test.xml\"\r\n";
|
|
submission.body += "Content-Type: text/xml\r\n\r\n";
|
|
submission.body += xml;
|
|
submission.body += "\r\n--" + std::string{boundary} + "--\r\n";
|
|
return submission;
|
|
}
|
|
|
|
Void::Result::Result<void, Void::Result::Error>
|
|
submit_cdash_report(std::string_view cdash_url, std::string_view project,
|
|
const CdashReportOptions &options) {
|
|
// Parse scheme://host[:port][/base].
|
|
std::string url{cdash_url};
|
|
while (!url.empty() && url.back() == '/') {
|
|
url.pop_back();
|
|
}
|
|
std::string scheme = "http";
|
|
if (const auto scheme_end = url.find("://"); scheme_end != std::string::npos) {
|
|
scheme = url.substr(0, scheme_end);
|
|
url.erase(0, scheme_end + 3);
|
|
}
|
|
if (scheme != "http" && scheme != "https") {
|
|
return std::unexpected{make_error("CDash URL must be http:// or https://")};
|
|
}
|
|
std::string host_port = url;
|
|
std::string base_path;
|
|
if (const auto slash = url.find('/'); slash != std::string::npos) {
|
|
host_port = url.substr(0, slash);
|
|
base_path = url.substr(slash);
|
|
}
|
|
std::string host = host_port;
|
|
std::string port = scheme == "https" ? "443" : "80";
|
|
if (const auto colon = host_port.rfind(':'); colon != std::string::npos) {
|
|
host = host_port.substr(0, colon);
|
|
port = host_port.substr(colon + 1);
|
|
}
|
|
const auto submission = build_cdash_submission(options, project);
|
|
const std::string path =
|
|
base_path + "/submit.php?project=" + Void::Encoding::Url::encode(project);
|
|
|
|
#if defined(VBS_HAS_VOID_NET)
|
|
Void::Net::Request request;
|
|
request.method = Void::Net::Method::Post;
|
|
request.url = std::format("{}://{}:{}{}", scheme, host, port, path);
|
|
request.headers.push_back(Void::Net::Header{"Content-Type", submission.content_type});
|
|
request.body = submission.body;
|
|
request.timeout = std::chrono::seconds{30};
|
|
const Void::Net::HttpClient client = Void::Net::HttpClient::secure();
|
|
auto response = client.send(request);
|
|
if (!response) {
|
|
return std::unexpected{
|
|
make_error(std::format("CDash submission failed: {}", response.error().message()))};
|
|
}
|
|
if (response->status < 200 || response->status >= 300) {
|
|
return std::unexpected{
|
|
make_error(std::format("CDash submission rejected with HTTP {}: {}", response->status,
|
|
response->body.substr(0, 200)))};
|
|
}
|
|
return {};
|
|
#else
|
|
#if defined(_WIN32)
|
|
// Windows: curl performs the submission for http and https (Void::Net not linked).
|
|
auto curl = Platform::resolve_executable("curl");
|
|
if (!curl) {
|
|
return std::unexpected{make_error(
|
|
"CDash submission on Windows requires curl (Void::Net not linked)")};
|
|
}
|
|
Platform::ProcessRequest req;
|
|
req.executable = *curl;
|
|
req.arguments = {"--silent",
|
|
"--show-error",
|
|
"-X",
|
|
"POST",
|
|
"-H",
|
|
"Content-Type: " + submission.content_type,
|
|
"--data-binary",
|
|
"@-",
|
|
"-w",
|
|
"\n%{http_code}",
|
|
std::format("{}://{}:{}{}", scheme, host, port, path)};
|
|
req.stdin_data = submission.body;
|
|
req.timeout = std::chrono::seconds{60};
|
|
auto proc = Platform::run_supervised(req);
|
|
if (!proc || !proc->succeeded()) {
|
|
return std::unexpected{make_error(std::format(
|
|
"CDash submission failed: {}",
|
|
proc ? proc->stderr_data : proc.error().message()))};
|
|
}
|
|
int status = 0;
|
|
if (const auto nl = proc->stdout_data.rfind('\n'); nl != std::string::npos) {
|
|
(void)Void::Str::to_int(Void::Str::trim_ascii(proc->stdout_data.substr(nl + 1)), status);
|
|
}
|
|
if (status < 200 || status >= 300) {
|
|
return std::unexpected{
|
|
make_error(std::format("CDash submission rejected with HTTP {}", status))};
|
|
}
|
|
return {};
|
|
#else
|
|
// Plain TCP HTTP/1.1 POST for http:// (Void::Net server transport not linked).
|
|
if (scheme != "http") {
|
|
return std::unexpected{
|
|
make_error("HTTPS CDash submission requires the Void::Net HTTP client")};
|
|
}
|
|
struct addrinfo hints{};
|
|
hints.ai_family = AF_INET;
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
struct addrinfo *resolved = nullptr;
|
|
if (::getaddrinfo(host.c_str(), port.c_str(), &hints, &resolved) != 0 || resolved == nullptr) {
|
|
return std::unexpected{
|
|
make_error(std::format("CDash submission: cannot resolve host '{}'", host))};
|
|
}
|
|
auto free_ai = Void::Scope::on_exit([&] { ::freeaddrinfo(resolved); });
|
|
const int fd =
|
|
::socket(resolved->ai_family, resolved->ai_socktype | SOCK_CLOEXEC, resolved->ai_protocol);
|
|
if (fd < 0) {
|
|
return std::unexpected{make_error("CDash submission: socket() failed")};
|
|
}
|
|
Void::System::OwnedFd guard{fd};
|
|
struct timeval tv{30, 0};
|
|
(void)::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
|
(void)::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
|
if (::connect(fd, resolved->ai_addr, resolved->ai_addrlen) != 0) {
|
|
return std::unexpected{
|
|
make_error(std::format("CDash submission: connect to {}:{} failed", host, port))};
|
|
}
|
|
std::string request =
|
|
std::format("POST {} HTTP/1.1\r\nHost: {}:{}\r\nConnection: close\r\n"
|
|
"Content-Type: {}\r\nContent-Length: {}\r\n\r\n",
|
|
path, host, port, submission.content_type, submission.body.size());
|
|
request += submission.body;
|
|
std::size_t sent = 0;
|
|
while (sent < request.size()) {
|
|
const ssize_t n = ::send(fd, request.data() + sent, request.size() - sent, MSG_NOSIGNAL);
|
|
if (n < 0) {
|
|
if (errno == EINTR) {
|
|
continue;
|
|
}
|
|
return std::unexpected{make_error("CDash submission: send() failed")};
|
|
}
|
|
sent += static_cast<std::size_t>(n);
|
|
}
|
|
std::string raw;
|
|
std::array<char, 16384> buffer{};
|
|
for (;;) {
|
|
const ssize_t n = ::recv(fd, buffer.data(), buffer.size(), 0);
|
|
if (n > 0) {
|
|
raw.append(buffer.data(), static_cast<std::size_t>(n));
|
|
} else if (n == 0) {
|
|
break;
|
|
} else if (errno != EINTR) {
|
|
return std::unexpected{make_error("CDash submission: recv() failed")};
|
|
}
|
|
}
|
|
int status = 0;
|
|
if (const auto sp = raw.find(' '); sp != std::string::npos) {
|
|
(void)Void::Str::to_int(std::string_view{raw}.substr(sp + 1, 3), status);
|
|
}
|
|
if (status < 200 || status >= 300) {
|
|
return std::unexpected{
|
|
make_error(std::format("CDash submission rejected with HTTP {}", status))};
|
|
}
|
|
return {};
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
} // namespace Void::Build::Report
|