Fix run_make on Windows

This commit is contained in:
Luke Street 2025-02-09 11:11:09 -07:00
parent 561a9107e2
commit 3c66ac3d54
6 changed files with 22 additions and 26 deletions

7
Cargo.lock generated
View File

@ -3013,7 +3013,6 @@ dependencies = [
"notify-debouncer-full", "notify-debouncer-full",
"num-traits", "num-traits",
"object", "object",
"path-slash",
"pbjson", "pbjson",
"pbjson-build", "pbjson-build",
"ppc750cl", "ppc750cl",
@ -3231,12 +3230,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "path-slash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42"
[[package]] [[package]]
name = "pathdiff" name = "pathdiff"
version = "0.2.3" version = "0.2.3"

View File

@ -52,7 +52,6 @@ bindings = [
build = [ build = [
"dep:notify", "dep:notify",
"dep:notify-debouncer-full", "dep:notify-debouncer-full",
"dep:path-slash",
"dep:reqwest", "dep:reqwest",
"dep:self_update", "dep:self_update",
"dep:shell-escape", "dep:shell-escape",
@ -186,7 +185,6 @@ tempfile = { version = "3.15", optional = true }
time = { version = "0.3", optional = true } time = { version = "0.3", optional = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
path-slash = { version = "0.2", optional = true }
winapi = { version = "0.3", optional = true } winapi = { version = "0.3", optional = true }
# For Linux static binaries, use rustls # For Linux static binaries, use rustls

View File

@ -2,7 +2,7 @@ pub mod watcher;
use std::process::Command; use std::process::Command;
use typed_path::Utf8PlatformPathBuf; use typed_path::{Utf8PlatformPathBuf, Utf8UnixPath};
pub struct BuildStatus { pub struct BuildStatus {
pub success: bool, pub success: bool,
@ -31,7 +31,7 @@ pub struct BuildConfig {
pub selected_wsl_distro: Option<String>, pub selected_wsl_distro: Option<String>,
} }
pub fn run_make(config: &BuildConfig, arg: &str) -> BuildStatus { pub fn run_make(config: &BuildConfig, arg: &Utf8UnixPath) -> BuildStatus {
let Some(cwd) = &config.project_dir else { let Some(cwd) = &config.project_dir else {
return BuildStatus { return BuildStatus {
success: false, success: false,
@ -51,7 +51,6 @@ pub fn run_make(config: &BuildConfig, arg: &str) -> BuildStatus {
let mut command = { let mut command = {
use std::os::windows::process::CommandExt; use std::os::windows::process::CommandExt;
use path_slash::PathExt;
let mut command = if config.selected_wsl_distro.is_some() { let mut command = if config.selected_wsl_distro.is_some() {
Command::new("wsl") Command::new("wsl")
} else { } else {
@ -61,21 +60,21 @@ pub fn run_make(config: &BuildConfig, arg: &str) -> BuildStatus {
// Strip distro root prefix \\wsl.localhost\{distro} // Strip distro root prefix \\wsl.localhost\{distro}
let wsl_path_prefix = format!("\\\\wsl.localhost\\{}", distro); let wsl_path_prefix = format!("\\\\wsl.localhost\\{}", distro);
let cwd = match cwd.strip_prefix(wsl_path_prefix) { let cwd = match cwd.strip_prefix(wsl_path_prefix) {
Ok(new_cwd) => format!("/{}", new_cwd.to_slash_lossy().as_ref()), Ok(new_cwd) => Utf8UnixPath::new("/").join(new_cwd.with_unix_encoding()),
Err(_) => cwd.to_string_lossy().to_string(), Err(_) => cwd.with_unix_encoding(),
}; };
command command
.arg("--cd") .arg("--cd")
.arg(cwd) .arg(cwd.as_str())
.arg("-d") .arg("-d")
.arg(distro) .arg(distro)
.arg("--") .arg("--")
.arg(make) .arg(make)
.args(make_args) .args(make_args)
.arg(arg.to_slash_lossy().as_ref()); .arg(arg.as_str());
} else { } else {
command.current_dir(cwd).args(make_args).arg(arg.to_slash_lossy().as_ref()); command.current_dir(cwd).args(make_args).arg(arg.as_str());
} }
command.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW); command.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW);
command command

View File

@ -1,6 +1,6 @@
use std::{sync::mpsc::Receiver, task::Waker}; use std::{sync::mpsc::Receiver, task::Waker};
use anyhow::{anyhow, Error, Result}; use anyhow::{bail, Error, Result};
use time::OffsetDateTime; use time::OffsetDateTime;
use typed_path::Utf8PlatformPathBuf; use typed_path::Utf8PlatformPathBuf;
@ -43,14 +43,20 @@ fn run_build(
.as_ref() .as_ref()
.ok_or_else(|| Error::msg("Missing project dir"))?; .ok_or_else(|| Error::msg("Missing project dir"))?;
if let Some(target_path) = &config.target_path { if let Some(target_path) = &config.target_path {
target_path_rel = Some(target_path.strip_prefix(project_dir).map_err(|_| { target_path_rel = match target_path.strip_prefix(project_dir) {
anyhow!("Target path '{}' doesn't begin with '{}'", target_path, project_dir) Ok(p) => Some(p.with_unix_encoding()),
})?); Err(_) => {
bail!("Target path '{}' doesn't begin with '{}'", target_path, project_dir);
}
};
} }
if let Some(base_path) = &config.base_path { if let Some(base_path) = &config.base_path {
base_path_rel = Some(base_path.strip_prefix(project_dir).map_err(|_| { base_path_rel = match base_path.strip_prefix(project_dir) {
anyhow!("Base path '{}' doesn't begin with '{}'", base_path, project_dir) Ok(p) => Some(p.with_unix_encoding()),
})?); Err(_) => {
bail!("Base path '{}' doesn't begin with '{}'", base_path, project_dir);
}
};
}; };
} }

View File

@ -384,7 +384,7 @@ fn object_context_ui(ui: &mut egui::Ui, object: &ObjectConfig) {
.clicked() .clicked()
{ {
log::info!("Opening file {}", source_path); log::info!("Opening file {}", source_path);
if let Err(e) = open::that_detached(source_path) { if let Err(e) = open::that_detached(source_path.as_str()) {
log::error!("Failed to open source file: {e}"); log::error!("Failed to open source file: {e}");
} }
ui.close_menu(); ui.close_menu();

View File

@ -281,7 +281,7 @@ impl DiffViewState {
state.config.selected_obj.as_ref().and_then(|obj| obj.source_path.as_ref()) state.config.selected_obj.as_ref().and_then(|obj| obj.source_path.as_ref())
{ {
log::info!("Opening file {}", source_path); log::info!("Opening file {}", source_path);
open::that_detached(source_path).unwrap_or_else(|err| { open::that_detached(source_path.as_str()).unwrap_or_else(|err| {
log::error!("Failed to open source file: {err}"); log::error!("Failed to open source file: {err}");
}); });
} }