From 466fe3abcfaa112054aff5f45814e0a1efd86564 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 21 Jun 2021 13:00:05 +0200 Subject: [PATCH] Run `$WINELOADER --version` under the correct env This makes the initialization message reflect the correct Wine version when using a `WINELOADER` script to change between Wine versions depending on the Wine prefix. --- CHANGELOG.md | 6 +++ src/plugin/bridges/common.h | 2 +- src/plugin/utils.cpp | 74 +++++++++++++++++++------------------ src/plugin/utils.h | 23 +++++++----- 4 files changed, 59 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a0c3e7e..8b742eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,12 @@ Versioning](https://semver.org/spec/v2.0.0.html). - Fixed VST2 speaker arrangement configurations returned by the plugin not being serialized correctly. No plugins seem to actually use these, so it should not have caused any issues. +- When printing the Wine version during initialization, the Wine process used + for this is now run under the same environment as the Wine plugin host process + will be run under. This means that when using a custom `WINELOADER` script to + use different Wine versions depending on the Wine prefix, the `wine version:` + line in the initialization message will always match the version of Wine the + plugin is going to be run under. ### yabridgectl diff --git a/src/plugin/bridges/common.h b/src/plugin/bridges/common.h index ef310c92..fc0b209f 100644 --- a/src/plugin/bridges/common.h +++ b/src/plugin/bridges/common.h @@ -175,7 +175,7 @@ class PluginBridge { info.wine_prefix); init_msg << "'" << std::endl; - init_msg << "wine version: '" << get_wine_version() << "'" + init_msg << "wine version: '" << info.wine_version() << "'" << std::endl; init_msg << std::endl; diff --git a/src/plugin/utils.cpp b/src/plugin/utils.cpp index 1ff05bc3..d4318013 100644 --- a/src/plugin/utils.cpp +++ b/src/plugin/utils.cpp @@ -24,6 +24,10 @@ #include #include +// XXX: With Boost 1.75 at least, this header cannot be included in alphabetical +// order because it's missing some includes +#include + // Generated inside of the build directory #include @@ -90,6 +94,41 @@ boost::filesystem::path PluginInfo::normalize_wine_prefix() const { wine_prefix); } +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; + bp::environment env = create_host_env(); + if (const std::string wineloader_path = env["WINELOADER"].to_string(); + access(wineloader_path.c_str(), X_OK) == 0) { + wine_path = wineloader_path; + } else { + wine_path = bp::search_path("wine").string(); + } + + bp::ipstream output; + try { + bp::system(wine_path, "--version", bp::std_out = output); + } catch (const std::system_error&) { + return ""; + } + + // `wine --version` might contain additional output in certain custom Wine + // builds, so we only want to look at the first line + std::string version_string; + std::getline(output, version_string); + + // Strip the `wine-` prefix from the output, could potentially be absent in + // custom Wine builds + constexpr std::string_view version_prefix("wine-"); + if (version_string.starts_with(version_prefix)) { + version_string = version_string.substr(version_prefix.size()); + } + + return version_string; +} + fs::path find_plugin_library(const fs::path& this_plugin_path, PluginType plugin_type, bool prefer_32bit_vst3) { @@ -341,41 +380,6 @@ std::vector get_augmented_search_path() { return search_path; } -std::string get_wine_version() { - // 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; - bp::environment env = boost::this_process::environment(); - if (const std::string wineloader_path = env["WINELOADER"].to_string(); - access(wineloader_path.c_str(), X_OK) == 0) { - wine_path = wineloader_path; - } else { - wine_path = bp::search_path("wine").string(); - } - - bp::ipstream output; - try { - bp::system(wine_path, "--version", bp::std_out = output); - } catch (const std::system_error&) { - return ""; - } - - // `wine --version` might contain additional output in certain custom Wine - // builds, so we only want to look at the first line - std::string version_string; - std::getline(output, version_string); - - // Strip the `wine-` prefix from the output, could potentially be absent in - // custom Wine builds - constexpr std::string_view version_prefix("wine-"); - if (version_string.starts_with(version_prefix)) { - version_string = version_string.substr(version_prefix.size()); - } - - return version_string; -} - Configuration load_config_for(const fs::path& yabridge_path) { // First find the closest `yabridge.tmol` file for the plugin, falling back // to default configuration settings if it doesn't exist diff --git a/src/plugin/utils.h b/src/plugin/utils.h index 05f68c2d..1022ce05 100644 --- a/src/plugin/utils.h +++ b/src/plugin/utils.h @@ -83,6 +83,19 @@ struct PluginInfo { */ boost::filesystem::path normalize_wine_prefix() const; + /** + * Return the installed Wine version. This is obtained by from `wine + * --version` and then stripping the `wine-` prefix. This respects the + * `WINELOADER` environment variable used in the scripts generated by + * winegcc. The script will be run with under the same environment as the + * Wine plugin host will be run at, since the user may use a custom + * `WINELOADER` to change use different Wine binaries for each prefix. + * + * This will *not* throw when Wine can not be found, but will instead return + * ''. This way the user will still get some useful log files. + */ + std::string wine_version() const; + const PluginType plugin_type; /** @@ -228,16 +241,6 @@ std::vector get_augmented_search_path(); */ boost::filesystem::path get_this_file_location(); -/** - * Return the installed Wine version. This is obtained by from `wine --version` - * and then stripping the `wine-` prefix. This respects the `WINELOADER` - * environment variable used in the scripts generated by winegcc. - * - * This will *not* throw when Wine can not be found, but will instead return - * ''. This way the user will still get some useful log files. - */ -std::string get_wine_version(); - /** * Load the configuration that belongs to a copy of or symlink to * `libyabridge-{vst2,vst3}.so`. If no configuration file could be found then