Skip to content

Commit fcee4c2

Browse files
authored
refactor(bundler): finish initial documentation, reorganize modules (#1662)
1 parent 4f1e87f commit fcee4c2

File tree

31 files changed

+724
-632
lines changed

31 files changed

+724
-632
lines changed

.changes/bundler-docs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
Adds basic library documentation.

.changes/bundler-package-types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
The `PackageTypes` enum now includes all options, including Windows packages.

tooling/bundler/Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ edition = "2018"
1616

1717
[dependencies]
1818
ar = "0.8.0"
19-
chrono = "0.4"
20-
dirs-next = "2.0.0"
2119
glob = "0.3.0"
2220
icns = "0.3"
2321
image = "0.23.14"
@@ -35,18 +33,19 @@ walkdir = "2"
3533
handlebars = { version = "3.5" }
3634
zip = { version = "0.5" }
3735
tempfile = "3.2.0"
38-
regex = { version = "1" }
36+
regex = "1"
3937

4038
[target."cfg(target_os = \"windows\")".dependencies]
41-
attohttpc = { version = "0.17.0" }
42-
regex = { version = "1" }
39+
attohttpc = "0.17"
4340
uuid = { version = "0.8", features = [ "v5" ] }
4441
bitness = "0.4"
4542
winreg = "0.8"
43+
sha2 = "0.9"
44+
hex = "0.4"
4645

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

5150
[lib]
5251
name = "tauri_bundler"

tooling/bundler/src/bundle.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,37 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
mod appimage_bundle;
65
mod category;
7-
pub mod common;
8-
mod deb_bundle;
9-
mod dmg_bundle;
10-
mod ios_bundle;
11-
mod macos_bundle;
12-
#[cfg(target_os = "windows")]
13-
mod msi_bundle;
6+
mod common;
7+
#[cfg(target_os = "linux")]
8+
mod linux;
9+
#[cfg(target_os = "macos")]
10+
mod macos;
1411
mod path_utils;
1512
mod platform;
16-
mod rpm_bundle;
1713
mod settings;
1814
mod updater_bundle;
1915
#[cfg(target_os = "windows")]
20-
mod wix;
16+
mod windows;
2117

2218
pub use self::{
2319
category::AppCategory,
24-
common::{print_error, print_info},
2520
settings::{
2621
BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings, PackageType,
2722
Settings, SettingsBuilder, UpdaterSettings,
2823
},
2924
};
30-
#[cfg(windows)]
3125
pub use settings::{WindowsSettings, WixSettings};
3226

33-
use common::print_finished;
27+
use common::{print_finished, print_info};
3428

3529
use std::path::PathBuf;
3630

31+
/// Generated bundle metadata.
3732
pub struct Bundle {
38-
// the package type
33+
/// The package type.
3934
pub package_type: PackageType,
40-
/// all paths for this package
35+
/// All paths for this package.
4136
pub bundle_paths: Vec<PathBuf>,
4237
}
4338

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

5045
for package_type in &package_types {
5146
let bundle_paths = match package_type {
52-
PackageType::MacOsBundle => macos_bundle::bundle_project(&settings)?,
53-
PackageType::IosBundle => ios_bundle::bundle_project(&settings)?,
47+
#[cfg(target_os = "macos")]
48+
PackageType::MacOsBundle => macos::app::bundle_project(&settings)?,
49+
#[cfg(target_os = "macos")]
50+
PackageType::IosBundle => macos::ios::bundle_project(&settings)?,
5451
#[cfg(target_os = "windows")]
55-
PackageType::WindowsMsi => msi_bundle::bundle_project(&settings)?,
56-
PackageType::Deb => deb_bundle::bundle_project(&settings)?,
57-
PackageType::Rpm => rpm_bundle::bundle_project(&settings)?,
58-
PackageType::AppImage => appimage_bundle::bundle_project(&settings)?,
52+
PackageType::WindowsMsi => windows::msi::bundle_project(&settings)?,
53+
#[cfg(target_os = "linux")]
54+
PackageType::Deb => linux::debian::bundle_project(&settings)?,
55+
#[cfg(target_os = "linux")]
56+
PackageType::Rpm => linux::rpm::bundle_project(&settings)?,
57+
#[cfg(target_os = "linux")]
58+
PackageType::AppImage => linux::appimage::bundle_project(&settings)?,
5959
// dmg is dependant of MacOsBundle, we send our bundles to prevent rebuilding
60-
PackageType::Dmg => dmg_bundle::bundle_project(&settings, &bundles)?,
60+
#[cfg(target_os = "macos")]
61+
PackageType::Dmg => macos::dmg::bundle_project(&settings, &bundles)?,
6162
// updater is dependant of multiple bundle, we send our bundles to prevent rebuilding
6263
PackageType::Updater => updater_bundle::bundle_project(&settings, &bundles)?,
64+
_ => {
65+
print_info(&format!("ignoring {:?}", package_type))?;
66+
continue;
67+
}
6368
};
6469

6570
bundles.push(Bundle {

tooling/bundler/src/bundle/category.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const MACOS_APP_CATEGORY_PREFIX: &str = "public.app-category.";
1313
// that don't fit these; we should add those here too.
1414
/// The possible app categories.
1515
/// Corresponds to `LSApplicationCategoryType` on macOS and the GNOME desktop categories on Debian.
16+
#[allow(missing_docs)]
1617
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1718
pub enum AppCategory {
1819
Business,

tooling/bundler/src/bundle/common.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn create_file(path: &Path) -> crate::Result<BufWriter<File>> {
3737

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

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

177-
/// Prints a message to stderr, in the same format that `cargo` uses,
178-
/// indicating that we have finished the the given signatures.
179-
pub fn print_signed_updater_archive(output_paths: &[PathBuf]) -> crate::Result<()> {
180-
let pluralised = if output_paths.len() == 1 {
181-
"updater archive"
182-
} else {
183-
"updater archives"
184-
};
185-
let msg = format!("{} {} at:", output_paths.len(), pluralised);
186-
print_progress("Signed", &msg)?;
187-
for path in output_paths {
188-
println!(" {}", path.display());
189-
}
190-
Ok(())
191-
}
192-
193180
/// Prints a formatted bundle progress to stderr.
194181
fn print_progress(step: &str, msg: &str) -> crate::Result<()> {
195182
let mut output = StandardStream::stderr(ColorChoice::Always);
@@ -202,6 +189,7 @@ fn print_progress(step: &str, msg: &str) -> crate::Result<()> {
202189
}
203190

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

226-
/// Prints an error to stderr, in the same format that `cargo` uses.
227-
pub fn print_error(error: &anyhow::Error) -> crate::Result<()> {
228-
let mut output = StandardStream::stderr(ColorChoice::Always);
229-
let _ = output.set_color(ColorSpec::new().set_fg(Some(Color::Red)).set_bold(true));
230-
write!(output, "error:")?;
231-
output.reset()?;
232-
let _ = output.set_color(ColorSpec::new().set_bold(true));
233-
writeln!(output, " {}", error)?;
234-
output.reset()?;
235-
for cause in error.chain().skip(1) {
236-
writeln!(output, " Caused by: {}", cause)?;
237-
}
238-
// Add Backtrace once its stable.
239-
// if let Some(backtrace) = error.backtrace() {
240-
// writeln!(output, "{:?}", backtrace)?;
241-
// }
242-
output.flush()?;
243-
std::process::exit(1)
244-
}
245-
246214
pub fn execute_with_verbosity(cmd: &mut Command, settings: &Settings) -> crate::Result<()> {
247215
let stdio_config = if settings.is_verbose() {
248216
Stdio::piped

tooling/bundler/src/bundle/appimage_bundle.rs renamed to tooling/bundler/src/bundle/linux/appimage.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use super::{common, deb_bundle, path_utils};
5+
use super::{
6+
super::{common, path_utils},
7+
debian,
8+
};
69
use crate::Settings;
710

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

3639
// generate deb_folder structure
37-
let (_, icons) = deb_bundle::generate_data(settings, &package_dir)?;
38-
let icons: Vec<deb_bundle::DebIcon> = icons.into_iter().collect();
40+
let (_, icons) = debian::generate_data(settings, &package_dir)?;
41+
let icons: Vec<debian::DebIcon> = icons.into_iter().collect();
3942

4043
let output_path = settings.project_out_directory().join("bundle/appimage");
4144
if output_path.exists() {

tooling/bundler/src/bundle/deb_bundle.rs renamed to tooling/bundler/src/bundle/linux/debian.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// metadata, as well as generating the md5sums file. Currently we do not
2323
// generate postinst or prerm files.
2424

25-
use super::common;
25+
use super::super::common;
2626
use crate::Settings;
2727

2828
use anyhow::Context;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod appimage;
2+
pub mod debian;
3+
pub mod rpm;

0 commit comments

Comments
 (0)