Skip to content

Commit

Permalink
respect pre-1.0 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Dec 18, 2023
1 parent 200b1da commit 87dddad
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
12 changes: 9 additions & 3 deletions libninja/src/rust/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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()
})
}
Expand Down
22 changes: 22 additions & 0 deletions libninja/src/rust/codegen/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
}
4 changes: 3 additions & 1 deletion libninja/src/rust/lower_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 87dddad

Please sign in to comment.