Fix running external tools on Windows [rebuild] [release]

This commit is contained in:
Dustin Carlino 2021-04-15 11:29:29 -07:00
parent 9d4587d000
commit d41482febd
3 changed files with 16 additions and 11 deletions

View File

@ -1,7 +1,7 @@
// TODO This doesn't really belong in gameplay/freeform
use map_gui::load::FutureLoader;
use map_gui::tools::{find_exe_dir, RunCommand};
use map_gui::tools::{find_exe, RunCommand};
use widgetry::EventCtx;
use crate::app::{App, Transition};
@ -27,7 +27,7 @@ pub fn import(ctx: &mut EventCtx) -> Transition {
ctx,
app,
vec![
format!("{}/import_grid2demand", find_exe_dir()),
find_exe("import_grid2demand"),
format!("--map={}", app.primary.map.get_name().path()),
format!("--input={}", path),
],

View File

@ -9,7 +9,7 @@ use widgetry::{
};
use crate::load::MapLoader;
use crate::tools::{find_exe_dir, open_browser, PopupMsg};
use crate::tools::{find_exe, open_browser, PopupMsg};
use crate::AppLike;
pub struct ImportCity<A: AppLike> {
@ -98,10 +98,8 @@ impl<A: AppLike + 'static> State<A> for ImportCity<A> {
Transition::Keep
}
"Import the area from your clipboard" => {
let mut args = vec![
format!("{}/one_step_import", find_exe_dir()),
"boundary.geojson".to_string(),
];
let mut args =
vec![find_exe("one_step_import"), "boundary.geojson".to_string()];
if self.panel.is_checked("left handed driving") {
args.push("--drive_on_left".to_string());
}

View File

@ -213,9 +213,9 @@ pub fn open_browser<I: AsRef<str>>(url: I) {
let _ = webbrowser::open(url.as_ref());
}
/// Native-only: Locate the directory with other executables.
pub fn find_exe_dir() -> &'static str {
vec![
/// Returns the path to an executable. Native-only.
pub fn find_exe(cmd: &str) -> String {
let dir = vec![
"./target/release",
"../target/release",
"../../target/release",
@ -224,5 +224,12 @@ pub fn find_exe_dir() -> &'static str {
]
.into_iter()
.find(|x| std::path::Path::new(x).exists())
.unwrap_or("./target/release")
.unwrap_or("./target/release");
// Apparently std::path on Windows doesn't do any of this correction. We could build up a
// PathBuf properly, I guess
if cfg!(windows) {
format!("{}/{}.exe", dir, cmd).replace("/", "\\")
} else {
format!("{}/{}", dir, cmd)
}
}