|
| 1 | +use runfiles::{rlocation, Runfiles}; |
| 2 | +use std::process; |
| 3 | +use std::path::PathBuf; |
| 4 | + |
| 5 | +pub fn invoke_binary(bin: PathBuf) { |
| 6 | + let child = process::Command::new(bin) |
| 7 | + .stdin(process::Stdio::piped()) |
| 8 | + .stdout(process::Stdio::piped()) |
| 9 | + .spawn() |
| 10 | + .expect("Failed to spawn command"); |
| 11 | + let output = child.wait_with_output().expect("Failed to read stdout"); |
| 12 | + let stdout = String::from_utf8(output.stdout).unwrap(); |
| 13 | + println!("say_hello binary output: {}", stdout.trim()); |
| 14 | +} |
| 15 | + |
| 16 | +pub fn invoke_say_hello_binary_with_path() { |
| 17 | + let r = Runfiles::create().unwrap(); |
| 18 | + let bin = rlocation!(r, "_main/pkg_a/say_hello").unwrap(); |
| 19 | + println!("Invoking say_hello binary with path: {}", bin.display()); |
| 20 | + |
| 21 | + invoke_binary(bin); |
| 22 | +} |
| 23 | + |
| 24 | +pub fn invoke_say_hello_binary_with_env_var() { |
| 25 | + let r = Runfiles::create().unwrap(); |
| 26 | + let bin = rlocation!(r, env!("SAY_HELLO_BIN")).unwrap(); |
| 27 | + println!("Invoking say_hello binary with env var: {}", bin.display()); |
| 28 | + |
| 29 | + invoke_binary(bin); |
| 30 | +} |
| 31 | + |
| 32 | +pub fn invoke_say_hello_with_late_join() { |
| 33 | + let r = Runfiles::create().unwrap(); |
| 34 | + let bin_folder = rlocation!(r, "_main/pkg_a").unwrap(); |
| 35 | + |
| 36 | + let bin = bin_folder.join("say_hello"); |
| 37 | + println!("Invoking pkg_a binary with late join: {}", bin.display()); |
| 38 | + |
| 39 | + invoke_binary(bin); |
| 40 | +} |
| 41 | + |
| 42 | +pub fn invoke_say_hello_with_late_join_parent() { |
| 43 | + let r = Runfiles::create().unwrap(); |
| 44 | + let bin_folder = rlocation!(r, "_main/pkg_a/say_hello").unwrap(); |
| 45 | + |
| 46 | + let bin = bin_folder.parent().unwrap().join("say_hello"); |
| 47 | + println!("Invoking pkg_a binary with late join parent: {}", bin.display()); |
| 48 | + |
| 49 | + invoke_binary(bin); |
| 50 | +} |
0 commit comments