Skip to content

Commit

Permalink
refactor(bundler): finish initial documentation, reorganize modules (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Apr 30, 2021
1 parent 4f1e87f commit fcee4c2
Show file tree
Hide file tree
Showing 31 changed files with 724 additions and 632 deletions.
5 changes: 5 additions & 0 deletions .changes/bundler-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Adds basic library documentation.
5 changes: 5 additions & 0 deletions .changes/bundler-package-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

The `PackageTypes` enum now includes all options, including Windows packages.
15 changes: 7 additions & 8 deletions tooling/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ edition = "2018"

[dependencies]
ar = "0.8.0"
chrono = "0.4"
dirs-next = "2.0.0"
glob = "0.3.0"
icns = "0.3"
image = "0.23.14"
Expand All @@ -35,18 +33,19 @@ walkdir = "2"
handlebars = { version = "3.5" }
zip = { version = "0.5" }
tempfile = "3.2.0"
regex = { version = "1" }
regex = "1"

[target."cfg(target_os = \"windows\")".dependencies]
attohttpc = { version = "0.17.0" }
regex = { version = "1" }
attohttpc = "0.17"
uuid = { version = "0.8", features = [ "v5" ] }
bitness = "0.4"
winreg = "0.8"
sha2 = "0.9"
hex = "0.4"

[target."cfg(not(target_os = \"linux\"))".dependencies]
sha2 = { version = "0.9" }
hex = { version = "0.4" }
[target."cfg(target_os = \"macos\")".dependencies]
chrono = "0.4"
dirs-next = "2.0"

[lib]
name = "tauri_bundler"
Expand Down
49 changes: 27 additions & 22 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

mod appimage_bundle;
mod category;
pub mod common;
mod deb_bundle;
mod dmg_bundle;
mod ios_bundle;
mod macos_bundle;
#[cfg(target_os = "windows")]
mod msi_bundle;
mod common;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
mod path_utils;
mod platform;
mod rpm_bundle;
mod settings;
mod updater_bundle;
#[cfg(target_os = "windows")]
mod wix;
mod windows;

pub use self::{
category::AppCategory,
common::{print_error, print_info},
settings::{
BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings, PackageType,
Settings, SettingsBuilder, UpdaterSettings,
},
};
#[cfg(windows)]
pub use settings::{WindowsSettings, WixSettings};

use common::print_finished;
use common::{print_finished, print_info};

use std::path::PathBuf;

/// Generated bundle metadata.
pub struct Bundle {
// the package type
/// The package type.
pub package_type: PackageType,
/// all paths for this package
/// All paths for this package.
pub bundle_paths: Vec<PathBuf>,
}

Expand All @@ -49,17 +44,27 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {

for package_type in &package_types {
let bundle_paths = match package_type {
PackageType::MacOsBundle => macos_bundle::bundle_project(&settings)?,
PackageType::IosBundle => ios_bundle::bundle_project(&settings)?,
#[cfg(target_os = "macos")]
PackageType::MacOsBundle => macos::app::bundle_project(&settings)?,
#[cfg(target_os = "macos")]
PackageType::IosBundle => macos::ios::bundle_project(&settings)?,
#[cfg(target_os = "windows")]
PackageType::WindowsMsi => msi_bundle::bundle_project(&settings)?,
PackageType::Deb => deb_bundle::bundle_project(&settings)?,
PackageType::Rpm => rpm_bundle::bundle_project(&settings)?,
PackageType::AppImage => appimage_bundle::bundle_project(&settings)?,
PackageType::WindowsMsi => windows::msi::bundle_project(&settings)?,
#[cfg(target_os = "linux")]
PackageType::Deb => linux::debian::bundle_project(&settings)?,
#[cfg(target_os = "linux")]
PackageType::Rpm => linux::rpm::bundle_project(&settings)?,
#[cfg(target_os = "linux")]
PackageType::AppImage => linux::appimage::bundle_project(&settings)?,
// dmg is dependant of MacOsBundle, we send our bundles to prevent rebuilding
PackageType::Dmg => dmg_bundle::bundle_project(&settings, &bundles)?,
#[cfg(target_os = "macos")]
PackageType::Dmg => macos::dmg::bundle_project(&settings, &bundles)?,
// updater is dependant of multiple bundle, we send our bundles to prevent rebuilding
PackageType::Updater => updater_bundle::bundle_project(&settings, &bundles)?,
_ => {
print_info(&format!("ignoring {:?}", package_type))?;
continue;
}
};

bundles.push(Bundle {
Expand Down
1 change: 1 addition & 0 deletions tooling/bundler/src/bundle/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const MACOS_APP_CATEGORY_PREFIX: &str = "public.app-category.";
// that don't fit these; we should add those here too.
/// The possible app categories.
/// Corresponds to `LSApplicationCategoryType` on macOS and the GNOME desktop categories on Debian.
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AppCategory {
Business,
Expand Down
40 changes: 4 additions & 36 deletions tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn create_file(path: &Path) -> crate::Result<BufWriter<File>> {

/// Makes a symbolic link to a directory.
#[cfg(unix)]
#[allow(dead_code)]
fn symlink_dir(src: &Path, dst: &Path) -> io::Result<()> {
std::os::unix::fs::symlink(src, dst)
}
Expand All @@ -49,6 +50,7 @@ fn symlink_dir(src: &Path, dst: &Path) -> io::Result<()> {

/// Makes a symbolic link to a file.
#[cfg(unix)]
#[allow(dead_code)]
fn symlink_file(src: &Path, dst: &Path) -> io::Result<()> {
std::os::unix::fs::symlink(src, dst)
}
Expand Down Expand Up @@ -87,6 +89,7 @@ pub fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> crate::Result<
/// parent directories of the destination path as necessary. Fails if the
/// source path is not a directory or doesn't exist, or if the destination path
/// already exists.
#[allow(dead_code)]
pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
if !from.exists() {
return Err(crate::Error::GenericError(format!(
Expand Down Expand Up @@ -174,22 +177,6 @@ pub fn print_finished(bundles: &[crate::bundle::Bundle]) -> crate::Result<()> {
Ok(())
}

/// Prints a message to stderr, in the same format that `cargo` uses,
/// indicating that we have finished the the given signatures.
pub 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);
print_progress("Signed", &msg)?;
for path in output_paths {
println!(" {}", path.display());
}
Ok(())
}

/// Prints a formatted bundle progress to stderr.
fn print_progress(step: &str, msg: &str) -> crate::Result<()> {
let mut output = StandardStream::stderr(ColorChoice::Always);
Expand All @@ -202,6 +189,7 @@ fn print_progress(step: &str, msg: &str) -> crate::Result<()> {
}

/// Prints a warning message to stderr, in the same format that `cargo` uses.
#[allow(dead_code)]
pub fn print_warning(message: &str) -> crate::Result<()> {
let mut output = StandardStream::stderr(ColorChoice::Always);
let _ = output.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true));
Expand All @@ -223,26 +211,6 @@ pub fn print_info(message: &str) -> crate::Result<()> {
Ok(())
}

/// Prints an error to stderr, in the same format that `cargo` uses.
pub fn print_error(error: &anyhow::Error) -> crate::Result<()> {
let mut output = StandardStream::stderr(ColorChoice::Always);
let _ = output.set_color(ColorSpec::new().set_fg(Some(Color::Red)).set_bold(true));
write!(output, "error:")?;
output.reset()?;
let _ = output.set_color(ColorSpec::new().set_bold(true));
writeln!(output, " {}", error)?;
output.reset()?;
for cause in error.chain().skip(1) {
writeln!(output, " Caused by: {}", cause)?;
}
// Add Backtrace once its stable.
// if let Some(backtrace) = error.backtrace() {
// writeln!(output, "{:?}", backtrace)?;
// }
output.flush()?;
std::process::exit(1)
}

pub fn execute_with_verbosity(cmd: &mut Command, settings: &Settings) -> crate::Result<()> {
let stdio_config = if settings.is_verbose() {
Stdio::piped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::{common, deb_bundle, path_utils};
use super::{
super::{common, path_utils},
debian,
};
use crate::Settings;

use handlebars::Handlebars;
Expand Down Expand Up @@ -34,8 +37,8 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
let package_dir = settings.project_out_directory().join("bundle/appimage_deb");

// generate deb_folder structure
let (_, icons) = deb_bundle::generate_data(settings, &package_dir)?;
let icons: Vec<deb_bundle::DebIcon> = icons.into_iter().collect();
let (_, icons) = debian::generate_data(settings, &package_dir)?;
let icons: Vec<debian::DebIcon> = icons.into_iter().collect();

let output_path = settings.project_out_directory().join("bundle/appimage");
if output_path.exists() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// metadata, as well as generating the md5sums file. Currently we do not
// generate postinst or prerm files.

use super::common;
use super::super::common;
use crate::Settings;

use anyhow::Context;
Expand Down
3 changes: 3 additions & 0 deletions tooling/bundler/src/bundle/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod appimage;
pub mod debian;
pub mod rpm;
File renamed without changes.
Loading

0 comments on commit fcee4c2

Please sign in to comment.