From d0a6e918cc5b457c99f1ea973323f92a4000844a Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Mon, 14 Jun 2021 18:23:49 +1000 Subject: [PATCH] block compilation if both backends are enabled --- CHANGELOG.md | 4 +++- build.rs | 10 ++++++++++ src/main.rs | 9 +++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 build.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b1f59..96b8d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Dates are given in YYYY-MM-DD format. - Nicer version output: `fif -V` reports "fif v0.3.2" (instead of just "fif 0.3.2" without the "v"), and `fif --version` reports `fif v0.3.2 (XDG-Mime backend)`, or whatever backend you're using - fif's trace output now includes its version, backend, operating system, and architecture +- Block compilation if both the `xdg-mime-backend` and `infer-backend` + [features](https://gitlab.com/Lynnesbian/fif/-/wikis/Cargo-Features) are enabled ### v0.3.1 (2021-07-06) #### Features @@ -151,7 +153,7 @@ Dates are given in YYYY-MM-DD format. #### Features - Added extension sets -- you can now use, for example, `-E images` to check files with known image extensions - Shell script output now uses `printf` instead of `echo` -- Added [`infer`] backend +- Added [`infer`] backend, configurable with [Cargo features](https://gitlab.com/Lynnesbian/fif/-/wikis/Cargo-Features) #### Bugfixes - Fixed broken singlethreaded support #### Other diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..cdea0ba --- /dev/null +++ b/build.rs @@ -0,0 +1,10 @@ +#[allow(unreachable_code, clippy::pedantic)] +fn main() -> Result<(), String> { + #[cfg(all(feature = "infer-backend", feature = "xdg-mime-backend"))] + // fail build if the user has set both the infer and xdg-mime backends + return Err(String::from( + "fif cannot be compiled with multiple backends set - please enable only one, or use the default.", + )); + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 369238e..908a202 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,8 +34,8 @@ use crate::findings::ScanError; use crate::formats::{Format, PowerShell, Shell}; use crate::mime_db::MimeDb; use crate::parameters::{OutputFormat, ScanOpts}; -use std::collections::BTreeSet; use crate::utils::{clap_long_version, os_name}; +use std::collections::BTreeSet; mod findings; mod formats; @@ -72,7 +72,12 @@ fn main() { // .target(env_logger::Target::Stdout) // log to stdout rather than stderr .init(); - trace!("fif {}, running on {} {}", clap_long_version(), std::env::consts::ARCH, os_name()); + trace!( + "fif {}, running on {} {}", + clap_long_version(), + std::env::consts::ARCH, + os_name() + ); trace!("Initialise mimetype database"); init_db();