Skip to content

Commit

Permalink
bundler/rpm: Add custom files
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlemasle committed Nov 21, 2022
1 parent 43a93ec commit 059aa8d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
4 changes: 4 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ pub struct RpmConfig {
/// The RPM epoch.
#[serde(default)]
pub epoch: i32,
/// The files to include on the package.
#[serde(default)]
pub files: HashMap<PathBuf, PathBuf>,
}

impl Default for RpmConfig {
Expand All @@ -296,6 +299,7 @@ impl Default for RpmConfig {
depends: None,
release: default_release(),
epoch: 0,
files: Default::default(),
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions tooling/bundler/src/bundle/linux/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
//!
//! - Generation of [desktop entries] (`.desktop` files)
//! - Copy of icons in the [icons file hierarchy]
//! - [AppStream] metadata files
//!
//! The specifications are developed and hosted at [freedesktop.org].
//!
//! [freedesktop.org]: https://www.freedesktop.org
//! [desktop entries]: https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/
//! [icons file hierarchy]: https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup
//! [AppStream]: https://www.freedesktop.org/software/appstream/docs/

use std::collections::BTreeMap;
use std::ffi::OsStr;
Expand Down Expand Up @@ -89,14 +87,18 @@ pub fn copy_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<Ve
}

/// Generate the application desktop file and store it under the `data_dir`.
/// Returns the path of the resulting file.
pub fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<PathBuf> {
/// Returns the path of the resulting file (source path) and the destination
/// path in the package.
pub fn generate_desktop_file(
settings: &Settings,
data_dir: &Path,
) -> crate::Result<(PathBuf, PathBuf)> {
let bin_name = settings.main_binary_name();
let desktop_file_name = format!("{}.desktop", bin_name);
let desktop_file_path = data_dir
.join("usr/share/applications")
.join(desktop_file_name);
let file = &mut common::create_file(&desktop_file_path)?;
let path = PathBuf::from("usr/share/applications").join(desktop_file_name);
let dest_path = PathBuf::from("/").join(&path);
let file_path = data_dir.join(&path);
let file = &mut common::create_file(&file_path)?;

writeln!(file, "[Desktop Entry]")?;
if let Some(category) = settings.app_category() {
Expand All @@ -112,5 +114,5 @@ pub fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Res
writeln!(file, "Name={}", settings.product_name())?;
writeln!(file, "Terminal=false")?;
writeln!(file, "Type=Application")?;
Ok(desktop_file_path)
Ok((file_path, dest_path))
}
31 changes: 22 additions & 9 deletions tooling/bundler/src/bundle/linux/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {

// Add resources
let resource_dir = Path::new("/usr/lib").join(settings.main_binary_name());
// TODO: we should also package the directory `/usr/lib/<binary_name>`,
// TODO: we should also install the directory `/usr/lib/<binary_name>` itself,
// which is owned by the package, but it's currently not possible with rpm-rs.
for src in settings.resource_files() {
let src = src?;
Expand All @@ -98,22 +98,35 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
}

// Add Desktop entry file
let desktop_file_path = freedesktop::generate_desktop_file(settings, &package_dir)?;
let (desktop_src_path, desktop_dest_path) =
freedesktop::generate_desktop_file(settings, &package_dir)?;
builder = builder.with_file(
&desktop_file_path,
RPMFileOptions::new(
PathBuf::from("/")
.join(desktop_file_path.strip_prefix(&package_dir)?)
.to_string_lossy(),
),
&desktop_src_path,
RPMFileOptions::new(desktop_dest_path.to_string_lossy()),
)?;

// Add icons
for (icon, src) in &freedesktop::list_icon_files(settings, &PathBuf::from("/"))? {
builder = builder.with_file(src, RPMFileOptions::new(icon.path.to_string_lossy()))?;
}

// TODO: Add custom files
// Add custom files
for (rpm_path, src_path) in settings.rpm().files.iter() {
if src_path.is_file() {
builder = builder.with_file(src_path, RPMFileOptions::new(rpm_path.to_string_lossy()))?;
} else {
for entry in walkdir::WalkDir::new(src_path) {
let entry_path = entry?.into_path();
if entry_path.is_file() {
let dest_path = rpm_path.join(entry_path.strip_prefix(&src_path).unwrap());
builder = builder.with_file(
&entry_path,
RPMFileOptions::new(dest_path.to_string_lossy()),
)?;
}
}
}
}

// TODO: Add signature

Expand Down
3 changes: 3 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ pub struct RpmSettings {
pub release: String,
/// The RPM epoch.
pub epoch: i32,
/// List of custom files to add to the RPM package.
/// Maps the path on the RPM package to the path of the file to include (relative to the current working directory).
pub files: HashMap<PathBuf, PathBuf>,
}

/// The macOS bundle settings.
Expand Down
11 changes: 11 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"rpm": {
"epoch": 0,
"files": {},
"release": "1"
},
"targets": "all",
Expand Down Expand Up @@ -282,6 +283,7 @@
},
"rpm": {
"epoch": 0,
"files": {},
"release": "1"
},
"targets": "all",
Expand Down Expand Up @@ -1103,6 +1105,7 @@
"description": "Configuration for the RPM bundle.",
"default": {
"epoch": 0,
"files": {},
"release": "1"
},
"allOf": [
Expand Down Expand Up @@ -1304,6 +1307,14 @@
"default": 0,
"type": "integer",
"format": "int32"
},
"files": {
"description": "The files to include on the package.",
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ fn tauri_config_to_bundle_settings(
},
release: config.rpm.release,
epoch: config.rpm.epoch,
files: config.rpm.files,
},
macos: MacOsSettings {
frameworks: config.macos.frameworks,
Expand Down

0 comments on commit 059aa8d

Please sign in to comment.