mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Always search for host in ~/.local/share/yabridge
This commit is contained in:
Generated
+10
@@ -242,6 +242,15 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_executable"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577"
|
||||
dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
@@ -704,6 +713,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"colored",
|
||||
"is_executable",
|
||||
"lazy_static",
|
||||
"promptly",
|
||||
"rayon",
|
||||
|
||||
@@ -10,10 +10,11 @@ repository = "https://github.com/robbert-vdh/yabridge"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.31"
|
||||
aho-corasick = "0.7.13"
|
||||
colored = "2.0.0"
|
||||
anyhow = "1.0.31"
|
||||
clap = { version = "3.0.0-beta.1", features = ["wrap_help"] }
|
||||
colored = "2.0.0"
|
||||
is_executable = "0.1.2"
|
||||
lazy_static = "1.4.0"
|
||||
promptly = "0.3.0"
|
||||
rayon = "1.3.1"
|
||||
|
||||
@@ -29,15 +29,15 @@ use xdg::BaseDirectories;
|
||||
use crate::files::{self, SearchResults};
|
||||
|
||||
/// The name of the config file, relative to `$XDG_CONFIG_HOME/CONFIG_PREFIX`.
|
||||
const CONFIG_FILE_NAME: &str = "config.toml";
|
||||
pub const CONFIG_FILE_NAME: &str = "config.toml";
|
||||
/// The name of the XDG base directory prefix for yabridgectl, relative to `$XDG_CONFIG_HOME` and
|
||||
/// `$XDG_DATA_HOME`.
|
||||
const YABRIDGECTL_PREFIX: &str = "yabridgectl";
|
||||
|
||||
/// The name of the library file we're searching for.
|
||||
const LIBYABRIDGE_NAME: &str = "libyabridge.so";
|
||||
pub const LIBYABRIDGE_NAME: &str = "libyabridge.so";
|
||||
/// The name of the script we're going to run to verify that everything's working correctly.
|
||||
const YABRIDGE_HOST_EXE_NAME: &str = "yabridge-host.exe";
|
||||
pub const YABRIDGE_HOST_EXE_NAME: &str = "yabridge-host.exe";
|
||||
/// The name of the XDG base directory prefix for yabridge's own files, relative to
|
||||
/// `$XDG_CONFIG_HOME` and `$XDG_DATA_HOME`.
|
||||
const YABRIDGE_PREFIX: &str = "yabridge";
|
||||
@@ -191,8 +191,8 @@ impl Config {
|
||||
}
|
||||
|
||||
Err(anyhow!(
|
||||
"Could not find '{}' in either '{}' or '{}'. You can tell yabridgectl where \
|
||||
to search for it using 'yabridgectl set --path=<path>'.",
|
||||
"Could not find '{}' in either '{}' or '{}'. You can override the default \
|
||||
search path using 'yabridgectl set --path=<path>'.",
|
||||
LIBYABRIDGE_NAME,
|
||||
system_path.display(),
|
||||
user_path.display()
|
||||
@@ -229,12 +229,12 @@ impl Config {
|
||||
/// Fetch the XDG base directories for yabridge's own files, converting any error messages if this
|
||||
/// somehow fails into a printable string to reduce boiler plate. This is only used when searching
|
||||
/// for `libyabridge.so` when no explicit search path has been set.
|
||||
fn yabridge_directories() -> Result<BaseDirectories> {
|
||||
pub fn yabridge_directories() -> Result<BaseDirectories> {
|
||||
BaseDirectories::with_prefix(YABRIDGE_PREFIX).context("Error while parsing base directories")
|
||||
}
|
||||
|
||||
/// Fetch the XDG base directories used for yabridgectl, converting any error messages if this
|
||||
/// somehow fails into a printable string to reduce boiler plate.
|
||||
fn yabridgectl_directories() -> Result<BaseDirectories> {
|
||||
pub fn yabridgectl_directories() -> Result<BaseDirectories> {
|
||||
BaseDirectories::with_prefix(YABRIDGECTL_PREFIX).context("Error while parsing base directories")
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use anyhow::Result;
|
||||
use clap::{app_from_crate, App, AppSettings, Arg};
|
||||
use colored::Colorize;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::config::Config;
|
||||
@@ -27,6 +28,17 @@ mod files;
|
||||
mod utils;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// We'll modify our `PATH` environment variable so it matches up with
|
||||
// `get_modified_search_path()` from `src/plugin/utils.h` for easier setup
|
||||
let yabridge_home = config::yabridge_directories()?.get_data_home();
|
||||
env::set_var(
|
||||
"PATH",
|
||||
match env::var("PATH") {
|
||||
Ok(path) => format!("{}:{}", path, yabridge_home.display()),
|
||||
_ => format!("{}", yabridge_home.display()),
|
||||
},
|
||||
);
|
||||
|
||||
let mut config = Config::read()?;
|
||||
|
||||
// Used for validation in `yabridgectl rm <path>`
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use colored::Colorize;
|
||||
use is_executable::IsExecutable;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
@@ -28,7 +29,7 @@ use std::path::Path;
|
||||
use std::process::{Command, Stdio};
|
||||
use textwrap::Wrapper;
|
||||
|
||||
use crate::config::{Config, KnownConfig};
|
||||
use crate::config::{self, Config, KnownConfig, YABRIDGE_HOST_EXE_NAME};
|
||||
|
||||
/// (Part of) the expected output when running `yabridge-host.exe`. Used to verify that everything's
|
||||
/// working correctly. We'll only match this prefix so we can modify the exact output at a later
|
||||
@@ -82,15 +83,33 @@ pub fn hash_file(file: &Path) -> Result<i64> {
|
||||
Ok(hasher.finish() as i64)
|
||||
}
|
||||
|
||||
/// Verify that `yabridge-host.exe` is accessible in a login shell. Returns unit if it is, or if we
|
||||
/// the login shell is set to an unknown shell. In the last case we'll just print a warning since we
|
||||
/// don't know how to invoke the shell as a login shell. This is needed when using copies to ensure
|
||||
/// that yabridge can find the host binaries when the VST host is launched from the desktop
|
||||
/// enviornment.
|
||||
/// Verify that `yabridge-host.exe` can be found when yabridge is run in a host launched from the
|
||||
/// GUI. We do this by launching a login shell, appending `~/.local/share/yabridge` to the login
|
||||
/// shell's search path since that's what yabridge also does, and then making the the file can be
|
||||
/// found. Returns unit if it can be found, or if we the login shell is set to an unknown shell. In
|
||||
/// the last case we'll just print a warning since we don't know how to invoke the shell as a login
|
||||
/// shell. This is needed when using copies to ensure that yabridge can find the host binaries when
|
||||
/// the VST host is launched from the desktop enviornment.
|
||||
///
|
||||
/// When we could not find `yabridge-host.exe`, we'll return `Err(shell_name)` so we can print a
|
||||
/// descriptive warning message.
|
||||
pub fn verify_path_setup() -> Result<(), String> {
|
||||
// First we'll check `~/.local/share/yabridge`, since that's a special location where yabridge
|
||||
// will always search
|
||||
if config::yabridge_directories()
|
||||
.ok()
|
||||
.and_then(|dirs| {
|
||||
dirs.get_data_home()
|
||||
.push(YABRIDGE_HOST_EXE_NAME)
|
||||
.is_executable()
|
||||
})
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Then we'll check the login shell, since DAWs launched from the GUI will have the same
|
||||
// environment
|
||||
match env::var("SHELL") {
|
||||
Ok(shell_path) => {
|
||||
// `$SHELL` will often contain a full path, but it doesn't have to
|
||||
@@ -113,13 +132,20 @@ pub fn verify_path_setup() -> Result<(), String> {
|
||||
| "zsh" => command
|
||||
.arg("-l")
|
||||
.arg("-c")
|
||||
.arg("command -v yabridge-host.exe"),
|
||||
.arg(format!("command -v {}", YABRIDGE_HOST_EXE_NAME)),
|
||||
// These shells either have their own implementation of `which` and don't support
|
||||
// `command`, or they don't have a seperate login shell flag
|
||||
"elvish" | "oil" => command.arg("-c").arg("command -v yabridge-host.exe"),
|
||||
"elvish" | "oil" => command
|
||||
.arg("-c")
|
||||
.arg(format!("command -v {}", YABRIDGE_HOST_EXE_NAME)),
|
||||
// xonsh's which implementation is broken as of writing this, so I left it out
|
||||
"pwsh" => command.arg("-l").arg("-c").arg("which yabridge-host.exe"),
|
||||
"nu" => command.arg("-c").arg("which yabridge-host.exe"),
|
||||
"pwsh" => command
|
||||
.arg("-l")
|
||||
.arg("-c")
|
||||
.arg(format!("which {}", YABRIDGE_HOST_EXE_NAME)),
|
||||
"nu" => command
|
||||
.arg("-c")
|
||||
.arg(format!("which {}", YABRIDGE_HOST_EXE_NAME)),
|
||||
shell => {
|
||||
eprintln!(
|
||||
"\n{}",
|
||||
|
||||
Reference in New Issue
Block a user