Skip to content

Commit

Permalink
fix(cli): warn about bundling updater target without appropriate targ…
Browse files Browse the repository at this point in the history
…ets, 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>
  • Loading branch information
amrbashir and lucasfernog authored Jun 13, 2023
1 parent 696d77c commit d75c1b8
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 126 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-updater-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:enhance'
'@tauri-apps/cli': 'patch:enhance'
---

Print a useful error when `updater` bundle target is specified without an updater-enabled target.
1 change: 1 addition & 0 deletions core/tauri-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ walkdir = { version = "2", optional = true }
memchr = "2"
semver = "1"
infer = "0.12"
dunce = "1"

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.4"
Expand Down
6 changes: 2 additions & 4 deletions core/tauri-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,9 @@ macro_rules! debug_eprintln {
};
}

/// Reconstructs a path from its components using the platform separator then converts it to String
/// Reconstructs a path from its components using the platform separator then converts it to String and removes UNC prefixes on Windows if it exists.
pub fn display_path<P: AsRef<Path>>(p: P) -> String {
p.as_ref()
.components()
.collect::<PathBuf>()
dunce::simplified(&p.as_ref().components().collect::<PathBuf>())
.display()
.to_string()
}
33 changes: 1 addition & 32 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 45 additions & 19 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ pub struct Bundle {
/// Bundles the project.
/// Returns the list of paths where the bundles can be found.
pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
let mut bundles: Vec<Bundle> = Vec::new();
let package_types = settings.package_types()?;
if package_types.is_empty() {
return Ok(Vec::new());
}

let mut bundles: Vec<Bundle> = Vec::new();

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

// updater is dependant of multiple bundle, we send our bundles to prevent rebuilding
PackageType::Updater => updater_bundle::bundle_project(&settings, &bundles)?,
PackageType::Updater => {
if !package_types.iter().any(|p| {
matches!(
p,
PackageType::AppImage
| PackageType::MacOsBundle
| PackageType::Nsis
| PackageType::WindowsMsi
)
}) {
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");
continue;
}
updater_bundle::bundle_project(&settings, &bundles)?
}
_ => {
warn!("ignoring {:?}", package_type);
warn!("ignoring {}", package_type.short_name());
continue;
}
};
Expand Down Expand Up @@ -133,26 +151,34 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
}
}

let pluralised = if bundles.len() == 1 {
"bundle"
} else {
"bundles"
};

let mut printable_paths = String::new();
for bundle in &bundles {
for path in &bundle.bundle_paths {
let mut note = "";
if bundle.package_type == crate::PackageType::Updater {
note = " (updater)";
if !bundles.is_empty() {
let bundles_wo_updater = bundles
.iter()
.filter(|b| b.package_type != PackageType::Updater)
.collect::<Vec<_>>();
let pluralised = if bundles_wo_updater.len() == 1 {
"bundle"
} else {
"bundles"
};

let mut printable_paths = String::new();
for bundle in &bundles {
for path in &bundle.bundle_paths {
let mut note = "";
if bundle.package_type == crate::PackageType::Updater {
note = " (updater)";
}
writeln!(printable_paths, " {}{}", display_path(path), note).unwrap();
}
writeln!(printable_paths, " {}{}", display_path(path), note).unwrap();
}
}

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

Ok(bundles)
Ok(bundles)
} else {
Err(anyhow::anyhow!("No bundles were built").into())
}
}

/// Check to see if there are icons in the settings struct
Expand Down
86 changes: 33 additions & 53 deletions tooling/bundler/src/bundle/updater_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

use super::common;

#[cfg(target_os = "macos")]
use super::macos::app;

#[cfg(target_os = "linux")]
use super::linux::appimage;

use crate::{
bundle::{
windows::{
Expand Down Expand Up @@ -47,9 +41,9 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
}

#[cfg(target_os = "macos")]
return bundle_update_macos(settings, bundles);
return bundle_update_macos(bundles);
#[cfg(target_os = "linux")]
return bundle_update_linux(settings, bundles);
return bundle_update_linux(bundles);

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

// find our .app or rebuild our bundle
let bundle_path = match bundles
if let Some(source_path) = bundles
.iter()
.filter(|bundle| bundle.package_type == crate::PackageType::MacOsBundle)
.find_map(|bundle| {
bundle
.bundle_paths
.iter()
.find(|path| path.extension() == Some(OsStr::new("app")))
}) {
Some(path) => vec![path.clone()],
None => app::bundle_project(settings)?,
};

// we expect our .app to be on bundle_path[0]
if bundle_path.is_empty() {
return Err(crate::Error::UnableToFindProject);
}

let source_path = &bundle_path[0];

// add .tar.gz to our path
let osx_archived = format!("{}.tar.gz", source_path.display());
let osx_archived_path = PathBuf::from(&osx_archived);
})
{
// add .tar.gz to our path
let osx_archived = format!("{}.tar.gz", source_path.display());
let osx_archived_path = PathBuf::from(&osx_archived);

// Create our gzip file (need to send parent)
// as we walk the source directory (source isnt added)
create_tar(source_path, &osx_archived_path)
.with_context(|| "Failed to tar.gz update directory")?;
// Create our gzip file (need to send parent)
// as we walk the source directory (source isnt added)
create_tar(source_path, &osx_archived_path)
.with_context(|| "Failed to tar.gz update directory")?;

info!(action = "Bundling"; "{} ({})", osx_archived, display_path(&osx_archived_path));
info!(action = "Bundling"; "{} ({})", osx_archived, display_path(&osx_archived_path));

Ok(vec![osx_archived_path])
Ok(vec![osx_archived_path])
} else {
Err(crate::Error::UnableToFindProject)
}
}

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

// build our app actually we support only appimage on linux
let bundle_path = match bundles
if let Some(source_path) = bundles
.iter()
.filter(|bundle| bundle.package_type == crate::PackageType::AppImage)
.find_map(|bundle| {
bundle
.bundle_paths
.iter()
.find(|path| path.extension() == Some(OsStr::new("AppImage")))
}) {
Some(path) => vec![path.clone()],
None => appimage::bundle_project(settings)?,
};

// we expect our .app to be on bundle[0]
if bundle_path.is_empty() {
return Err(crate::Error::UnableToFindProject);
}

let source_path = &bundle_path[0];

// add .tar.gz to our path
let appimage_archived = format!("{}.tar.gz", source_path.display());
let appimage_archived_path = PathBuf::from(&appimage_archived);
})
{
// add .tar.gz to our path
let appimage_archived = format!("{}.tar.gz", source_path.display());
let appimage_archived_path = PathBuf::from(&appimage_archived);

// Create our gzip file
create_tar(source_path, &appimage_archived_path)
.with_context(|| "Failed to tar.gz update directory")?;
// Create our gzip file
create_tar(source_path, &appimage_archived_path)
.with_context(|| "Failed to tar.gz update directory")?;

info!(action = "Bundling"; "{} ({})", appimage_archived, display_path(&appimage_archived_path));
info!(action = "Bundling"; "{} ({})", appimage_archived, display_path(&appimage_archived_path));

Ok(vec![appimage_archived_path])
Ok(vec![appimage_archived_path])
} else {
Err(crate::Error::UnableToFindProject)
}
}

// Create simple update-win_<arch>.zip
Expand Down
8 changes: 5 additions & 3 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions tooling/cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,22 @@ fn run_hook(name: &str, hook: HookCommand, interface: &AppInterface, debug: bool
}

fn print_signed_updater_archive(output_paths: &[PathBuf]) -> crate::Result<()> {
let pluralised = if output_paths.len() == 1 {
"updater archive"
} else {
"updater archives"
};
let msg = format!("{} {} at:", output_paths.len(), pluralised);
info!("{}", msg);
for path in output_paths {
#[cfg(unix)]
info!(" {}", path.display());
#[cfg(windows)]
info!(
" {}",
tauri_utils::display_path(path).replacen(r"\\?\", "", 1)
);
use std::fmt::Write;
if !output_paths.is_empty() {
let pluralised = if output_paths.len() == 1 {
"updater signature"
} else {
"updater signatures"
};
let mut printable_paths = String::new();
for path in output_paths {
writeln!(
printable_paths,
" {}",
tauri_utils::display_path(path)
)?;
}
info!( action = "Finished"; "{} {} at:\n{}", output_paths.len(), pluralised, printable_paths);
}
Ok(())
}
Expand Down

0 comments on commit d75c1b8

Please sign in to comment.