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

View File

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

View File

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

View File

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