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.
This commit is contained in:
Robbert van der Helm
2021-06-21 13:00:05 +02:00
parent b81871e4bf
commit 466fe3abcf
4 changed files with 59 additions and 46 deletions
+6
View File
@@ -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
+1 -1
View File
@@ -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;
+39 -35
View File
@@ -24,6 +24,10 @@
#include <boost/process/system.hpp>
#include <sstream>
// XXX: With Boost 1.75 at least, this header cannot be included in alphabetical
// order because it's missing some includes
#include <boost/process/env.hpp>
// Generated inside of the build directory
#include <src/common/config/config.h>
@@ -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 "<NOT FOUND>";
}
// `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<boost::filesystem::path> 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 "<NOT FOUND>";
}
// `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
+13 -10
View File
@@ -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
* '<NOT FOUND>'. 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<boost::filesystem::path> 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
* '<NOT FOUND>'. 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