Skip to content

Commit 9da9960

Browse files
authored
fix(cli): fix printing paths on Windows (#6137)
1 parent ed6b81b commit 9da9960

File tree

14 files changed

+72
-35
lines changed

14 files changed

+72
-35
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"cli.rs": "patch"
3+
"tauri-bundler": "patch"
4+
---
5+
6+
On Windows, printing consistent paths on Windows with backslashs only.
7+

core/tauri-utils/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
//! Tauri utility helpers
66
#![warn(missing_docs, rust_2018_idioms)]
77

8-
use std::fmt::Display;
8+
use std::{
9+
fmt::Display,
10+
path::{Path, PathBuf},
11+
};
912

1013
use semver::Version;
1114
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -294,3 +297,12 @@ macro_rules! debug_eprintln {
294297
$crate::consume_unused_variable!($($arg)*);
295298
};
296299
}
300+
301+
/// Reconstructs a path from its components using the platform separator then converts it to String
302+
pub fn display_path<P: AsRef<Path>>(p: P) -> String {
303+
p.as_ref()
304+
.components()
305+
.collect::<PathBuf>()
306+
.display()
307+
.to_string()
308+
}

tooling/bundler/src/bundle.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ mod settings;
1515
mod updater_bundle;
1616
mod windows;
1717

18+
use tauri_utils::display_path;
19+
1820
pub use self::{
1921
category::AppCategory,
2022
settings::{
@@ -101,7 +103,7 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
101103
if bundle.package_type == crate::PackageType::Updater {
102104
note = " (updater)";
103105
}
104-
writeln!(printable_paths, " {}{}", path.display(), note).unwrap();
106+
writeln!(printable_paths, " {}{}", display_path(path), note).unwrap();
105107
}
106108
}
107109

tooling/bundler/src/bundle/updater_bundle.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
},
2222
Settings,
2323
};
24+
use tauri_utils::display_path;
2425

2526
use std::{
2627
fs::{self, File},
@@ -93,7 +94,7 @@ fn bundle_update_macos(settings: &Settings, bundles: &[Bundle]) -> crate::Result
9394
create_tar(source_path, &osx_archived_path)
9495
.with_context(|| "Failed to tar.gz update directory")?;
9596

96-
info!(action = "Bundling"; "{} ({})", osx_archived, osx_archived_path.display());
97+
info!(action = "Bundling"; "{} ({})", osx_archived, display_path(&osx_archived_path));
9798

9899
Ok(vec![osx_archived_path])
99100
}
@@ -135,7 +136,7 @@ fn bundle_update_linux(settings: &Settings, bundles: &[Bundle]) -> crate::Result
135136
create_tar(source_path, &appimage_archived_path)
136137
.with_context(|| "Failed to tar.gz update directory")?;
137138

138-
info!(action = "Bundling"; "{} ({})", appimage_archived, appimage_archived_path.display());
139+
info!(action = "Bundling"; "{} ({})", appimage_archived, display_path(&appimage_archived_path));
139140

140141
Ok(vec![appimage_archived_path])
141142
}
@@ -216,7 +217,7 @@ fn bundle_update_windows(settings: &Settings, bundles: &[Bundle]) -> crate::Resu
216217
});
217218
let archived_path = archived_path.with_extension(format!("{}.zip", bundle_name));
218219

219-
info!(action = "Bundling"; "{}", archived_path.display());
220+
info!(action = "Bundling"; "{}", display_path(&archived_path));
220221

221222
// Create our gzip file
222223
create_zip(&source_path, &archived_path).with_context(|| "Failed to zip update bundle")?;

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::{
2525
path::{Path, PathBuf},
2626
process::Command,
2727
};
28+
use tauri_utils::display_path;
2829
use tauri_utils::{config::WebviewInstallMode, resources::resource_relpath};
2930
use uuid::Uuid;
3031

@@ -313,7 +314,7 @@ fn run_candle(
313314
wxs_file_path.to_string_lossy().to_string(),
314315
format!(
315316
"-dSourceDir={}",
316-
settings.binary_path(main_binary).display()
317+
display_path(settings.binary_path(main_binary))
317318
),
318319
];
319320

@@ -361,7 +362,7 @@ fn run_light(
361362
"-ext".to_string(),
362363
"WixUtilExtension".to_string(),
363364
"-o".to_string(),
364-
output_path.display().to_string(),
365+
display_path(output_path),
365366
];
366367

367368
args.extend(arguments);
@@ -799,14 +800,14 @@ pub fn build_wix_app_installer(
799800
}
800801
),
801802
"-loc".into(),
802-
locale_path.display().to_string(),
803+
display_path(&locale_path),
803804
"*.wixobj".into(),
804805
];
805806
let msi_output_path = output_path.join("output.msi");
806807
let msi_path = app_installer_output_path(settings, &language, &app_version, updater)?;
807808
create_dir_all(msi_path.parent().unwrap())?;
808809

809-
info!(action = "Running"; "light to produce {}", msi_path.display());
810+
info!(action = "Running"; "light to produce {}", display_path(&msi_path));
810811

811812
run_light(
812813
wix_toolset_path,

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
},
1616
Settings,
1717
};
18+
use tauri_utils::display_path;
1819

1920
use anyhow::Context;
2021
use handlebars::{to_json, Handlebars};
@@ -385,7 +386,7 @@ fn build_nsis_app_installer(
385386
));
386387
create_dir_all(nsis_installer_path.parent().unwrap())?;
387388

388-
info!(action = "Running"; "makensis.exe to produce {}", nsis_installer_path.display());
389+
info!(action = "Running"; "makensis.exe to produce {}", display_path(&nsis_installer_path));
389390

390391
#[cfg(target_os = "windows")]
391392
let mut nsis_cmd = Command::new(_nsis_toolset_path.join("makensis.exe"));

tooling/bundler/src/bundle/windows/util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ fn verify(data: &Vec<u8>, hash: &str, mut hasher: impl Digest) -> crate::Result<
7575

7676
#[cfg(target_os = "windows")]
7777
pub fn try_sign(file_path: &PathBuf, settings: &Settings) -> crate::Result<()> {
78+
use tauri_utils::display_path;
79+
7880
if let Some(certificate_thumbprint) = settings.windows().certificate_thumbprint.as_ref() {
79-
info!(action = "Signing"; "{}", file_path.display());
81+
info!(action = "Signing"; "{}", display_path(file_path));
8082
sign(
8183
file_path,
8284
&SignParams {

tooling/cli/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ fn print_signed_updater_archive(output_paths: &[PathBuf]) -> crate::Result<()> {
393393
#[cfg(windows)]
394394
info!(
395395
" {}",
396-
path.display().to_string().replacen(r"\\?\", "", 1)
396+
tauri_utils::display_path(path).replacen(r"\\?\", "", 1)
397397
);
398398
}
399399
Ok(())

tooling/cli/src/info.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn webview2_version() -> crate::Result<Option<String>> {
288288
);
289289
// check 64bit machine-wide installation
290290
let output = Command::new(&powershell_path)
291-
.args(&["-NoProfile", "-Command"])
291+
.args(["-NoProfile", "-Command"])
292292
.arg("Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
293293
.output()?;
294294
if output.status.success() {
@@ -298,7 +298,7 @@ fn webview2_version() -> crate::Result<Option<String>> {
298298
}
299299
// check 32bit machine-wide installation
300300
let output = Command::new(&powershell_path)
301-
.args(&["-NoProfile", "-Command"])
301+
.args(["-NoProfile", "-Command"])
302302
.arg("Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
303303
.output()?;
304304
if output.status.success() {
@@ -308,7 +308,7 @@ fn webview2_version() -> crate::Result<Option<String>> {
308308
}
309309
// check user-wide installation
310310
let output = Command::new(&powershell_path)
311-
.args(&["-NoProfile", "-Command"])
311+
.args(["-NoProfile", "-Command"])
312312
.arg("Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
313313
.output()?;
314314
if output.status.success() {
@@ -342,7 +342,7 @@ fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
342342
}
343343
}
344344
let output = cross_command(vswhere.to_str().unwrap())
345-
.args(&[
345+
.args([
346346
"-prerelease",
347347
"-products",
348348
"*",
@@ -636,7 +636,7 @@ pub fn command(_options: Options) -> Result<()> {
636636
InfoBlock::new("MSVC", "").display();
637637
for i in build_tools {
638638
indent(6);
639-
println!("{}", format!("{} {}", "-".cyan(), i));
639+
println!("{} {}", "-".cyan(), i);
640640
}
641641
}
642642
}

tooling/cli/src/interface/rust.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::helpers::{
3737
app_paths::{app_dir, tauri_dir},
3838
config::{nsis_settings, reload as reload_config, wix_settings, Config},
3939
};
40+
use tauri_utils::display_path;
4041

4142
mod cargo_config;
4243
mod desktop;
@@ -431,10 +432,10 @@ impl Rust {
431432
.unwrap();
432433
for path in watch_folders {
433434
if !ignore_matcher.is_ignore(path, true) {
434-
info!("Watching {} for changes...", path.display());
435+
info!("Watching {} for changes...", display_path(path));
435436
lookup(path, |file_type, p| {
436437
if p != path {
437-
debug!("Watching {} for changes...", p.display());
438+
debug!("Watching {} for changes...", display_path(&p));
438439
let _ = watcher.watcher().watch(
439440
&p,
440441
if file_type.is_dir() {
@@ -474,10 +475,7 @@ impl Rust {
474475
} else {
475476
info!(
476477
"File {} changed. Rebuilding application...",
477-
event_path
478-
.strip_prefix(app_path)
479-
.unwrap_or(&event_path)
480-
.display()
478+
display_path(event_path.strip_prefix(app_path).unwrap_or(&event_path))
481479
);
482480
// When tauri.conf.json is changed, rewrite_manifest will be called
483481
// which will trigger the watcher again

0 commit comments

Comments
 (0)