From 87dddad0eb9a129dd2f35b4c476ebe701ea78fb1 Mon Sep 17 00:00:00 2001 From: Kurt Wolf Date: Mon, 18 Dec 2023 14:42:58 -0500 Subject: [PATCH] respect pre-1.0 versions --- libninja/src/rust/cargo_toml.rs | 12 +++++++++--- libninja/src/rust/codegen/typ.rs | 22 ++++++++++++++++++++++ libninja/src/rust/lower_mir.rs | 4 +++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/libninja/src/rust/cargo_toml.rs b/libninja/src/rust/cargo_toml.rs index 50d5ab3..db6e50f 100644 --- a/libninja/src/rust/cargo_toml.rs +++ b/libninja/src/rust/cargo_toml.rs @@ -31,9 +31,14 @@ pub fn update_cargo_toml(extras: &Extras, opts: &OutputConfig, context: &HashMap *t = "0.1.0".to_string(); } else { let mut ver = semver::Version::parse(t).unwrap(); - ver.major += 1; - ver.minor = 0; - ver.patch = 0; + if ver.major == 0 { + ver.minor += 1; + ver.patch = 0; + } else { + ver.major += 1; + ver.minor = 0; + ver.patch = 0; + } *t = ver.to_string(); } } @@ -76,6 +81,7 @@ fn detailed(version: &str, features: &[&str]) -> Dependency { Dependency::Detailed(DependencyDetail { version: Some(version.to_string()), features: features.iter().map(|f| f.to_string()).collect(), + default_features: true, ..DependencyDetail::default() }) } diff --git a/libninja/src/rust/codegen/typ.rs b/libninja/src/rust/codegen/typ.rs index 4cce37d..1ccb0bf 100644 --- a/libninja/src/rust/codegen/typ.rs +++ b/libninja/src/rust/codegen/typ.rs @@ -10,6 +10,7 @@ pub trait ToRustType { fn to_reference_type(&self, specifier: TokenStream) -> TokenStream; fn is_reference_type(&self) -> bool; fn implements_default(&self, spec: &HirSpec) -> bool; + fn implements_dummy(&self, spec: &HirSpec) -> bool; } impl ToRustType for Ty { @@ -86,4 +87,25 @@ impl ToRustType for Ty { Ty::Currency { .. } => true, } } + + fn implements_dummy(&self, spec: &HirSpec) -> bool { + match self { + Ty::String => true, + Ty::Integer { .. } => true, + Ty::Float => true, + Ty::Boolean => true, + Ty::Array(inner) => { + inner.implements_dummy(spec) + } + Ty::Model(name) => { + let model = spec.get_record(name.as_str()).expect("Model not found"); + model.fields().all(|f| f.ty.implements_dummy(spec)) + } + Ty::Unit => true, + Ty::Any => false, + Ty::Date { .. } => true, + Ty::DateTime => true, + Ty::Currency { .. } => true, + } + } } diff --git a/libninja/src/rust/lower_mir.rs b/libninja/src/rust/lower_mir.rs index a447721..0360777 100644 --- a/libninja/src/rust/lower_mir.rs +++ b/libninja/src/rust/lower_mir.rs @@ -224,7 +224,8 @@ pub struct RefTarget { pub fn create_sumtype_struct(schema: &Struct, config: &ConfigFlags, spec: &HirSpec) -> TokenStream { let default = schema.derive_default(spec); let ormlite = config.ormlite.then(|| { quote! { , TableMeta, IntoArguments } }).unwrap_or_default(); - let dummy = config.fake.then(|| { quote! { , Dummy } }).unwrap_or_default(); + let fake = config.fake && schema.fields.values().all(|f| f.ty.implements_dummy(spec)); + let dummy = fake.then(|| { quote! { , Dummy } }).unwrap_or_default(); let docs = schema.docs.clone().to_rust_code(); let name = schema.name.to_rust_struct(); @@ -335,6 +336,7 @@ mod tests { ty: Ty::String, ..HirField::default() }], + docs: None, }; let code = create_newtype_struct(&schema); let code = format_code(code).unwrap();