forked from meli/meli
1
Fork 0

Fix compilation error when building without `gpgme` feature

fix/242
Manos Pitsidianakis 2023-07-03 14:59:37 +03:00
parent 619fbef129
commit e3dfeaad7e
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
6 changed files with 42 additions and 19 deletions

View File

@ -62,7 +62,8 @@ notify-rust = { version = "^4", default-features = false, features = ["dbus", ],
flate2 = { version = "1", optional = true }
proc-macro2 = "1.0.37"
quote = "^1.0"
syn = { version = "1.0.92", features = [] }
regex = "1"
syn = { version = "1", features = [] }
[dev-dependencies]
flate2 = { version = "1" }

View File

@ -26,6 +26,7 @@ mod config_macros;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/conf/.rebuild.overrides.rs");
config_macros::override_derive(&[
("src/conf/pager.rs", "PagerSettings"),
("src/conf/listing.rs", "ListingSettings"),

View File

@ -26,7 +26,7 @@ use std::{
};
use quote::{format_ident, quote};
extern crate proc_macro;
use regex::Regex;
// Write ConfigStructOverride to overrides.rs
pub fn override_derive(filenames: &[(&str, &str)]) {
@ -64,6 +64,10 @@ use melib::HeaderName;
"##
.to_string();
let cfg_attr_default_attr_regex = Regex::new(r"\s*default\s*[,]").unwrap();
let cfg_attr_default_val_attr_regex = Regex::new(r#"\s*default\s*=\s*"[^"]*"\s*,\s*"#).unwrap();
let cfg_attr_feature_regex = Regex::new(r"[(](?:not[(]\s*)?feature").unwrap();
'file_loop: for (filename, ident) in filenames {
println!("cargo:rerun-if-changed={}", filename);
let mut file = File::open(filename)
@ -115,7 +119,20 @@ use melib::HeaderName;
if let proc_macro2::TokenTree::Group(g) =
f.tokens.clone().into_iter().next().unwrap()
{
let attr_inner_value = f.tokens.to_string();
let mut attr_inner_value = f.tokens.to_string();
if cfg_attr_feature_regex.is_match(&attr_inner_value) {
attr_inner_value = cfg_attr_default_val_attr_regex
.replace_all(&attr_inner_value, "")
.to_string();
if attr_inner_value.contains("default") {
attr_inner_value = cfg_attr_default_attr_regex
.replace_all(&attr_inner_value, "")
.to_string();
}
let new_toks: proc_macro2::TokenStream =
attr_inner_value.parse().unwrap();
new_attr.tokens = quote! { #new_toks };
}
if !attr_inner_value.starts_with("( default")
&& !attr_inner_value.starts_with("( default =")
&& !attr_inner_value.starts_with("(default")
@ -156,7 +173,9 @@ use melib::HeaderName;
#[serde(default)]
pub #ident : Option<#ty>
};
field_idents.push(ident);
if !field_idents.contains(&ident) {
field_idents.push(ident);
}
field_tokentrees.push(t);
}
//let fields = &s.fields;

View File

View File

@ -39,7 +39,5 @@ use melib::HeaderName;
# [derive (Debug , Serialize , Deserialize , Clone)] # [serde (deny_unknown_fields)] pub struct TagsSettingsOverride { # [serde (deserialize_with = "tag_color_de")] # [serde (default)] pub colors : Option < HashMap < TagHash , Color > > , # [serde (deserialize_with = "tag_set_de" , alias = "ignore-tags")] # [serde (default)] pub ignore_tags : Option < HashSet < TagHash > > } impl Default for TagsSettingsOverride { fn default () -> Self { TagsSettingsOverride { colors : None , ignore_tags : None } } }
# [cfg (feature = "gpgme")] # [derive (Debug , Serialize , Deserialize , Clone)] # [serde (deny_unknown_fields)] pub struct PGPSettingsOverride { # [doc = " auto verify signed e-mail according to RFC3156"] # [doc = " Default: true"] # [serde (alias = "auto-verify-signatures")] # [serde (default)] pub auto_verify_signatures : Option < bool > , # [doc = " auto decrypt encrypted e-mail"] # [doc = " Default: true"] # [serde (alias = "auto-decrypt")] # [serde (default)] pub auto_decrypt : Option < bool > , # [doc = " always sign sent e-mail"] # [doc = " Default: false"] # [serde (alias = "auto-sign")] # [serde (default)] pub auto_sign : Option < bool > , # [doc = " Auto encrypt sent e-mail"] # [doc = " Default: false"] # [serde (alias = "auto-encrypt")] # [serde (default)] pub auto_encrypt : Option < bool > , # [doc = " Default: None"] # [serde (alias = "sign-key")] # [serde (default)] pub sign_key : Option < Option < String > > , # [doc = " Default: None"] # [serde (alias = "decrypt-key")] # [serde (default)] pub decrypt_key : Option < Option < String > > , # [doc = " Default: None"] # [serde (alias = "encrypt-key")] # [serde (default)] pub encrypt_key : Option < Option < String > > , # [doc = " Allow remote lookups"] # [doc = " Default: None"] # [serde (alias = "allow-remote-lookups")] # [serde (default)] pub allow_remote_lookup : Option < ToggleFlag > , # [doc = " Remote lookup mechanisms."] # [doc = " Default: \"local,wkd\""] # [serde (alias = "remote-lookup-mechanisms")] # [serde (default)] pub remote_lookup_mechanisms : Option < melib :: gpgme :: LocateKey > } # [cfg (feature = "gpgme")] impl Default for PGPSettingsOverride { fn default () -> Self { PGPSettingsOverride { auto_verify_signatures : None , auto_decrypt : None , auto_sign : None , auto_encrypt : None , sign_key : None , decrypt_key : None , encrypt_key : None , allow_remote_lookup : None , remote_lookup_mechanisms : None } } }
# [cfg (not (feature = "gpgme"))] # [derive (Debug , Serialize , Deserialize , Clone)] # [serde (deny_unknown_fields)] pub struct PGPSettingsOverride { } # [cfg (not (feature = "gpgme"))] impl Default for PGPSettingsOverride { fn default () -> Self { PGPSettingsOverride { } } }
# [derive (Debug , Serialize , Deserialize , Clone)] # [serde (deny_unknown_fields)] pub struct PGPSettingsOverride { # [doc = " auto verify signed e-mail according to RFC3156"] # [doc = " Default: true"] # [serde (alias = "auto-verify-signatures")] # [serde (default)] pub auto_verify_signatures : Option < bool > , # [doc = " auto decrypt encrypted e-mail"] # [doc = " Default: true"] # [serde (alias = "auto-decrypt")] # [serde (default)] pub auto_decrypt : Option < bool > , # [doc = " always sign sent e-mail"] # [doc = " Default: false"] # [serde (alias = "auto-sign")] # [serde (default)] pub auto_sign : Option < bool > , # [doc = " Auto encrypt sent e-mail"] # [doc = " Default: false"] # [serde (alias = "auto-encrypt")] # [serde (default)] pub auto_encrypt : Option < bool > , # [doc = " Default: None"] # [serde (alias = "sign-key")] # [serde (default)] pub sign_key : Option < Option < String > > , # [doc = " Default: None"] # [serde (alias = "decrypt-key")] # [serde (default)] pub decrypt_key : Option < Option < String > > , # [doc = " Default: None"] # [serde (alias = "encrypt-key")] # [serde (default)] pub encrypt_key : Option < Option < String > > , # [doc = " Allow remote lookups"] # [doc = " Default: None"] # [serde (alias = "allow-remote-lookups")] # [serde (default)] pub allow_remote_lookup : Option < ToggleFlag > , # [doc = " Remote lookup mechanisms."] # [doc = " Default: \"local,wkd\""] # [cfg_attr (feature = "gpgme" , serde (alias = "remote-lookup-mechanisms"))] # [cfg (feature = "gpgme")] # [serde (default)] pub remote_lookup_mechanisms : Option < melib :: gpgme :: LocateKey > , # [cfg (not (feature = "gpgme"))] # [cfg_attr (not (feature = "gpgme") , serde (alias = "remote-lookup-mechanisms"))] # [serde (default)] pub remote_lookup_mechanisms : Option < String > } impl Default for PGPSettingsOverride { fn default () -> Self { PGPSettingsOverride { auto_verify_signatures : None , auto_decrypt : None , auto_sign : None , auto_encrypt : None , sign_key : None , decrypt_key : None , encrypt_key : None , allow_remote_lookup : None , remote_lookup_mechanisms : None } } }

View File

@ -19,13 +19,10 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
#[cfg(feature = "gpgme")]
use melib::conf::ToggleFlag;
#[cfg(feature = "gpgme")]
use super::default_vals::*;
#[cfg(feature = "gpgme")]
/// Settings for digital signing and encryption
#[derive(Debug, Deserialize, Clone, Serialize)]
#[serde(deny_unknown_fields)]
@ -70,11 +67,21 @@ pub struct PGPSettings {
/// Remote lookup mechanisms.
/// Default: "local,wkd"
#[serde(
default = "default_lookup_mechanism",
alias = "remote-lookup-mechanisms"
#[cfg_attr(
feature = "gpgme",
serde(
default = "default_lookup_mechanism",
alias = "remote-lookup-mechanisms"
)
)]
#[cfg(feature = "gpgme")]
pub remote_lookup_mechanisms: melib::gpgme::LocateKey,
#[cfg(not(feature = "gpgme"))]
#[cfg_attr(
not(feature = "gpgme"),
serde(default, alias = "remote-lookup-mechanisms")
)]
pub remote_lookup_mechanisms: String,
}
#[cfg(feature = "gpgme")]
@ -82,7 +89,6 @@ fn default_lookup_mechanism() -> melib::gpgme::LocateKey {
melib::gpgme::LocateKey::LOCAL | melib::gpgme::LocateKey::WKD
}
#[cfg(feature = "gpgme")]
impl Default for PGPSettings {
fn default() -> Self {
PGPSettings {
@ -94,12 +100,10 @@ impl Default for PGPSettings {
decrypt_key: None,
encrypt_key: None,
allow_remote_lookup: internal_value_false::<ToggleFlag>(),
#[cfg(feature = "gpgme")]
remote_lookup_mechanisms: default_lookup_mechanism(),
#[cfg(not(feature = "gpgme"))]
remote_lookup_mechanisms: String::new(),
}
}
}
#[cfg(not(feature = "gpgme"))]
#[derive(Debug, Default, Deserialize, Clone, Serialize)]
#[serde(deny_unknown_fields)]
pub struct PGPSettings;