Skip to content

Commit

Permalink
feat: Add Section, Priority and Changelog options (#8620)
Browse files Browse the repository at this point in the history
* Init section, priority and changelog

* Add section. priority and changelog support

* fix variable name

* Add .changes file

* Fix Formatting

* Apply suggestions from code review
  • Loading branch information
naman-crabnebula authored Jan 17, 2024
1 parent 4926648 commit 7aa30de
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/add-section-priority-changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch:feat
---

Add `priority`, `section` and `changelog` options in Debian config.
21 changes: 21 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,27 @@
"string",
"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"
]
},
"changelog": {
"description": "Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down
8 changes: 8 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ pub struct DebConfig {
///
/// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
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>,
/// Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See
/// https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes
pub changelog: Option<PathBuf>,
}

fn de_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
Expand Down
29 changes: 28 additions & 1 deletion tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,30 @@ pub fn generate_data(
let icons =
generate_icon_files(settings, &data_dir).with_context(|| "Failed to create icon files")?;
generate_desktop_file(settings, &data_dir).with_context(|| "Failed to create desktop file")?;
generate_changelog_file(settings, &data_dir)
.with_context(|| "Failed to create changelog.gz file")?;

Ok((data_dir, icons))
}

/// Generate the Changelog file by compressing, to be stored at /usr/share/doc/package-name/changelog.gz. See
/// https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes
fn generate_changelog_file(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
if let Some(changelog_src_path) = &settings.deb().changelog {
let mut src_file = File::open(changelog_src_path)?;
let bin_name = settings.main_binary_name();
let dest_path = data_dir.join(format!("usr/share/doc/{}/changelog.gz", bin_name));

let changelog_file = common::create_file(&dest_path)?;
let mut gzip_encoder = GzEncoder::new(changelog_file, Compression::new(9));
io::copy(&mut src_file, &mut gzip_encoder)?;

let mut changelog_file = gzip_encoder.finish()?;
changelog_file.flush()?;
}
Ok(())
}

/// Generate the application desktop file and store it under the `data_dir`.
fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
let bin_name = settings.main_binary_name();
Expand Down Expand Up @@ -212,6 +232,14 @@ fn generate_control_file(
writeln!(file, "Installed-Size: {}", total_dir_size(data_dir)? / 1024)?;
let authors = settings.authors_comma_separated().unwrap_or_default();
writeln!(file, "Maintainer: {}", authors)?;
if let Some(section) = &settings.deb().section {
writeln!(file, "Section: {}", section)?;
}
if let Some(priority) = &settings.deb().priority {
writeln!(file, "Priority: {}", priority)?;
} else {
writeln!(file, "Priority: optional")?;
}
if !settings.homepage_url().is_empty() {
writeln!(file, "Homepage: {}", settings.homepage_url())?;
}
Expand All @@ -236,7 +264,6 @@ fn generate_control_file(
writeln!(file, " {}", line)?;
}
}
writeln!(file, "Priority: optional")?;
file.flush()?;
Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ pub struct DebianSettings {
#[doc = include_str!("./linux/templates/main.desktop")]
/// ```
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>,
/// Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See
/// https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes
pub changelog: Option<PathBuf>,
}

/// The macOS bundle settings.
Expand Down
21 changes: 21 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,27 @@
"string",
"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"
]
},
"changelog": {
"description": "Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down
3 changes: 3 additions & 0 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,9 @@ fn tauri_config_to_bundle_settings(
},
files: config.deb.files,
desktop_template: config.deb.desktop_template,
section: config.deb.section,
priority: config.deb.priority,
changelog: config.deb.changelog,
},
macos: MacOsSettings {
frameworks: config.macos.frameworks,
Expand Down

0 comments on commit 7aa30de

Please sign in to comment.