feat(bundler): allow including custom files on debian package, fix #1428 (#1613)

This commit is contained in:
Lucas Fernandes Nogueira 2021-04-25 01:46:04 -03:00 committed by GitHub
parent 11dc184e01
commit 9e87fe6a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 1493 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---
Allow including custom files on the debian package.

View File

@ -1,4 +1,5 @@
target
Cargo.lock
.DS_Store
*.rs.bk
*~

File diff suppressed because it is too large Load Diff

View File

@ -73,6 +73,8 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
let (data_dir, _) = generate_data(settings, &package_dir)
.with_context(|| "Failed to build data folders and files")?;
copy_custom_files(settings, &data_dir).with_context(|| "Failed to copy custom files")?;
// Generate control files.
let control_dir = package_dir.join("control");
generate_control_file(settings, arch, &control_dir, &data_dir)
@ -113,7 +115,7 @@ pub fn generate_data(
.with_context(|| format!("Failed to copy binary from {:?}", bin_path))?;
}
transfer_resource_files(settings, &data_dir).with_context(|| "Failed to copy resource files")?;
copy_resource_files(settings, &data_dir).with_context(|| "Failed to copy resource files")?;
settings
.copy_binaries(&bin_dir)
@ -313,11 +315,35 @@ fn generate_md5sums(control_dir: &Path, data_dir: &Path) -> crate::Result<()> {
/// Copy the bundle's resource files into an appropriate directory under the
/// `data_dir`.
fn transfer_resource_files(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
fn copy_resource_files(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
let resource_dir = data_dir.join("usr/lib").join(settings.main_binary_name());
settings.copy_resources(&resource_dir)
}
/// Copies user-defined files to the deb package.
fn copy_custom_files(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
for (deb_path, path) in settings.deb().files.iter() {
let deb_path = if deb_path.is_absolute() {
deb_path.strip_prefix("/").unwrap()
} else {
deb_path
};
if path.is_file() {
common::copy_file(path, data_dir.join(deb_path))?;
} else {
let out_dir = data_dir.join(deb_path);
for entry in walkdir::WalkDir::new(&path) {
let entry_path = entry?.into_path();
if entry_path.is_file() {
let without_prefix = entry_path.strip_prefix(&path).unwrap();
common::copy_file(&entry_path, out_dir.join(without_prefix))?;
}
}
}
}
Ok(())
}
/// Generate the icon files and store them under the `data_dir`.
fn generate_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<BTreeSet<DebIcon>> {
let base_dir = data_dir.join("usr/share/icons/hicolor");

View File

@ -5,8 +5,6 @@
use super::category::AppCategory;
use crate::bundle::{common, platform::target_triple};
use serde::Deserialize;
use std::{
collections::HashMap,
path::{Path, PathBuf},
@ -88,7 +86,7 @@ const ALL_PACKAGE_TYPES: &[PackageType] = &[
];
/// The package settings.
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone)]
pub struct PackageSettings {
/// the package's product name.
pub product_name: String,
@ -105,7 +103,7 @@ pub struct PackageSettings {
}
/// The updater settings.
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone)]
pub struct UpdaterSettings {
/// Whether the updater is active or not.
pub active: bool,
@ -118,7 +116,7 @@ pub struct UpdaterSettings {
}
/// The Linux debian bundle settings.
#[derive(Clone, Debug, Deserialize, Default)]
#[derive(Clone, Debug, Default)]
pub struct DebianSettings {
// OS-specific settings:
/// the list of debian dependencies.
@ -129,10 +127,13 @@ pub struct DebianSettings {
///
/// without it, you can't run some applications installed by the user.
pub use_bootstrapper: Option<bool>,
/// List of custom files to add to the deb package.
/// Maps the path on the debian package to the path of the file to include (relative to the current working directory).
pub files: HashMap<PathBuf, PathBuf>,
}
/// The macOS bundle settings.
#[derive(Clone, Debug, Deserialize, Default)]
#[derive(Clone, Debug, Default)]
pub struct MacOsSettings {
/// MacOS frameworks that need to be bundled with the app.
///
@ -166,31 +167,23 @@ pub struct MacOsSettings {
}
#[cfg(windows)]
#[derive(Clone, Debug, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, Debug, Default)]
pub struct WixSettings {
/// By default, the bundler uses an internal template.
/// This option allows you to define your own wix file.
pub template: Option<PathBuf>,
#[serde(default)]
pub fragment_paths: Vec<PathBuf>,
#[serde(default)]
pub component_group_refs: Vec<String>,
#[serde(default)]
pub component_refs: Vec<String>,
#[serde(default)]
pub feature_group_refs: Vec<String>,
#[serde(default)]
pub feature_refs: Vec<String>,
#[serde(default)]
pub merge_refs: Vec<String>,
#[serde(default)]
pub skip_webview_install: bool,
}
/// The Windows bundle settings.
#[cfg(windows)]
#[derive(Clone, Debug, Deserialize, Default)]
#[derive(Clone, Debug, Default)]
pub struct WindowsSettings {
pub digest_algorithm: Option<String>,
pub certificate_thumbprint: Option<String>,
@ -199,7 +192,7 @@ pub struct WindowsSettings {
}
/// The bundle settings of the BuildArtifact we're bundling.
#[derive(Clone, Debug, Deserialize, Default)]
#[derive(Clone, Debug, Default)]
pub struct BundleSettings {
/// the app's identifier.
pub identifier: Option<String>,

View File

@ -25,6 +25,8 @@ pub struct DebConfig {
pub depends: Option<Vec<String>>,
#[serde(default)]
pub use_bootstrapper: bool,
#[serde(default)]
pub files: HashMap<PathBuf, PathBuf>,
}
#[skip_serializing_none]

View File

@ -82,6 +82,7 @@
"bundle": {
"active": false,
"deb": {
"files": {},
"useBootstrapper": false
},
"macOS": {
@ -263,6 +264,7 @@
},
"deb": {
"default": {
"files": {},
"useBootstrapper": false
},
"allOf": [
@ -634,6 +636,13 @@
"type": "string"
}
},
"files": {
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"useBootstrapper": {
"default": false,
"type": "boolean"
@ -903,6 +912,7 @@
"default": {
"active": false,
"deb": {
"files": {},
"useBootstrapper": false
},
"macOS": {

View File

@ -337,6 +337,7 @@ fn tauri_config_to_bundle_settings(
deb: DebianSettings {
depends: config.deb.depends,
use_bootstrapper: Some(config.deb.use_bootstrapper),
files: config.deb.files,
},
macos: MacOsSettings {
frameworks: config.macos.frameworks,