Skip to content

Commit

Permalink
feat: Make note of deprecated action optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Sep 2, 2024
1 parent 3937f57 commit f2c367e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
17 changes: 2 additions & 15 deletions crates/stackable-versioned-macros/src/attrs/common/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,6 @@ impl ItemAttributes {

let mut errors = Error::accumulator();

// TODO (@Techassi): Make the field or variant 'note' optional, because
// in the future, the macro will generate parts of the deprecation note
// automatically. The user-provided note will then be appended to the
// auto-generated one.

if let Some(deprecated) = &self.deprecated {
if deprecated.note.is_empty() {
errors.push(
Error::custom("deprecation note must not be empty")
.with_span(&deprecated.note.span()),
);
}
}

// Semantic validation
errors.handle(self.validate_action_combinations(item_ident, item_type));
errors.handle(self.validate_action_order(item_ident, item_type));
Expand Down Expand Up @@ -348,9 +334,10 @@ pub(crate) struct ChangedAttributes {
/// For the deprecated() action
///
/// Example usage:
/// - `deprecated(since = "...")`
/// - `deprecated(since = "...", note = "...")`
#[derive(Clone, Debug, FromMeta)]
pub(crate) struct DeprecatedAttributes {
pub(crate) since: SpannedValue<Version>,
pub(crate) note: SpannedValue<String>,
pub(crate) note: Option<SpannedValue<String>>,
}
4 changes: 2 additions & 2 deletions crates/stackable-versioned-macros/src/codegen/common/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where
ItemStatus::Deprecation {
previous_ident: ident.clone(),
ident: deprecated_ident.clone(),
note: deprecated.note.to_string(),
note: deprecated.note.as_deref().cloned(),
},
);

Expand Down Expand Up @@ -363,8 +363,8 @@ pub(crate) enum ItemStatus {
},
Deprecation {
previous_ident: Ident,
note: Option<String>,
ident: Ident,
note: String,
},
NoChange(Ident),
NotPresent,
Expand Down
26 changes: 21 additions & 5 deletions crates/stackable-versioned-macros/src/codegen/vstruct/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,27 @@ impl VersionedField {
ident: field_ident,
note,
..
} => Some(quote! {
#(#original_attributes)*
#[deprecated = #note]
pub #field_ident: #field_type,
}),
} => {
// FIXME (@Techassi): Emitting the deprecated attribute
// should cary over even when the item status is
// 'NoChange'.
// TODO (@Techassi): Make the generation of deprecated
// items customizable. When a container is used as a K8s
// CRD, the item must continue to exist, even when
// deprecated. For other versioning use-cases, that
// might not be the case.
let deprecated_attr = if let Some(note) = note {
quote! {#[deprecated = #note]}
} else {
quote! {#[deprecated]}
};

Some(quote! {
#(#original_attributes)*
#deprecated_attr
pub #field_ident: #field_type,
})
}
ItemStatus::NotPresent => None,
ItemStatus::NoChange(field_ident) => Some(quote! {
#(#original_attributes)*
Expand Down

0 comments on commit f2c367e

Please sign in to comment.