Skip to content

Commit

Permalink
feat: add uncompressed artifacts to path for started plugin process
Browse files Browse the repository at this point in the history
Signed-off-by: jlanson <[email protected]>
  • Loading branch information
j-lanson authored and patrickjcasey committed Dec 13, 2024
1 parent 42671cf commit 50a4476
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions hipcheck/src/plugin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,35 @@ impl PluginExecutor {
));
};

let Ok(canon_working_dir) = plugin.working_dir.canonicalize() else {
return Err(hc_error!(
"Failed to canonicalize plugin working dir: {:?}",
&plugin.working_dir
));
};

// Entrypoints are often "<BIN_NAME>" which can overlap with existing binaries on the
// system like "git", "npm", so we must search for <BIN_NAME> from within the plugin
// cache subfolder. First, grab the existing path.
let Some(mut os_paths) =
let Some(mut which_os_paths) =
std::env::var_os("PATH").map(|s| std::env::split_paths(&s).collect::<Vec<_>>())
else {
return Err(hc_error!("Unable to get system PATH var"));
};

let Ok(canon_working_dir) = plugin.working_dir.canonicalize() else {
return Err(hc_error!(
"Failed to canonicalize plugin working dir: {:?}",
&plugin.working_dir
));
};
// Add canonicalized plugin cache dir to end of PATH for plugin exec
let mut cmd_os_paths = which_os_paths.clone();
cmd_os_paths.push(canon_working_dir.clone());
let cmd_path = std::env::join_paths(cmd_os_paths).unwrap();

// Add canonicalized plugin cache dir to temp PATH
os_paths.insert(0, canon_working_dir.clone());
let search_path = std::env::join_paths(os_paths).unwrap();
// Add canonicalized plugin cache dir to front of PATH for bin-searching
which_os_paths.insert(0, canon_working_dir.clone());
let which_path = std::env::join_paths(which_os_paths).unwrap();

// Find the binary_str using temp PATH
let Ok(canon_bin_path) = which::which_in::<&str, &OsString, &Path>(
bin_path_str,
Some(&search_path),
Some(&which_path),
canon_working_dir.as_ref(),
) else {
return Err(hc_error!(
Expand Down Expand Up @@ -138,6 +143,7 @@ impl PluginExecutor {
// Spawn plugin process
log::debug!("Spawning '{}' on port {}", &plugin.entrypoint, port_str);
let Ok(mut proc) = Command::new(&canon_bin_path)
.env("PATH", &cmd_path)
.args(spawn_args)
// @Temporary - directly forward stdout/stderr from plugin to shell
.stdout(std::io::stdout())
Expand Down

0 comments on commit 50a4476

Please sign in to comment.