From 9fed55e692b620c035cd977422605d061fd6a9a1 Mon Sep 17 00:00:00 2001 From: Kirottu Date: Tue, 2 May 2023 13:51:03 +0300 Subject: [PATCH] Load plugins from paths provided in the env var ANYRUN_PLUGINS --- anyrun/src/main.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/anyrun/src/main.rs b/anyrun/src/main.rs index 7b10acc..a58382d 100644 --- a/anyrun/src/main.rs +++ b/anyrun/src/main.rs @@ -299,6 +299,17 @@ fn activate(app: >k::Application, runtime_data: Rc .name(style_names::MAIN) .build(); + // Prioritise the ANYRUN_PLUGINS env var over other paths + let mut plugin_paths = match env::var("ANYRUN_PLUGINS") { + Ok(string) => string.split(':').map(PathBuf::from).collect::>(), + Err(_) => Vec::new(), + }; + + plugin_paths.append(&mut vec![ + format!("{}/plugins", config_dir).into(), + format!("{}/plugins", DEFAULT_CONFIG_DIR).into(), + ]); + // Load plugins from the paths specified in the config file runtime_data.borrow_mut().as_mut().unwrap().plugins = plugins .iter() @@ -310,12 +321,23 @@ fn activate(app: >k::Application, runtime_data: Rc global_path.extend(plugin_path.iter()); // Load the plugin's dynamic library. + let plugin = if plugin_path.is_absolute() { abi_stable::library::lib_header_from_path(plugin_path) - } else if user_path.exists() { - abi_stable::library::lib_header_from_path(&user_path) } else { - abi_stable::library::lib_header_from_path(&global_path) + let path = plugin_paths + .clone() + .into_iter() + .map(|mut path| { + path.push(plugin_path); + path + }) + .find(|path| path.exists()) + .expect("Invalid plugin path"); + + println!("{}", path.display()); + + abi_stable::library::lib_header_from_path(&path) } .and_then(|plugin| plugin.init_root_module::()) .expect("Failed to load plugin");