|
| 1 | +use std::env; |
1 | 2 | use std::io::BufRead; |
2 | | -use std::path::Path; |
| 3 | +use std::path::{Path, PathBuf}; |
3 | 4 |
|
4 | 5 | enum BootstrapReadiness { |
5 | 6 | AlreadyBootstrapped, |
@@ -74,18 +75,31 @@ fn main() { |
74 | 75 | } |
75 | 76 |
|
76 | 77 | fn config_dir() -> std::path::PathBuf { |
77 | | - let home_dir = dirs::home_dir().expect("Can't get home dir"); // TODO: allow override of config dir |
78 | | - home_dir.join(".krustlet/config") |
| 78 | + match env::var("KRUSTLET_DATA_DIR") { |
| 79 | + Ok(config_dir) => PathBuf::from(config_dir), |
| 80 | + _ => { |
| 81 | + let home_dir = dirs::home_dir().expect("Can't get home dir"); |
| 82 | + home_dir.join(".krustlet/config") |
| 83 | + } |
| 84 | + } |
79 | 85 | } |
80 | 86 |
|
81 | 87 | fn config_file_path_str(file_name: impl AsRef<std::path::Path>) -> String { |
82 | 88 | config_dir().join(file_name).to_str().unwrap().to_owned() |
83 | 89 | } |
84 | 90 |
|
85 | 91 | fn build_workspace() -> anyhow::Result<()> { |
86 | | - let build_result = std::process::Command::new("cargo") |
87 | | - .args(&["build"]) |
88 | | - .output()?; |
| 92 | + let mut cmd = std::process::Command::new("cargo"); |
| 93 | + #[cfg(target_family = "unix")] |
| 94 | + cmd.args(&["build"]); |
| 95 | + #[cfg(target_family = "windows")] |
| 96 | + cmd.args(&[ |
| 97 | + "build", |
| 98 | + "--no-default-features", |
| 99 | + "--features", |
| 100 | + "rustls-tls,kubelet/derive", |
| 101 | + ]); |
| 102 | + let build_result = cmd.output()?; |
89 | 103 |
|
90 | 104 | if build_result.status.success() { |
91 | 105 | Ok(()) |
@@ -220,11 +234,10 @@ fn is_resource_gone(kubectl_output: &std::process::Output) -> bool { |
220 | 234 | } |
221 | 235 |
|
222 | 236 | fn run_bootstrap() -> anyhow::Result<()> { |
223 | | - let (shell, ext) = match std::env::consts::OS { |
224 | | - "windows" => Ok(("powershell.exe", "ps1")), |
225 | | - "linux" | "macos" => Ok(("bash", "sh")), |
226 | | - os => Err(anyhow::anyhow!("Unsupported OS {}", os)), |
227 | | - }?; |
| 237 | + #[cfg(target_family = "unix")] |
| 238 | + let (shell, ext) = ("bash", "sh"); |
| 239 | + #[cfg(target_family = "windows")] |
| 240 | + let (shell, ext) = ("powershell.exe", "ps1"); |
228 | 241 |
|
229 | 242 | let repo_root = std::env!("CARGO_MANIFEST_DIR"); |
230 | 243 |
|
@@ -266,7 +279,12 @@ fn launch_kubelet( |
266 | 279 | let port_arg = format!("{}", kubelet_port); |
267 | 280 |
|
268 | 281 | let repo_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 282 | + #[cfg(target_family = "unix")] |
269 | 283 | let bin_path = repo_root.join("target/debug").join(name); |
| 284 | + #[cfg(target_family = "windows")] |
| 285 | + let bin_path = repo_root |
| 286 | + .join("target/debug") |
| 287 | + .join(name.to_owned() + ".exe"); |
270 | 288 |
|
271 | 289 | let stderr = std::fs::File::create(Path::new(LOG_DIR).join(format!("{}.stderr", name)))?; |
272 | 290 |
|
@@ -483,11 +501,20 @@ fn run_test_suite(krustlet_process: &mut OwnedChildProcess) -> anyhow::Result<() |
483 | 501 | let stdout = std::fs::File::create(Path::new(LOG_DIR).join("integration_tests.stdout"))?; |
484 | 502 | let stderr = std::fs::File::create(Path::new(LOG_DIR).join("integration_tests.stderr"))?; |
485 | 503 |
|
486 | | - let mut test_process = std::process::Command::new("cargo") |
487 | | - .args(&["test", "--test", "integration_tests"]) |
488 | | - .stderr(stdout) |
489 | | - .stdout(stderr) |
490 | | - .spawn()?; |
| 504 | + let mut cmd = std::process::Command::new("cargo"); |
| 505 | + #[cfg(target_family = "unix")] |
| 506 | + cmd.args(&["test", "--test", "integration_tests"]); |
| 507 | + #[cfg(target_family = "windows")] |
| 508 | + cmd.args(&[ |
| 509 | + "test", |
| 510 | + "--test", |
| 511 | + "integration_tests", |
| 512 | + "--no-default-features", |
| 513 | + "--features", |
| 514 | + "rustls-tls,kubelet/derive", |
| 515 | + ]); |
| 516 | + |
| 517 | + let mut test_process = cmd.stderr(stdout).stdout(stderr).spawn()?; |
491 | 518 | println!("Integration tests running"); |
492 | 519 | let start = std::time::Instant::now(); |
493 | 520 | loop { |
|
0 commit comments