Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deb): add priority and section options #126

Merged
merged 11 commits into from
Jan 15, 2024
5 changes: 5 additions & 0 deletions .changes/priority-and-section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-packager": minor
amr-crabnebula marked this conversation as resolved.
Show resolved Hide resolved
---

Add the support for priority and section in Debian Config
amr-crabnebula marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions bindings/packager/nodejs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 8 additions & 0 deletions bindings/packager/nodejs/src-ts/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
14 changes: 14 additions & 0 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
5 changes: 5 additions & 0 deletions crates/packager/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ pub struct DebianConfig {
/// ```
#[serde(alias = "desktop-template", alias = "desktop_template")]
pub desktop_template: Option<PathBuf>,
/// Define the section in Debian Control file. See : https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
pub section: Option<String>,
/// 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<String>,
/// 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<HashMap<String, String>>,
Expand Down
29 changes: 16 additions & 13 deletions crates/packager/src/package/deb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
ffi::OsStr,
fs::File,
io::Write,
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
};

Expand All @@ -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;
Expand Down Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -282,7 +294,6 @@ fn generate_control_file(
writeln!(file, " {}", line)?;
}
}
writeln!(file, "Priority: optional")?;
file.flush()?;
Ok(())
}
Expand Down Expand Up @@ -416,22 +427,14 @@ fn create_tar_from_dir<P: AsRef<Path>, 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)?;
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading