mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-08 12:30:12 +02:00
Replace most uses of Boost.{Filesystem,Process}
With the `ghc::filesystem` dependency from the previous commit. If we can replace the rest of the Boost.Filesystem dependency then we can get rid the one nasty runtime dependency we have, and it will make implementing the chainloading simpler since can reuse more code without bringing in Boost.
This commit is contained in:
@@ -236,7 +236,7 @@ class PluginBridge {
|
||||
[&](const OverridenWinePrefix& prefix) {
|
||||
init_msg << prefix.value.string() << " <overridden>";
|
||||
},
|
||||
[&](const boost::filesystem::path& prefix) {
|
||||
[&](const ghc::filesystem::path& prefix) {
|
||||
init_msg << prefix.string();
|
||||
},
|
||||
[&](const DefaultWinePrefix&) { init_msg << "<default>"; },
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "../common/utils.h"
|
||||
|
||||
namespace bp = boost::process;
|
||||
namespace fs = boost::filesystem;
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
HostProcess::HostProcess(boost::asio::io_context& io_context,
|
||||
Logger& logger,
|
||||
@@ -157,7 +157,8 @@ GroupHost::GroupHost(boost::asio::io_context& io_context,
|
||||
// because it should run independently of this yabridge instance as
|
||||
// it will likely outlive it.
|
||||
bp::child group_host =
|
||||
launch_host(host_path_, group_socket_path,
|
||||
// FIXME: Boost.Filesystem conversion
|
||||
launch_host(host_path_, group_socket_path.string(),
|
||||
bp::env = plugin_info.create_host_env());
|
||||
group_host.detach();
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
|
||||
#include <boost/asio/local/stream_protocol.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/process/child.hpp>
|
||||
#include <boost/process/extend.hpp>
|
||||
#include <boost/process/io.hpp>
|
||||
#include <ghc/filesystem.hpp>
|
||||
|
||||
#include "../common/communication/common.h"
|
||||
#include "../common/logging/common.h"
|
||||
@@ -46,7 +46,7 @@ class HostProcess {
|
||||
* is chosen depending on the architecture of the plugin's DLL file and on
|
||||
* the hosting mode.
|
||||
*/
|
||||
virtual boost::filesystem::path path() = 0;
|
||||
virtual ghc::filesystem::path path() = 0;
|
||||
|
||||
/**
|
||||
* Return true if the host process is still running. Used during startup to
|
||||
@@ -69,7 +69,7 @@ class HostProcess {
|
||||
* multiple arugments.
|
||||
*/
|
||||
template <typename... Args>
|
||||
boost::process::child launch_host(boost::filesystem::path host_path,
|
||||
boost::process::child launch_host(ghc::filesystem::path host_path,
|
||||
Args&&... args) {
|
||||
return boost::process::child(
|
||||
#ifdef WITH_WINEDBG
|
||||
@@ -88,7 +88,8 @@ class HostProcess {
|
||||
host_path.string() + ".so",
|
||||
#endif // WINEDBG_LEGACY_ARGUMENT_QUOTING
|
||||
#else
|
||||
host_path,
|
||||
// FIXME: Replace Boost.Filesystem
|
||||
host_path.string(),
|
||||
#endif // WITH_WINEDBG
|
||||
boost::process::std_out = stdout_pipe_,
|
||||
boost::process::std_err = stderr_pipe_,
|
||||
@@ -207,13 +208,13 @@ class IndividualHost : public HostProcess {
|
||||
const PluginInfo& plugin_info,
|
||||
const HostRequest& host_request);
|
||||
|
||||
boost::filesystem::path path() override;
|
||||
ghc::filesystem::path path() override;
|
||||
bool running() override;
|
||||
void terminate() override;
|
||||
|
||||
private:
|
||||
const PluginInfo& plugin_info_;
|
||||
boost::filesystem::path host_path_;
|
||||
ghc::filesystem::path host_path_;
|
||||
boost::process::child host_;
|
||||
};
|
||||
|
||||
@@ -255,13 +256,13 @@ class GroupHost : public HostProcess {
|
||||
const PluginInfo& plugin_info,
|
||||
const HostRequest& host_request);
|
||||
|
||||
boost::filesystem::path path() override;
|
||||
ghc::filesystem::path path() override;
|
||||
bool running() noexcept override;
|
||||
void terminate() override;
|
||||
|
||||
private:
|
||||
const PluginInfo& plugin_info_;
|
||||
boost::filesystem::path host_path_;
|
||||
ghc::filesystem::path host_path_;
|
||||
|
||||
/**
|
||||
* We want to either connect to an existing group host process, or spawn a
|
||||
|
||||
+24
-16
@@ -38,7 +38,7 @@
|
||||
#include "../common/utils.h"
|
||||
|
||||
namespace bp = boost::process;
|
||||
namespace fs = boost::filesystem;
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
// These functions are used to populate the fields in `PluginInfo`. See the
|
||||
// docstrings for the corresponding fields for more information on what we're
|
||||
@@ -74,7 +74,7 @@ bp::environment PluginInfo::create_host_env() const {
|
||||
// just for clarity's sake)
|
||||
std::visit(overload{
|
||||
[](const OverridenWinePrefix&) {},
|
||||
[&](const boost::filesystem::path& prefix) {
|
||||
[&](const ghc::filesystem::path& prefix) {
|
||||
env["WINEPREFIX"] = prefix.string();
|
||||
},
|
||||
[](const DefaultWinePrefix&) {},
|
||||
@@ -84,11 +84,11 @@ bp::environment PluginInfo::create_host_env() const {
|
||||
return env;
|
||||
}
|
||||
|
||||
boost::filesystem::path PluginInfo::normalize_wine_prefix() const {
|
||||
ghc::filesystem::path PluginInfo::normalize_wine_prefix() const {
|
||||
return std::visit(
|
||||
overload{
|
||||
[](const OverridenWinePrefix& prefix) { return prefix.value; },
|
||||
[](const boost::filesystem::path& prefix) { return prefix; },
|
||||
[](const ghc::filesystem::path& prefix) { return prefix; },
|
||||
[](const DefaultWinePrefix&) {
|
||||
const bp::environment env = boost::this_process::environment();
|
||||
return fs::path(env.at("HOME").to_string()) / ".wine";
|
||||
@@ -101,7 +101,8 @@ std::string PluginInfo::wine_version() const {
|
||||
// The '*.exe' scripts generated by winegcc allow you to override the binary
|
||||
// used to run Wine, so will will handle this in the same way for our Wine
|
||||
// version detection
|
||||
fs::path wine_path;
|
||||
// FIXME: Replace Boost.Filesystem usage
|
||||
boost::filesystem::path wine_path;
|
||||
bp::environment env = create_host_env();
|
||||
if (const std::string wineloader_path = env["WINELOADER"].to_string();
|
||||
access(wineloader_path.c_str(), X_OK) == 0) {
|
||||
@@ -280,7 +281,8 @@ fs::path get_this_file_location() {
|
||||
// way to work around this if this happens is to just add another
|
||||
// leading slash and then normalize the path, since three or more
|
||||
// slashes will be coerced into a single slash.
|
||||
fs::path this_file = boost::dll::this_line_location();
|
||||
// FIXME: Replace Boost.Filesystem usage
|
||||
fs::path this_file = boost::dll::this_line_location().string();
|
||||
if (this_file.string().starts_with("//")) {
|
||||
this_file = ("/" / this_file).lexically_normal();
|
||||
}
|
||||
@@ -318,9 +320,10 @@ std::string create_logger_prefix(const fs::path& endpoint_base_dir) {
|
||||
return "[" + endpoint_name + "] ";
|
||||
}
|
||||
|
||||
fs::path find_vst_host(const boost::filesystem::path& this_plugin_path,
|
||||
fs::path find_vst_host(const ghc::filesystem::path& this_plugin_path,
|
||||
LibArchitecture plugin_arch,
|
||||
bool use_plugin_groups) {
|
||||
// FIXME: Anything using `this_plugin_path` and similar needs to be changed
|
||||
auto host_name = use_plugin_groups ? yabridge_group_host_name
|
||||
: yabridge_individual_host_name;
|
||||
if (plugin_arch == LibArchitecture::dll_32) {
|
||||
@@ -338,19 +341,20 @@ fs::path find_vst_host(const boost::filesystem::path& this_plugin_path,
|
||||
|
||||
// Boost will return an empty path if the file could not be found in the
|
||||
// search path
|
||||
const fs::path vst_host_path =
|
||||
const boost::filesystem::path vst_host_path =
|
||||
bp::search_path(host_name, get_augmented_search_path());
|
||||
if (vst_host_path == "") {
|
||||
throw std::runtime_error("Could not locate '" + std::string(host_name) +
|
||||
"'");
|
||||
}
|
||||
|
||||
return vst_host_path;
|
||||
// FIXME: Replace Boost.Filesystem usage requiring this conversion
|
||||
return vst_host_path.string();
|
||||
}
|
||||
|
||||
boost::filesystem::path generate_group_endpoint(
|
||||
ghc::filesystem::path generate_group_endpoint(
|
||||
const std::string& group_name,
|
||||
const boost::filesystem::path& wine_prefix,
|
||||
const ghc::filesystem::path& wine_prefix,
|
||||
const LibArchitecture architecture) {
|
||||
std::ostringstream socket_name;
|
||||
socket_name << "yabridge-group-" << group_name << "-"
|
||||
@@ -370,6 +374,7 @@ boost::filesystem::path generate_group_endpoint(
|
||||
return get_temporary_directory() / socket_name.str();
|
||||
}
|
||||
|
||||
// FIXME: Replace Boost.Filesystem
|
||||
std::vector<boost::filesystem::path> get_augmented_search_path() {
|
||||
// HACK: `std::locale("")` would return the current locale, but this
|
||||
// overload is implementation specific, and libstdc++ returns an error
|
||||
@@ -410,12 +415,13 @@ std::vector<boost::filesystem::path> get_augmented_search_path() {
|
||||
const bp::environment environment = boost::this_process::environment();
|
||||
if (auto xdg_data_home = environment.find("XDG_DATA_HOME");
|
||||
xdg_data_home != environment.end()) {
|
||||
search_path.push_back(fs::path(xdg_data_home->to_string()) /
|
||||
"yabridge");
|
||||
search_path.push_back(
|
||||
boost::filesystem::path(xdg_data_home->to_string()) / "yabridge");
|
||||
} else if (auto home_directory = environment.find("HOME");
|
||||
home_directory != environment.end()) {
|
||||
search_path.push_back(fs::path(home_directory->to_string()) / ".local" /
|
||||
"share" / "yabridge");
|
||||
search_path.push_back(
|
||||
boost::filesystem::path(home_directory->to_string()) / ".local" /
|
||||
"share" / "yabridge");
|
||||
}
|
||||
|
||||
return search_path;
|
||||
@@ -436,7 +442,9 @@ Configuration load_config_for(const fs::path& yabridge_path) {
|
||||
bool send_notification(const std::string& title,
|
||||
const std::string body,
|
||||
bool append_origin) {
|
||||
const fs::path notify_send_path = bp::search_path("notify-send");
|
||||
// FIXME: Replace Boost.Filesystem
|
||||
const boost::filesystem::path notify_send_path =
|
||||
bp::search_path("notify-send");
|
||||
if (notify_send_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+21
-19
@@ -34,7 +34,7 @@ struct DefaultWinePrefix {};
|
||||
* environment variable.
|
||||
*/
|
||||
struct OverridenWinePrefix {
|
||||
boost::filesystem::path value;
|
||||
ghc::filesystem::path value;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ struct PluginInfo {
|
||||
* Return the path to the actual Wine prefix in use, taking into account
|
||||
* `WINEPREFIX` overrides and the default `~/.wine` fallback.
|
||||
*/
|
||||
boost::filesystem::path normalize_wine_prefix() const;
|
||||
ghc::filesystem::path normalize_wine_prefix() const;
|
||||
|
||||
/**
|
||||
* Return the installed Wine version. This is obtained by from `wine
|
||||
@@ -103,7 +103,7 @@ struct PluginInfo {
|
||||
* module (since that has to be bundle on Linux) but rather the .so file
|
||||
* contained in that bundle.
|
||||
*/
|
||||
const boost::filesystem::path native_library_path_;
|
||||
const ghc::filesystem::path native_library_path_;
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ struct PluginInfo {
|
||||
* instead. We store this intermediate value so we can determine the
|
||||
* plugin's architecture.
|
||||
*/
|
||||
const boost::filesystem::path windows_library_path_;
|
||||
const ghc::filesystem::path windows_library_path_;
|
||||
|
||||
public:
|
||||
const LibArchitecture plugin_arch_;
|
||||
@@ -132,7 +132,7 @@ struct PluginInfo {
|
||||
*
|
||||
* https://developer.steinberg.help/pages/viewpage.action?pageId=9798275
|
||||
*/
|
||||
const boost::filesystem::path windows_plugin_path_;
|
||||
const ghc::filesystem::path windows_plugin_path_;
|
||||
|
||||
/**
|
||||
* The Wine prefix to use for hosting `windows_plugin_path_`. If the
|
||||
@@ -144,7 +144,7 @@ struct PluginInfo {
|
||||
* prefix will be used instead.
|
||||
*/
|
||||
const std::
|
||||
variant<OverridenWinePrefix, boost::filesystem::path, DefaultWinePrefix>
|
||||
variant<OverridenWinePrefix, ghc::filesystem::path, DefaultWinePrefix>
|
||||
wine_prefix_;
|
||||
};
|
||||
|
||||
@@ -174,7 +174,7 @@ std::string join_quoted_strings(std::vector<std::string>& strings);
|
||||
* @return A prefix string for log messages.
|
||||
*/
|
||||
std::string create_logger_prefix(
|
||||
const boost::filesystem::path& endpoint_base_dir);
|
||||
const ghc::filesystem::path& endpoint_base_dir);
|
||||
|
||||
/**
|
||||
* Finds the Wine VST host (either `yabridge-host.exe` or `yabridge-host.exe`
|
||||
@@ -197,8 +197,8 @@ std::string create_logger_prefix(
|
||||
* @return The a path to the VST host, if found.
|
||||
* @throw std::runtime_error If the Wine VST host could not be found.
|
||||
*/
|
||||
boost::filesystem::path find_vst_host(
|
||||
const boost::filesystem::path& this_plugin_path,
|
||||
ghc::filesystem::path find_vst_host(
|
||||
const ghc::filesystem::path& this_plugin_path,
|
||||
LibArchitecture plugin_arch,
|
||||
bool use_plugin_groups);
|
||||
|
||||
@@ -220,9 +220,9 @@ boost::filesystem::path find_vst_host(
|
||||
* @return A socket endpoint path that corresponds to the format described
|
||||
* above.
|
||||
*/
|
||||
boost::filesystem::path generate_group_endpoint(
|
||||
ghc::filesystem::path generate_group_endpoint(
|
||||
const std::string& group_name,
|
||||
const boost::filesystem::path& wine_prefix,
|
||||
const ghc::filesystem::path& wine_prefix,
|
||||
const LibArchitecture architecture);
|
||||
|
||||
/**
|
||||
@@ -233,6 +233,8 @@ boost::filesystem::path generate_group_endpoint(
|
||||
* environment variable can be a big hurdle if you've never done anything like
|
||||
* that before. And since this is the recommended installation location, it
|
||||
* makes sense to also search there by default.
|
||||
*
|
||||
* FIXME: Replace Boost.Filesystem
|
||||
*/
|
||||
std::vector<boost::filesystem::path> get_augmented_search_path();
|
||||
|
||||
@@ -240,7 +242,7 @@ std::vector<boost::filesystem::path> get_augmented_search_path();
|
||||
* Return a path to this `.so` file. This can be used to find out from where
|
||||
* this link to or copy of `libyabridge-{vst2,vst3}.so` was loaded.
|
||||
*/
|
||||
boost::filesystem::path get_this_file_location();
|
||||
ghc::filesystem::path get_this_file_location();
|
||||
|
||||
/**
|
||||
* Load the configuration that belongs to a copy of or symlink to
|
||||
@@ -263,7 +265,7 @@ boost::filesystem::path get_this_file_location();
|
||||
*
|
||||
* @see Configuration
|
||||
*/
|
||||
Configuration load_config_for(const boost::filesystem::path& yabridge_path);
|
||||
Configuration load_config_for(const ghc::filesystem::path& yabridge_path);
|
||||
|
||||
/**
|
||||
* Send a desktop notification using `notify-send`. Used for diagnostics when a
|
||||
@@ -299,14 +301,14 @@ bool send_notification(const std::string& title,
|
||||
* @return The path to the *file* found, or `std::nullopt` if the file could not
|
||||
* be found.
|
||||
*/
|
||||
template <invocable_returning<bool, const boost::filesystem::path&> F =
|
||||
bool(const boost::filesystem::path&)>
|
||||
std::optional<boost::filesystem::path> find_dominating_file(
|
||||
template <invocable_returning<bool, const ghc::filesystem::path&> F =
|
||||
bool(const ghc::filesystem::path&)>
|
||||
std::optional<ghc::filesystem::path> find_dominating_file(
|
||||
const std::string& filename,
|
||||
boost::filesystem::path starting_dir,
|
||||
F&& predicate = boost::filesystem::exists) {
|
||||
ghc::filesystem::path starting_dir,
|
||||
F&& predicate = ghc::filesystem::exists) {
|
||||
while (starting_dir != "") {
|
||||
const boost::filesystem::path candidate = starting_dir / filename;
|
||||
const ghc::filesystem::path candidate = starting_dir / filename;
|
||||
if (predicate(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user