feat(platform): build on native Windows hosts
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
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).
This commit is contained in:
1 parent
8768720e54
commit
e333bbe84b
23 files changed
+715
-127
No files matched your search
@@ -3,16 +3,23 @@
|
||||
#include <Void/System/Types.hpp>
|
||||
|
||||
#include <cerrno>
|
||||
#include <fcntl.h>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <set>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
|
||||
#if !defined(__linux__)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !defined(__linux__) && !defined(_WIN32)
|
||||
#error \
|
||||
"VoidBuildSystem's process and file backends currently support Linux hosts only (Track C2/C3 ports are planned)"
|
||||
"VoidBuildSystem's process and file backends currently support Linux and Windows hosts only (Track C2/C3 ports are planned)"
|
||||
#endif
|
||||
|
||||
namespace Void::Build::Platform {
|
||||
@@ -36,6 +43,44 @@ FileLock::acquire(const std::filesystem::path &lock_path, LockMode mode, bool no
|
||||
lock_path.string(), ec.message()))};
|
||||
}
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
// Void::FileSystem::FileLock is POSIX-only (Void/Library issue #66).
|
||||
const HANDLE raw = ::CreateFileW(lock_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (raw == INVALID_HANDLE_VALUE) {
|
||||
const DWORD err = ::GetLastError();
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("FileLock: cannot open '{}' (error {})", lock_path.string(), err),
|
||||
static_cast<int>(err))};
|
||||
}
|
||||
OVERLAPPED overlapped{};
|
||||
DWORD flags = mode == LockMode::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
|
||||
if (non_blocking) {
|
||||
flags |= LOCKFILE_FAIL_IMMEDIATELY;
|
||||
}
|
||||
if (::LockFileEx(raw, flags, 0, MAXDWORD, MAXDWORD, &overlapped) == 0) {
|
||||
const DWORD err = ::GetLastError();
|
||||
::CloseHandle(raw);
|
||||
if (non_blocking && (err == ERROR_LOCK_VIOLATION || err == ERROR_IO_PENDING)) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::busy,
|
||||
std::format("FileLock: '{}' is already locked", lock_path.string()), EAGAIN)};
|
||||
}
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("FileLock: locking '{}' failed (error {})", lock_path.string(), err),
|
||||
static_cast<int>(err))};
|
||||
}
|
||||
auto handle = std::shared_ptr<void>{raw, [](void *h) {
|
||||
OVERLAPPED unlock{};
|
||||
(void)::UnlockFileEx(static_cast<HANDLE>(h), 0, MAXDWORD,
|
||||
MAXDWORD, &unlock);
|
||||
(void)::CloseHandle(static_cast<HANDLE>(h));
|
||||
}};
|
||||
return FileLock{std::move(handle)};
|
||||
#else
|
||||
const auto vl_mode = (mode == LockMode::Exclusive) ? Void::FileSystem::LockMode::Exclusive
|
||||
: Void::FileSystem::LockMode::Shared;
|
||||
if (non_blocking) {
|
||||
@@ -46,7 +91,7 @@ FileLock::acquire(const std::filesystem::path &lock_path, LockMode mode, bool no
|
||||
if (!res->has_value()) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::busy,
|
||||
std::format("FileLock: '{}' is already locked", lock_path.string()), EWOULDBLOCK)};
|
||||
std::format("FileLock: '{}' is already locked", lock_path.string()), EAGAIN)};
|
||||
}
|
||||
return FileLock{std::move(**res)};
|
||||
}
|
||||
@@ -55,10 +100,78 @@ FileLock::acquire(const std::filesystem::path &lock_path, LockMode mode, bool no
|
||||
return std::unexpected{std::move(res.error())};
|
||||
}
|
||||
return FileLock{std::move(*res)};
|
||||
#endif
|
||||
}
|
||||
|
||||
Void::Result::Result<FileMetadata, Void::Result::Error>
|
||||
stat_lstat(const std::filesystem::path &path) {
|
||||
#if defined(_WIN32)
|
||||
std::error_code ec;
|
||||
const auto status = std::filesystem::symlink_status(path, ec);
|
||||
if (ec) {
|
||||
if (ec == std::errc::no_such_file_or_directory || ec == std::errc::not_a_directory) {
|
||||
FileMetadata missing;
|
||||
return missing;
|
||||
}
|
||||
return std::unexpected{sys_err(
|
||||
ec.value(), std::format("stat_lstat: symlink_status failed for '{}': {}",
|
||||
path.string(), ec.message()))};
|
||||
}
|
||||
if (!std::filesystem::exists(status)) {
|
||||
FileMetadata missing;
|
||||
return missing;
|
||||
}
|
||||
|
||||
FileMetadata meta;
|
||||
meta.exists = true;
|
||||
meta.is_regular = std::filesystem::is_regular_file(status);
|
||||
meta.is_directory = std::filesystem::is_directory(status);
|
||||
meta.is_symlink = std::filesystem::is_symlink(status);
|
||||
if (meta.is_symlink) {
|
||||
std::error_code target_ec;
|
||||
const auto target = std::filesystem::read_symlink(path, target_ec);
|
||||
if (!target_ec) {
|
||||
meta.symlink_target = target.string();
|
||||
}
|
||||
}
|
||||
|
||||
const auto followed = std::filesystem::status(path, ec);
|
||||
if (!ec) {
|
||||
if (std::filesystem::is_regular_file(followed)) {
|
||||
const auto size = std::filesystem::file_size(path, ec);
|
||||
if (!ec) {
|
||||
meta.size = static_cast<std::uint64_t>(size);
|
||||
}
|
||||
ec.clear();
|
||||
}
|
||||
const auto mtime = std::filesystem::last_write_time(path, ec);
|
||||
if (!ec) {
|
||||
const auto sys = std::chrono::file_clock::to_sys(mtime);
|
||||
const auto secs = std::chrono::floor<std::chrono::seconds>(sys);
|
||||
meta.mtime_sec = static_cast<std::int64_t>(secs.time_since_epoch().count());
|
||||
meta.mtime_nsec = static_cast<std::int64_t>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(sys - secs).count());
|
||||
}
|
||||
}
|
||||
|
||||
// Identity through a Win32 handle (volume serial, file index, link count).
|
||||
const HANDLE handle = ::CreateFileW(path.c_str(), FILE_READ_ATTRIBUTES,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
|
||||
nullptr);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
BY_HANDLE_FILE_INFORMATION info{};
|
||||
if (::GetFileInformationByHandle(handle, &info) != 0) {
|
||||
meta.dev = info.dwVolumeSerialNumber;
|
||||
meta.ino = (static_cast<std::uint64_t>(info.nFileIndexHigh) << 32) |
|
||||
static_cast<std::uint64_t>(info.nFileIndexLow);
|
||||
meta.nlink = info.nNumberOfLinks;
|
||||
}
|
||||
::CloseHandle(handle);
|
||||
}
|
||||
meta.mode = meta.is_directory ? 0755u : 0644u;
|
||||
return meta;
|
||||
#else
|
||||
struct stat st{};
|
||||
if (::lstat(path.c_str(), &st) != 0) {
|
||||
const int err = errno;
|
||||
@@ -104,6 +217,7 @@ stat_lstat(const std::filesystem::path &path) {
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
#endif
|
||||
}
|
||||
|
||||
Void::Result::Result<bool, Void::Result::Error>
|
||||
@@ -125,17 +239,47 @@ copy_isolated(const std::filesystem::path &src, const std::filesystem::path &dst
|
||||
|
||||
auto res = Void::FileSystem::reflink_copy_file(src, dst, opts);
|
||||
if (!res) {
|
||||
#if defined(_WIN32)
|
||||
// No reflink support on this filesystem/host: fall back to a plain copy.
|
||||
std::filesystem::copy_file(src, dst, std::filesystem::copy_options::overwrite_existing,
|
||||
ec);
|
||||
if (ec) {
|
||||
return std::unexpected{sys_err(
|
||||
ec.value(), std::format("copy_isolated: copy_file failed for '{}': {}",
|
||||
dst.string(), ec.message()))};
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return std::unexpected{std::move(res.error())};
|
||||
#endif
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
(void)mode_override;
|
||||
#else
|
||||
if (mode_override) {
|
||||
(void)::chmod(dst.c_str(), static_cast<mode_t>(*mode_override));
|
||||
}
|
||||
#endif
|
||||
return res->method == Void::FileSystem::CopyMethod::Reflink;
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
set_canonical_mtime(const std::filesystem::path &path, std::int64_t epoch_seconds) {
|
||||
#if defined(_WIN32)
|
||||
// Void::FileSystem::set_canonical_mtime is POSIX-only (Void/Library issue #66).
|
||||
std::error_code ec;
|
||||
const auto stamp = std::chrono::file_clock::from_sys(
|
||||
std::chrono::system_clock::time_point{std::chrono::seconds{epoch_seconds}});
|
||||
std::filesystem::last_write_time(path, stamp, ec);
|
||||
if (ec) {
|
||||
return std::unexpected{
|
||||
sys_err(ec.value(), std::format("set_canonical_mtime: failed for '{}': {}",
|
||||
path.string(), ec.message()))};
|
||||
}
|
||||
return {};
|
||||
#else
|
||||
return Void::FileSystem::set_canonical_mtime(path, epoch_seconds, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
@@ -172,6 +316,11 @@ Void::Result::Result<void, Void::Result::Error> atomic_write_file(const std::fil
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
fsync_directory(const std::filesystem::path &dir_path) {
|
||||
#if defined(_WIN32)
|
||||
// Windows has no directory fsync; MoveFileEx visibility is the durability guarantee.
|
||||
(void)dir_path;
|
||||
return {};
|
||||
#else
|
||||
const int fd = ::open(dir_path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
const int err = errno;
|
||||
@@ -193,6 +342,7 @@ fsync_directory(const std::filesystem::path &dir_path) {
|
||||
return std::unexpected{
|
||||
sys_err(err, std::format("fsync_directory: fsync failed for '{}'", dir_path.string()))};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
@@ -206,8 +356,27 @@ atomic_swap_symlink(const std::filesystem::path &link_path, const std::filesyste
|
||||
ec.value(), std::format("atomic_swap_symlink: create_directories failed for '{}'",
|
||||
parent.string()))};
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
// Void::FileSystem::atomic_symlink_swap is POSIX-only (Void/Library issue #66).
|
||||
// Windows symlink creation needs privileges, so the alias becomes a regular
|
||||
// file copy of the target: consumers read the same content at link_path.
|
||||
std::error_code target_ec;
|
||||
if (!std::filesystem::is_regular_file(target, target_ec)) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
std::format("atomic_swap_symlink: cannot alias '{}' to '{}' on Windows",
|
||||
link_path.string(), target.string()))};
|
||||
}
|
||||
const auto bytes = Void::FileSystem::read_file(target);
|
||||
if (!bytes) {
|
||||
return std::unexpected{std::move(bytes.error())};
|
||||
}
|
||||
return atomic_write_bytes(link_path, std::as_bytes(std::span<const char>{*bytes}),
|
||||
/*durable_sync=*/true);
|
||||
#else
|
||||
return Void::FileSystem::atomic_symlink_swap(link_path, target,
|
||||
Void::FileSystem::ReplaceDurability::durable_sync);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool path_is_within(const std::filesystem::path &root, const std::filesystem::path &path) {
|
||||
@@ -316,6 +485,19 @@ resolve_confined_path(const std::filesystem::path &root, const std::filesystem::
|
||||
}
|
||||
|
||||
Void::Result::Result<std::filesystem::path, Void::Result::Error> current_executable_path() {
|
||||
#if defined(_WIN32)
|
||||
std::wstring buffer(32768, L'\0');
|
||||
const DWORD length =
|
||||
::GetModuleFileNameW(nullptr, buffer.data(), static_cast<DWORD>(buffer.size()));
|
||||
if (length == 0 || length >= buffer.size()) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("current_executable_path: GetModuleFileNameW failed ({})",
|
||||
::GetLastError()))};
|
||||
}
|
||||
buffer.resize(length);
|
||||
return std::filesystem::path{buffer};
|
||||
#else
|
||||
std::error_code ec;
|
||||
const auto path = std::filesystem::read_symlink("/proc/self/exe", ec);
|
||||
if (ec || path.empty()) {
|
||||
@@ -326,6 +508,7 @@ Void::Result::Result<std::filesystem::path, Void::Result::Error> current_executa
|
||||
ec.value())};
|
||||
}
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Void::Build::Platform
|
||||
@@ -4,32 +4,77 @@
|
||||
#include <Void/System/Process.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <cwctype>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !defined(__linux__)
|
||||
#if !defined(__linux__) && !defined(_WIN32)
|
||||
#error \
|
||||
"VoidBuildSystem's process and file backends currently support Linux hosts only (Track C2/C3 ports are planned)"
|
||||
"VoidBuildSystem's process and file backends currently support Linux and Windows hosts only (Track C2/C3 ports are planned)"
|
||||
#endif
|
||||
|
||||
namespace Void::Build::Platform {
|
||||
namespace {
|
||||
|
||||
#if defined(_WIN32)
|
||||
constexpr char kPathSeparator = ';';
|
||||
#else
|
||||
constexpr char kPathSeparator = ':';
|
||||
#endif
|
||||
|
||||
bool is_executable_file(const std::filesystem::path &p) {
|
||||
#if defined(_WIN32)
|
||||
std::error_code ec;
|
||||
if (!std::filesystem::is_regular_file(p, ec)) {
|
||||
return false;
|
||||
}
|
||||
std::string ext = p.extension().string();
|
||||
std::ranges::transform(ext, ext.begin(), [](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
});
|
||||
return ext.empty() || ext == ".exe" || ext == ".com" || ext == ".bat" || ext == ".cmd";
|
||||
#else
|
||||
struct stat st{};
|
||||
if (::stat(p.c_str(), &st) != 0) {
|
||||
return false;
|
||||
}
|
||||
return S_ISREG(st.st_mode) && ::access(p.c_str(), X_OK) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> resolve_candidate(const std::filesystem::path &candidate) {
|
||||
std::vector<std::filesystem::path> names{candidate};
|
||||
#if defined(_WIN32)
|
||||
if (!candidate.has_extension()) {
|
||||
for (const char *ext : {".exe", ".cmd", ".bat", ".com"}) {
|
||||
names.push_back(candidate.string() + ext);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (const auto &name : names) {
|
||||
if (is_executable_file(name)) {
|
||||
std::error_code ec;
|
||||
auto abs = std::filesystem::absolute(name, ec);
|
||||
return ec ? name : abs.lexically_normal();
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void ensure_subreaper() noexcept {
|
||||
#if !defined(_WIN32)
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [] { (void)Void::Process::enable_subreaper(); });
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -40,11 +85,14 @@ resolve_executable(const std::filesystem::path &executable,
|
||||
if (executable.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (executable.is_absolute() || executable.string().find('/') != std::string::npos) {
|
||||
if (executable.is_absolute() ||
|
||||
executable.string().find_first_of(std::string_view{"/\\"}) != std::string::npos) {
|
||||
std::error_code ec;
|
||||
const auto abs = std::filesystem::absolute(executable, ec);
|
||||
if (!ec && is_executable_file(abs)) {
|
||||
return abs.lexically_normal();
|
||||
if (!ec) {
|
||||
if (auto resolved = resolve_candidate(abs); resolved) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -58,21 +106,23 @@ resolve_executable(const std::filesystem::path &executable,
|
||||
}
|
||||
std::size_t start = 0;
|
||||
while (start <= path_env.size()) {
|
||||
const auto colon = path_env.find(':', start);
|
||||
const auto segment = path_env.substr(
|
||||
start, colon == std::string_view::npos ? std::string_view::npos : colon - start);
|
||||
const auto separator = path_env.find(kPathSeparator, start);
|
||||
auto segment = path_env.substr(
|
||||
start, separator == std::string_view::npos ? std::string_view::npos : separator - start);
|
||||
// Windows PATH entries may be quoted.
|
||||
if (segment.size() >= 2 && segment.front() == '"' && segment.back() == '"') {
|
||||
segment.remove_prefix(1);
|
||||
segment.remove_suffix(1);
|
||||
}
|
||||
const std::filesystem::path dir =
|
||||
segment.empty() ? std::filesystem::path{"."} : std::filesystem::path{segment};
|
||||
const auto candidate = dir / executable;
|
||||
if (is_executable_file(candidate)) {
|
||||
std::error_code ec;
|
||||
auto abs = std::filesystem::absolute(candidate, ec);
|
||||
return ec ? candidate : abs.lexically_normal();
|
||||
if (auto resolved = resolve_candidate(dir / executable); resolved) {
|
||||
return resolved;
|
||||
}
|
||||
if (colon == std::string_view::npos) {
|
||||
if (separator == std::string_view::npos) {
|
||||
break;
|
||||
}
|
||||
start = colon + 1;
|
||||
start = separator + 1;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -159,15 +209,19 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) {
|
||||
bool group_timed_out = comm->timed_out;
|
||||
bool group_cancelled = comm->cancelled;
|
||||
bool descendants_terminated = false;
|
||||
#if !defined(_WIN32)
|
||||
const pid_t pgid = static_cast<pid_t>(child->pgid());
|
||||
#endif
|
||||
if (!group_timed_out && !group_cancelled && !comm->overflowed) {
|
||||
const auto descendant_deadline =
|
||||
std::chrono::steady_clock::now() + request.descendant_grace;
|
||||
while (child->process_group_alive()) {
|
||||
#if !defined(_WIN32)
|
||||
// Reap any adopted descendants in this process group (subreaper) so zombies clear.
|
||||
int wstatus = 0;
|
||||
while (pgid > 0 && ::waitpid(-pgid, &wstatus, WNOHANG) > 0) {
|
||||
}
|
||||
#endif
|
||||
if (!child->process_group_alive()) {
|
||||
break;
|
||||
}
|
||||
@@ -192,6 +246,7 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) {
|
||||
if (group_cancelled || group_timed_out || descendants_terminated || comm->overflowed ||
|
||||
child->process_group_alive()) {
|
||||
(void)child->terminate(request.kill_grace);
|
||||
#if !defined(_WIN32)
|
||||
// Reap the whole group until it is really gone (bounded), so no zombie or orphan is
|
||||
// left behind after test supervision.
|
||||
const auto reap_deadline =
|
||||
@@ -210,6 +265,7 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ProcessResult result;
|
||||
|
||||
Reference in new issue
Block a user