From bfa3b00cf1087b2ee1e93d9c57b6b577f6294891 Mon Sep 17 00:00:00 2001 From: Naman Garg <155433377+naman-crabnebula@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:46:14 +0530 Subject: [PATCH] feat(deb): add `priority` and `section` options (#126) * Add priority and section support * Fix formatting issue * Update Schema, Improve Code * Fix fmt * Regenerate confid.d.ts * For the sake of running test again * Update .changes/priority-and-section.md * add equivalent methods * Update schema.json * Update .changes/priority-and-section.md * Update crates/packager/src/config/mod.rs --- .changes/priority-and-section.md | 6 +++++ bindings/packager/nodejs/schema.json | 14 ++++++++++ bindings/packager/nodejs/src-ts/config.d.ts | 8 ++++++ crates/packager/schema.json | 16 +++++++++++- crates/packager/src/config/mod.rs | 18 +++++++++++++ crates/packager/src/package/deb/mod.rs | 29 ++++++++++++--------- examples/tauri/Cargo.toml | 1 + 7 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 .changes/priority-and-section.md diff --git a/.changes/priority-and-section.md b/.changes/priority-and-section.md new file mode 100644 index 00000000..c5fc54fc --- /dev/null +++ b/.changes/priority-and-section.md @@ -0,0 +1,6 @@ +--- +"cargo-packager": patch +"@crabnebula/packager": patch +--- + +Add `priority` and `section` options in Debian config diff --git a/bindings/packager/nodejs/schema.json b/bindings/packager/nodejs/schema.json index f8f48fad..aba0f52f 100644 --- a/bindings/packager/nodejs/schema.json +++ b/bindings/packager/nodejs/schema.json @@ -722,6 +722,20 @@ "null" ] }, + "section": { + "description": "Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections", + "type": [ + "string", + "null" + ] + }, + "priority": { + "description": "Change the priority of the Debian Package. By default, it is set to `optional`. Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra`", + "type": [ + "string", + "null" + ] + }, "files": { "description": "List of custom files to add to the deb package. Maps a dir/file to a dir/file inside the debian package.", "type": [ diff --git a/bindings/packager/nodejs/src-ts/config.d.ts b/bindings/packager/nodejs/src-ts/config.d.ts index caa7588f..2b32baaa 100644 --- a/bindings/packager/nodejs/src-ts/config.d.ts +++ b/bindings/packager/nodejs/src-ts/config.d.ts @@ -407,6 +407,14 @@ export interface DebianConfig { * Default file contents: ```text [Desktop Entry] Categories={{categories}} {{#if comment}} Comment={{comment}} {{/if}} Exec={{exec}} Icon={{icon}} Name={{name}} Terminal=false Type=Application {{#if mime_type}} MimeType={{mime_type}} {{/if}} ``` */ desktopTemplate?: string | null; + /** + * Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections + */ + section?: string | null; + /** + * Change the priority of the Debian Package. By default, it is set to `optional`. Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, extra + */ + priority?: string | null; /** * List of custom files to add to the deb package. Maps a dir/file to a dir/file inside the debian package. */ diff --git a/crates/packager/schema.json b/crates/packager/schema.json index f8f48fad..15e6c7c0 100644 --- a/crates/packager/schema.json +++ b/crates/packager/schema.json @@ -722,6 +722,20 @@ "null" ] }, + "section": { + "description": "Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections", + "type": [ + "string", + "null" + ] + }, + "priority": { + "description": "Change the priority of the Debian Package. By default, it is set to `optional`. Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra`", + "type": [ + "string", + "null" + ] + }, "files": { "description": "List of custom files to add to the deb package. Maps a dir/file to a dir/file inside the debian package.", "type": [ @@ -1206,4 +1220,4 @@ "additionalProperties": false } } -} \ No newline at end of file +} diff --git a/crates/packager/src/config/mod.rs b/crates/packager/src/config/mod.rs index de20c543..ecb93c11 100644 --- a/crates/packager/src/config/mod.rs +++ b/crates/packager/src/config/mod.rs @@ -311,6 +311,11 @@ pub struct DebianConfig { /// ``` #[serde(alias = "desktop-template", alias = "desktop_template")] pub desktop_template: Option, + /// Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections + pub section: Option, + /// Change the priority of the Debian Package. By default, it is set to `optional`. + /// Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra` + pub priority: Option, /// List of custom files to add to the deb package. /// Maps a dir/file to a dir/file inside the debian package. pub files: Option>, @@ -358,6 +363,19 @@ impl DebianConfig { self } + /// Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections + pub fn section>(mut self, section: S) -> Self { + self.section.replace(section.into()); + self + } + + /// Change the priority of the Debian Package. By default, it is set to `optional`. + /// Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra` + pub fn priority>(mut self, priority: S) -> Self { + self.priority.replace(priority.into()); + self + } + /// Set the list of custom files to add to the deb package. /// Maps a dir/file to a dir/file inside the debian package. pub fn files(mut self, files: I) -> Self diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index 42876aed..618253d9 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -9,6 +9,7 @@ use std::{ ffi::OsStr, fs::File, io::Write, + os::unix::fs::MetadataExt, path::{Path, PathBuf}, }; @@ -17,6 +18,7 @@ use heck::AsKebabCase; use image::{codecs::png::PngDecoder, ImageDecoder}; use relative_path::PathExt; use serde::Serialize; +use tar::HeaderMode; use walkdir::WalkDir; use super::Context; @@ -252,6 +254,16 @@ fn generate_control_file( if let Some(authors) = &config.authors { writeln!(file, "Maintainer: {}", authors.join(", "))?; } + if let Some(section) = config.deb().and_then(|d| d.section.as_ref()) { + writeln!(file, "Section: {}", section)?; + } + + if let Some(priority) = config.deb().and_then(|d| d.priority.as_ref()) { + writeln!(file, "Priority: {}", priority)?; + } else { + writeln!(file, "Priority: optional")?; + } + if let Some(homepage) = &config.homepage { writeln!(file, "Homepage: {}", homepage)?; } @@ -282,7 +294,6 @@ fn generate_control_file( writeln!(file, " {}", line)?; } } - writeln!(file, "Priority: optional")?; file.flush()?; Ok(()) } @@ -416,22 +427,14 @@ fn create_tar_from_dir, W: Write>(src_dir: P, dest_file: W) -> cr continue; } let dest_path = src_path.strip_prefix(src_dir)?; + let stat = std::fs::metadata(src_path)?; + let mut header = tar::Header::new_gnu(); + header.set_metadata_in_mode(&stat, HeaderMode::Deterministic); + header.set_mtime(stat.mtime() as u64); if entry.file_type().is_dir() { - let stat = std::fs::metadata(src_path)?; - let mut header = tar::Header::new_gnu(); - header.set_mode(0o755); - header.set_metadata(&stat); - header.set_uid(0); - header.set_gid(0); tar_builder.append_data(&mut header, dest_path, &mut std::io::empty())?; } else { let mut src_file = std::fs::File::open(src_path)?; - let stat = src_file.metadata()?; - let mut header = tar::Header::new_gnu(); - header.set_mode(0o644); - header.set_metadata(&stat); - header.set_uid(0); - header.set_gid(0); tar_builder.append_data(&mut header, dest_path, &mut src_file)?; } } diff --git a/examples/tauri/Cargo.toml b/examples/tauri/Cargo.toml index 39fedc57..c4149ceb 100644 --- a/examples/tauri/Cargo.toml +++ b/examples/tauri/Cargo.toml @@ -44,6 +44,7 @@ icons = [ [package.metadata.packager.deb] depends = ["libgtk-3-0", "libwebkit2gtk-4.1-0", "libayatana-appindicator3-1"] +section = "rust" [package.metadata.packager.appimage] bins = ["/usr/bin/xdg-open"]