From 021618cda37a8c46e9520767041d6d5d7f6bf111 Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Wed, 10 Jan 2024 00:24:46 +0530 Subject: [PATCH 01/11] Add priority and section support --- bindings/packager/nodejs/src-ts/config.d.ts | 15 +++++++++++++++ crates/packager/src/config/mod.rs | 5 +++++ crates/packager/src/package/deb/mod.rs | 12 +++++++++++- examples/tauri/Cargo.toml | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bindings/packager/nodejs/src-ts/config.d.ts b/bindings/packager/nodejs/src-ts/config.d.ts index caa7588f..6295cb51 100644 --- a/bindings/packager/nodejs/src-ts/config.d.ts +++ b/bindings/packager/nodejs/src-ts/config.d.ts @@ -407,6 +407,21 @@ 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. It is recommended to add a section in the debian application. + * + * 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. + * + * See : https://www.debian.org/doc/debian-policy/ch-archive.html#priorities + */ + 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/src/config/mod.rs b/crates/packager/src/config/mod.rs index de20c543..6ae915c9 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>, diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index 42876aed..9bac7e2f 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -252,6 +252,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 +292,7 @@ fn generate_control_file( writeln!(file, " {}", line)?; } } - writeln!(file, "Priority: optional")?; + file.flush()?; Ok(()) } 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"] From 7663eb6400e042f70bd9293580ecc7f5be4ba37a Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Wed, 10 Jan 2024 05:06:48 +0530 Subject: [PATCH 02/11] Fix formatting issue --- crates/packager/src/package/deb/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index 9bac7e2f..f3493520 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -258,7 +258,7 @@ fn generate_control_file( if let Some(priority) = config.deb().and_then(|d| d.priority.as_ref()) { writeln!(file, "Priority: {}", priority)?; - }else{ + } else { writeln!(file, "Priority: optional")?; } From 313888954b7c2a7428783fd942439b6993e24052 Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Thu, 11 Jan 2024 18:24:51 +0530 Subject: [PATCH 03/11] Update Schema, Improve Code --- .changes/priority-and-section.md | 5 +++++ bindings/packager/nodejs/schema.json | 14 ++++++++++++++ crates/packager/schema.json | 14 ++++++++++++++ crates/packager/src/package/deb/mod.rs | 19 +++++++------------ 4 files changed, 40 insertions(+), 12 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..8243e5b5 --- /dev/null +++ b/.changes/priority-and-section.md @@ -0,0 +1,5 @@ +--- +"cargo-packager": minor +--- + +Add the support for priority and section in Debian Config diff --git a/bindings/packager/nodejs/schema.json b/bindings/packager/nodejs/schema.json index f8f48fad..43a412b7 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/crates/packager/schema.json b/crates/packager/schema.json index f8f48fad..43a412b7 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": [ diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index f3493520..dd17fcb3 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -10,6 +10,7 @@ use std::{ fs::File, io::Write, path::{Path, PathBuf}, + os::unix::fs::MetadataExt, }; use handlebars::Handlebars; @@ -18,6 +19,7 @@ use image::{codecs::png::PngDecoder, ImageDecoder}; use relative_path::PathExt; use serde::Serialize; use walkdir::WalkDir; +use tar::HeaderMode; use super::Context; use crate::{ @@ -426,22 +428,15 @@ 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)?; } } From 8d0232391174282cc90fd2dc3b82809645ed50ff Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Thu, 11 Jan 2024 18:27:00 +0530 Subject: [PATCH 04/11] Fix fmt --- crates/packager/src/package/deb/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index dd17fcb3..ec27f1dc 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -9,8 +9,8 @@ use std::{ ffi::OsStr, fs::File, io::Write, - path::{Path, PathBuf}, os::unix::fs::MetadataExt, + path::{Path, PathBuf}, }; use handlebars::Handlebars; @@ -18,8 +18,8 @@ use heck::AsKebabCase; use image::{codecs::png::PngDecoder, ImageDecoder}; use relative_path::PathExt; use serde::Serialize; -use walkdir::WalkDir; use tar::HeaderMode; +use walkdir::WalkDir; use super::Context; use crate::{ From d4b3618c9dda50a960bed91ccba314e4c2c3ea2c Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Sat, 13 Jan 2024 03:15:27 +0530 Subject: [PATCH 05/11] Regenerate confid.d.ts --- bindings/packager/nodejs/src-ts/config.d.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/bindings/packager/nodejs/src-ts/config.d.ts b/bindings/packager/nodejs/src-ts/config.d.ts index 6295cb51..e621ef45 100644 --- a/bindings/packager/nodejs/src-ts/config.d.ts +++ b/bindings/packager/nodejs/src-ts/config.d.ts @@ -407,21 +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. It is recommended to add a section in the debian application. - * - * See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections + * 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. - * - * See : https://www.debian.org/doc/debian-policy/ch-archive.html#priorities + * 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. */ From 8932eca73ba4dcb83173e0844bea027de07eee5a Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Sat, 13 Jan 2024 04:18:50 +0530 Subject: [PATCH 06/11] For the sake of running test again --- crates/packager/src/package/deb/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/packager/src/package/deb/mod.rs b/crates/packager/src/package/deb/mod.rs index ec27f1dc..618253d9 100644 --- a/crates/packager/src/package/deb/mod.rs +++ b/crates/packager/src/package/deb/mod.rs @@ -294,7 +294,6 @@ fn generate_control_file( writeln!(file, " {}", line)?; } } - file.flush()?; Ok(()) } @@ -432,7 +431,6 @@ fn create_tar_from_dir, W: Write>(src_dir: P, dest_file: W) -> cr 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() { tar_builder.append_data(&mut header, dest_path, &mut std::io::empty())?; } else { From 7ad26590f9eda3a00dab3efd04901ee054c55ddd Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 15 Jan 2024 17:18:38 +0200 Subject: [PATCH 07/11] Update .changes/priority-and-section.md --- .changes/priority-and-section.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/priority-and-section.md b/.changes/priority-and-section.md index 8243e5b5..2241101c 100644 --- a/.changes/priority-and-section.md +++ b/.changes/priority-and-section.md @@ -2,4 +2,4 @@ "cargo-packager": minor --- -Add the support for priority and section in Debian Config +Add `priority` and `section` options in Debian config From a6c51ab1698810fbbcdaf41ecbe169d41b2b0ee1 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 15 Jan 2024 17:23:12 +0200 Subject: [PATCH 08/11] add equivalent methods --- bindings/packager/nodejs/schema.json | 2 +- bindings/packager/nodejs/src-ts/config.d.ts | 2 +- crates/packager/src/config/mod.rs | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bindings/packager/nodejs/schema.json b/bindings/packager/nodejs/schema.json index 43a412b7..aba0f52f 100644 --- a/bindings/packager/nodejs/schema.json +++ b/bindings/packager/nodejs/schema.json @@ -730,7 +730,7 @@ ] }, "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", + "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" diff --git a/bindings/packager/nodejs/src-ts/config.d.ts b/bindings/packager/nodejs/src-ts/config.d.ts index e621ef45..2b32baaa 100644 --- a/bindings/packager/nodejs/src-ts/config.d.ts +++ b/bindings/packager/nodejs/src-ts/config.d.ts @@ -412,7 +412,7 @@ export interface DebianConfig { */ 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 + * 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; /** diff --git a/crates/packager/src/config/mod.rs b/crates/packager/src/config/mod.rs index 6ae915c9..6dcf7e1c 100644 --- a/crates/packager/src/config/mod.rs +++ b/crates/packager/src/config/mod.rs @@ -313,8 +313,8 @@ pub struct DebianConfig { 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 + /// 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. @@ -363,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>(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>(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 From c758a95693c9b5bbf51f95e58f5c90b79f0c99ff Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 15 Jan 2024 17:24:02 +0200 Subject: [PATCH 09/11] Update schema.json --- crates/packager/schema.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/packager/schema.json b/crates/packager/schema.json index 43a412b7..15e6c7c0 100644 --- a/crates/packager/schema.json +++ b/crates/packager/schema.json @@ -730,7 +730,7 @@ ] }, "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", + "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" @@ -1220,4 +1220,4 @@ "additionalProperties": false } } -} \ No newline at end of file +} From b9ea28e1268196483f91ef1624c9145dc54ec3c5 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 15 Jan 2024 17:25:14 +0200 Subject: [PATCH 10/11] Update .changes/priority-and-section.md --- .changes/priority-and-section.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changes/priority-and-section.md b/.changes/priority-and-section.md index 2241101c..c5fc54fc 100644 --- a/.changes/priority-and-section.md +++ b/.changes/priority-and-section.md @@ -1,5 +1,6 @@ --- -"cargo-packager": minor +"cargo-packager": patch +"@crabnebula/packager": patch --- Add `priority` and `section` options in Debian config From 01cb1ed147d5b49686e2a73dd3dc5cd262987872 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 15 Jan 2024 17:27:19 +0200 Subject: [PATCH 11/11] Update crates/packager/src/config/mod.rs --- crates/packager/src/config/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/packager/src/config/mod.rs b/crates/packager/src/config/mod.rs index 6dcf7e1c..ecb93c11 100644 --- a/crates/packager/src/config/mod.rs +++ b/crates/packager/src/config/mod.rs @@ -364,14 +364,14 @@ impl DebianConfig { } /// Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections - pub fn section>(self, section: S) -> Self { + 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>(self, priority: S) -> Self { + pub fn priority>(mut self, priority: S) -> Self { self.priority.replace(priority.into()); self }