Skip to content

Commit d75c1b8

Browse files
fix(cli): warn about bundling updater target without appropriate targets, closes #7181 (#7189)
* fix(cli): warn about bundling updater target without appropriate targets, closes #7181 * change tags * cleanup --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 696d77c commit d75c1b8

File tree

8 files changed

+109
-126
lines changed

8 files changed

+109
-126
lines changed

.changes/cli-updater-only.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-cli': 'patch:enhance'
3+
'@tauri-apps/cli': 'patch:enhance'
4+
---
5+
6+
Print a useful error when `updater` bundle target is specified without an updater-enabled target.

core/tauri-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ walkdir = { version = "2", optional = true }
3636
memchr = "2"
3737
semver = "1"
3838
infer = "0.12"
39+
dunce = "1"
3940

4041
[target."cfg(target_os = \"linux\")".dependencies]
4142
heck = "0.4"

core/tauri-utils/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,9 @@ macro_rules! debug_eprintln {
298298
};
299299
}
300300

301-
/// Reconstructs a path from its components using the platform separator then converts it to String
301+
/// Reconstructs a path from its components using the platform separator then converts it to String and removes UNC prefixes on Windows if it exists.
302302
pub fn display_path<P: AsRef<Path>>(p: P) -> String {
303-
p.as_ref()
304-
.components()
305-
.collect::<PathBuf>()
303+
dunce::simplified(&p.as_ref().components().collect::<PathBuf>())
306304
.display()
307305
.to_string()
308306
}

examples/api/src-tauri/Cargo.lock

Lines changed: 1 addition & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/bundler/src/bundle.rs

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ pub struct Bundle {
4343
/// Bundles the project.
4444
/// Returns the list of paths where the bundles can be found.
4545
pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
46-
let mut bundles: Vec<Bundle> = Vec::new();
4746
let package_types = settings.package_types()?;
47+
if package_types.is_empty() {
48+
return Ok(Vec::new());
49+
}
50+
51+
let mut bundles: Vec<Bundle> = Vec::new();
4852

4953
let target_os = settings
5054
.target()
@@ -93,9 +97,23 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
9397
PackageType::AppImage => linux::appimage::bundle_project(&settings)?,
9498

9599
// updater is dependant of multiple bundle, we send our bundles to prevent rebuilding
96-
PackageType::Updater => updater_bundle::bundle_project(&settings, &bundles)?,
100+
PackageType::Updater => {
101+
if !package_types.iter().any(|p| {
102+
matches!(
103+
p,
104+
PackageType::AppImage
105+
| PackageType::MacOsBundle
106+
| PackageType::Nsis
107+
| PackageType::WindowsMsi
108+
)
109+
}) {
110+
warn!("The updater bundle target exists but couldn't find any updater-enabled target, so the updater artifacts won't be generated. Please add one of these targets as well: app, appimage, msi, nsis");
111+
continue;
112+
}
113+
updater_bundle::bundle_project(&settings, &bundles)?
114+
}
97115
_ => {
98-
warn!("ignoring {:?}", package_type);
116+
warn!("ignoring {}", package_type.short_name());
99117
continue;
100118
}
101119
};
@@ -133,26 +151,34 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
133151
}
134152
}
135153

136-
let pluralised = if bundles.len() == 1 {
137-
"bundle"
138-
} else {
139-
"bundles"
140-
};
141-
142-
let mut printable_paths = String::new();
143-
for bundle in &bundles {
144-
for path in &bundle.bundle_paths {
145-
let mut note = "";
146-
if bundle.package_type == crate::PackageType::Updater {
147-
note = " (updater)";
154+
if !bundles.is_empty() {
155+
let bundles_wo_updater = bundles
156+
.iter()
157+
.filter(|b| b.package_type != PackageType::Updater)
158+
.collect::<Vec<_>>();
159+
let pluralised = if bundles_wo_updater.len() == 1 {
160+
"bundle"
161+
} else {
162+
"bundles"
163+
};
164+
165+
let mut printable_paths = String::new();
166+
for bundle in &bundles {
167+
for path in &bundle.bundle_paths {
168+
let mut note = "";
169+
if bundle.package_type == crate::PackageType::Updater {
170+
note = " (updater)";
171+
}
172+
writeln!(printable_paths, " {}{}", display_path(path), note).unwrap();
148173
}
149-
writeln!(printable_paths, " {}{}", display_path(path), note).unwrap();
150174
}
151-
}
152175

153-
info!(action = "Finished"; "{} {} at:\n{}", bundles.len(), pluralised, printable_paths);
176+
info!(action = "Finished"; "{} {} at:\n{}", bundles_wo_updater.len(), pluralised, printable_paths);
154177

155-
Ok(bundles)
178+
Ok(bundles)
179+
} else {
180+
Err(anyhow::anyhow!("No bundles were built").into())
181+
}
156182
}
157183

158184
/// Check to see if there are icons in the settings struct

tooling/bundler/src/bundle/updater_bundle.rs

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
use super::common;
77

8-
#[cfg(target_os = "macos")]
9-
use super::macos::app;
10-
11-
#[cfg(target_os = "linux")]
12-
use super::linux::appimage;
13-
148
use crate::{
159
bundle::{
1610
windows::{
@@ -47,9 +41,9 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
4741
}
4842

4943
#[cfg(target_os = "macos")]
50-
return bundle_update_macos(settings, bundles);
44+
return bundle_update_macos(bundles);
5145
#[cfg(target_os = "linux")]
52-
return bundle_update_linux(settings, bundles);
46+
return bundle_update_linux(bundles);
5347

5448
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
5549
{
@@ -61,84 +55,70 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
6155
// Create simple update-macos.tar.gz
6256
// This is the Mac OS App packaged
6357
#[cfg(target_os = "macos")]
64-
fn bundle_update_macos(settings: &Settings, bundles: &[Bundle]) -> crate::Result<Vec<PathBuf>> {
58+
fn bundle_update_macos(bundles: &[Bundle]) -> crate::Result<Vec<PathBuf>> {
6559
use std::ffi::OsStr;
6660

6761
// find our .app or rebuild our bundle
68-
let bundle_path = match bundles
62+
if let Some(source_path) = bundles
6963
.iter()
7064
.filter(|bundle| bundle.package_type == crate::PackageType::MacOsBundle)
7165
.find_map(|bundle| {
7266
bundle
7367
.bundle_paths
7468
.iter()
7569
.find(|path| path.extension() == Some(OsStr::new("app")))
76-
}) {
77-
Some(path) => vec![path.clone()],
78-
None => app::bundle_project(settings)?,
79-
};
80-
81-
// we expect our .app to be on bundle_path[0]
82-
if bundle_path.is_empty() {
83-
return Err(crate::Error::UnableToFindProject);
84-
}
85-
86-
let source_path = &bundle_path[0];
87-
88-
// add .tar.gz to our path
89-
let osx_archived = format!("{}.tar.gz", source_path.display());
90-
let osx_archived_path = PathBuf::from(&osx_archived);
70+
})
71+
{
72+
// add .tar.gz to our path
73+
let osx_archived = format!("{}.tar.gz", source_path.display());
74+
let osx_archived_path = PathBuf::from(&osx_archived);
9175

92-
// Create our gzip file (need to send parent)
93-
// as we walk the source directory (source isnt added)
94-
create_tar(source_path, &osx_archived_path)
95-
.with_context(|| "Failed to tar.gz update directory")?;
76+
// Create our gzip file (need to send parent)
77+
// as we walk the source directory (source isnt added)
78+
create_tar(source_path, &osx_archived_path)
79+
.with_context(|| "Failed to tar.gz update directory")?;
9680

97-
info!(action = "Bundling"; "{} ({})", osx_archived, display_path(&osx_archived_path));
81+
info!(action = "Bundling"; "{} ({})", osx_archived, display_path(&osx_archived_path));
9882

99-
Ok(vec![osx_archived_path])
83+
Ok(vec![osx_archived_path])
84+
} else {
85+
Err(crate::Error::UnableToFindProject)
86+
}
10087
}
10188

10289
// Create simple update-linux_<arch>.tar.gz
10390
// Including the AppImage
10491
// Right now in linux we hot replace the bin and request a restart
10592
// No assets are replaced
10693
#[cfg(target_os = "linux")]
107-
fn bundle_update_linux(settings: &Settings, bundles: &[Bundle]) -> crate::Result<Vec<PathBuf>> {
94+
fn bundle_update_linux(bundles: &[Bundle]) -> crate::Result<Vec<PathBuf>> {
10895
use std::ffi::OsStr;
10996

11097
// build our app actually we support only appimage on linux
111-
let bundle_path = match bundles
98+
if let Some(source_path) = bundles
11299
.iter()
113100
.filter(|bundle| bundle.package_type == crate::PackageType::AppImage)
114101
.find_map(|bundle| {
115102
bundle
116103
.bundle_paths
117104
.iter()
118105
.find(|path| path.extension() == Some(OsStr::new("AppImage")))
119-
}) {
120-
Some(path) => vec![path.clone()],
121-
None => appimage::bundle_project(settings)?,
122-
};
123-
124-
// we expect our .app to be on bundle[0]
125-
if bundle_path.is_empty() {
126-
return Err(crate::Error::UnableToFindProject);
127-
}
128-
129-
let source_path = &bundle_path[0];
130-
131-
// add .tar.gz to our path
132-
let appimage_archived = format!("{}.tar.gz", source_path.display());
133-
let appimage_archived_path = PathBuf::from(&appimage_archived);
106+
})
107+
{
108+
// add .tar.gz to our path
109+
let appimage_archived = format!("{}.tar.gz", source_path.display());
110+
let appimage_archived_path = PathBuf::from(&appimage_archived);
134111

135-
// Create our gzip file
136-
create_tar(source_path, &appimage_archived_path)
137-
.with_context(|| "Failed to tar.gz update directory")?;
112+
// Create our gzip file
113+
create_tar(source_path, &appimage_archived_path)
114+
.with_context(|| "Failed to tar.gz update directory")?;
138115

139-
info!(action = "Bundling"; "{} ({})", appimage_archived, display_path(&appimage_archived_path));
116+
info!(action = "Bundling"; "{} ({})", appimage_archived, display_path(&appimage_archived_path));
140117

141-
Ok(vec![appimage_archived_path])
118+
Ok(vec![appimage_archived_path])
119+
} else {
120+
Err(crate::Error::UnableToFindProject)
121+
}
142122
}
143123

144124
// Create simple update-win_<arch>.zip

tooling/cli/Cargo.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/src/build.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,22 @@ fn run_hook(name: &str, hook: HookCommand, interface: &AppInterface, debug: bool
382382
}
383383

384384
fn print_signed_updater_archive(output_paths: &[PathBuf]) -> crate::Result<()> {
385-
let pluralised = if output_paths.len() == 1 {
386-
"updater archive"
387-
} else {
388-
"updater archives"
389-
};
390-
let msg = format!("{} {} at:", output_paths.len(), pluralised);
391-
info!("{}", msg);
392-
for path in output_paths {
393-
#[cfg(unix)]
394-
info!(" {}", path.display());
395-
#[cfg(windows)]
396-
info!(
397-
" {}",
398-
tauri_utils::display_path(path).replacen(r"\\?\", "", 1)
399-
);
385+
use std::fmt::Write;
386+
if !output_paths.is_empty() {
387+
let pluralised = if output_paths.len() == 1 {
388+
"updater signature"
389+
} else {
390+
"updater signatures"
391+
};
392+
let mut printable_paths = String::new();
393+
for path in output_paths {
394+
writeln!(
395+
printable_paths,
396+
" {}",
397+
tauri_utils::display_path(path)
398+
)?;
399+
}
400+
info!( action = "Finished"; "{} {} at:\n{}", output_paths.len(), pluralised, printable_paths);
400401
}
401402
Ok(())
402403
}

0 commit comments

Comments
 (0)