Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/stackable-operator/src/crd/git_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pub mod versioned {
// See https://github.com/stackabletech/issues/issues/849 for details.
#[versioned(changed(
since = "v1alpha2",
from_name = "credentials_secret",
from_type = "Option<String>",
previous_name = "credentials_secret",
previous_type = "Option<String>",
upgrade_with = credentials_secret_to_basic_auth,
downgrade_with = credentials_to_secret
))]
Expand Down
76 changes: 38 additions & 38 deletions crates/stackable-versioned-macros/src/attrs/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,32 +223,32 @@ impl CommonItemAttributes {
let mut errors = Error::accumulator();

for change in &self.changes {
if change.from_name.is_none()
&& change.from_type.is_none()
&& change.from_docs.is_none()
if change.previous_name.is_none()
&& change.previous_type.is_none()
&& change.previous_docs.is_none()
{
errors.push(Error::custom(
"`from_name`, `from_type` and `from_docs` are unset. Is this `changed()` action needed?"
"`previous_name`, `previous_type` and `previous_docs` are unset. Is this `changed()` action needed?"
).with_span(&change.since.span()));
}

// This ensures that `from_name` doesn't include the deprecation prefix.
if let Some(from_name) = change.from_name.as_ref()
&& from_name.starts_with(item_ident.deprecation_prefix())
// This ensures that `previous_name` doesn't include the deprecation prefix.
if let Some(previous_name) = change.previous_name.as_ref()
&& previous_name.starts_with(item_ident.deprecation_prefix())
{
errors.push(
Error::custom("the previous name must not start with the deprecation prefix")
.with_span(&from_name.span()),
.with_span(&previous_name.span()),
);
}

if change.from_type.is_none() {
if change.previous_type.is_none() {
// The upgrade_with argument only makes sense to use when the
// type changed
if let Some(upgrade_func) = change.upgrade_with.as_ref() {
errors.push(
Error::custom(
"the `upgrade_with` argument must be used in combination with `from_type`",
"the `upgrade_with` argument must be used in combination with `previous_type`",
)
.with_span(&upgrade_func.span()),
);
Expand All @@ -259,7 +259,7 @@ impl CommonItemAttributes {
if let Some(downgrade_func) = change.downgrade_with.as_ref() {
errors.push(
Error::custom(
"the `downgrade_with` argument must be used in combination with `from_type`",
"the `downgrade_with` argument must be used in combination with `previous_type`",
)
.with_span(&downgrade_func.span()),
);
Expand Down Expand Up @@ -305,7 +305,7 @@ impl CommonItemAttributes {
self.changes
.iter()
.filter_map(|change| {
let docs = change.from_docs.as_deref()?;
let docs = change.previous_docs.as_deref()?;
Some((*change.since, docs.into_doc_comments()))
})
.collect()
Expand Down Expand Up @@ -339,16 +339,16 @@ impl CommonItemAttributes {
);

for change in self.changes.iter().rev() {
let from_ident = if let Some(from) = change.from_name.as_deref() {
let previous_ident = if let Some(from) = change.previous_name.as_deref() {
format_ident!("{from}").into()
} else {
ident.clone()
};

// TODO (@Techassi): This is an awful lot of cloning, can we get
// rid of it?
let from_ty = change
.from_type
let previous_type = change
.previous_type
.as_ref()
.map_or_else(|| ty.clone(), |sv| sv.deref().clone());

Expand All @@ -357,15 +357,15 @@ impl CommonItemAttributes {
ItemStatus::Change {
downgrade_with: change.downgrade_with.as_deref().cloned(),
upgrade_with: change.upgrade_with.as_deref().cloned(),
from_ident: from_ident.clone(),
from_type: Box::new(from_ty.clone()),
to_ident: ident,
to_type: Box::new(ty),
previous_ident: previous_ident.clone(),
previous_type: Box::new(previous_type.clone()),
current_ident: ident,
current_type: Box::new(ty),
},
);

ident = from_ident;
ty = from_ty;
ident = previous_ident;
ty = previous_type;
}

// After the last iteration above (if any) we use the ident for the
Expand All @@ -389,16 +389,16 @@ impl CommonItemAttributes {
let mut actions = BTreeMap::new();

for change in self.changes.iter().rev() {
let from_ident = if let Some(from) = change.from_name.as_deref() {
let previous_ident = if let Some(from) = change.previous_name.as_deref() {
format_ident!("{from}").into()
} else {
ident.clone()
};

// TODO (@Techassi): This is an awful lot of cloning, can we get
// rid of it?
let from_ty = change
.from_type
let previous_type = change
.previous_type
.as_ref()
.map_or_else(|| ty.clone(), |sv| sv.deref().clone());

Expand All @@ -407,15 +407,15 @@ impl CommonItemAttributes {
ItemStatus::Change {
downgrade_with: change.downgrade_with.as_deref().cloned(),
upgrade_with: change.upgrade_with.as_deref().cloned(),
from_ident: from_ident.clone(),
from_type: Box::new(from_ty.clone()),
to_ident: ident,
to_type: Box::new(ty),
previous_ident: previous_ident.clone(),
previous_type: Box::new(previous_type.clone()),
current_ident: ident,
current_type: Box::new(ty),
},
);

ident = from_ident;
ty = from_ty;
ident = previous_ident;
ty = previous_type;
}

// After the last iteration above (if any) we use the ident for the
Expand Down Expand Up @@ -477,17 +477,17 @@ fn default_default_fn() -> SpannedValue<Path> {
/// For the changed() action
///
/// Example usage:
/// - `changed(since = "...", from_name = "...")`
/// - `changed(since = "...", from_name = "...", from_type="...")`
/// - `changed(since = "...", from_name = "...", from_type="...", upgrade_with = "...")`
/// - `changed(since = "...", from_name = "...", from_type="...", downgrade_with = "...")`
/// - `changed(since = "...", from_docs = "...")`
/// - `changed(since = "...", previous_name = "...")`
/// - `changed(since = "...", previous_name = "...", previous_type="...")`
/// - `changed(since = "...", previous_name = "...", previous_type="...", upgrade_with = "...")`
/// - `changed(since = "...", previous_name = "...", previous_type="...", downgrade_with = "...")`
/// - `changed(since = "...", previous_docs = "...")`
#[derive(Clone, Debug, FromMeta)]
pub struct ChangedAttributes {
pub since: SpannedValue<Version>,
pub from_name: Option<SpannedValue<String>>,
pub from_type: Option<SpannedValue<Type>>,
pub from_docs: Option<SpannedValue<String>>,
pub previous_name: Option<SpannedValue<String>>,
pub previous_type: Option<SpannedValue<Type>>,
pub previous_docs: Option<SpannedValue<String>>,
pub upgrade_with: Option<SpannedValue<Path>>,
pub downgrade_with: Option<SpannedValue<Path>>,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/stackable-versioned-macros/src/attrs/item/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ impl VariantAttributes {

// Validate names of renames
for change in &self.common.changes {
if let Some(from_name) = &change.from_name
&& !is_case(from_name.as_str(), Case::Pascal)
if let Some(previous_name) = &change.previous_name
&& !is_case(previous_name.as_str(), Case::Pascal)
{
errors.push(
Error::custom("renamed variant must use PascalCase")
.with_span(&from_name.span()),
.with_span(&previous_name.span()),
);
}
}
Expand Down
21 changes: 13 additions & 8 deletions crates/stackable-versioned-macros/src/codegen/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub trait ChangesetExt {
}

impl ChangesetExt for BTreeMap<Version, ItemStatus> {
#[allow(clippy::too_many_lines)]
fn insert_container_versions(&mut self, versions: &[VersionDefinition], ty: &Type) {
for version in versions {
if self.contains_key(&version.inner) {
Expand All @@ -112,15 +113,15 @@ impl ChangesetExt for BTreeMap<Version, ItemStatus> {
self.insert(version.inner, ItemStatus::NotPresent)
}
ItemStatus::Change {
from_ident,
from_type,
previous_ident,
previous_type,
..
} => self.insert(
version.inner,
ItemStatus::NoChange {
previously_deprecated: false,
ident: from_ident.clone(),
ty: from_type.clone(),
ident: previous_ident.clone(),
ty: previous_type.clone(),
},
),
ItemStatus::Deprecation { previous_ident, .. } => self.insert(
Expand Down Expand Up @@ -149,8 +150,10 @@ impl ChangesetExt for BTreeMap<Version, ItemStatus> {
let (ident, ty, previously_deprecated) = match status {
ItemStatus::Addition { ident, ty, .. } => (ident, ty, false),
ItemStatus::Change {
to_ident, to_type, ..
} => (to_ident, to_type, false),
current_ident,
current_type,
..
} => (current_ident, current_type, false),
ItemStatus::Deprecation { ident, .. } => {
(ident, &Box::new(ty.clone()), true)
}
Expand All @@ -176,8 +179,10 @@ impl ChangesetExt for BTreeMap<Version, ItemStatus> {
let (ident, ty, previously_deprecated) = match status {
ItemStatus::Addition { ident, ty, .. } => (ident, ty, false),
ItemStatus::Change {
to_ident, to_type, ..
} => (to_ident, to_type, false),
current_ident,
current_type,
..
} => (current_ident, current_type, false),
ItemStatus::NoChange {
previously_deprecated,
ident,
Expand Down
18 changes: 10 additions & 8 deletions crates/stackable-versioned-macros/src/codegen/item/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ impl VersionedField {
pub #ident: #ty,
}),
ItemStatus::Change {
to_ident, to_type, ..
current_ident,
current_type,
..
} => Some(quote! {
#attributes
pub #to_ident: #to_type,
pub #current_ident: #current_type,
}),
ItemStatus::Deprecation {
ident: field_ident,
Expand Down Expand Up @@ -239,21 +241,21 @@ impl VersionedField {
ItemStatus::Change {
downgrade_with,
upgrade_with,
from_ident,
to_ident,
previous_ident,
current_ident,
..
},
) => match direction {
Direction::Upgrade => Some(self.generate_from_impl_field(
to_ident,
current_ident,
from_struct_ident,
from_ident,
previous_ident,
upgrade_with.as_ref(),
)),
Direction::Downgrade => Some(self.generate_from_impl_field(
from_ident,
previous_ident,
from_struct_ident,
to_ident,
current_ident,
downgrade_with.as_ref(),
)),
},
Expand Down
13 changes: 7 additions & 6 deletions crates/stackable-versioned-macros/src/codegen/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use variant::*;

/// Generates the attributes of an item (field or variant) for the provided `version`.
///
/// If the docs of the item are changed in a later version (via `from_docs`), the original doc
/// If the docs of the item are changed in a later version (via `previous_docs`), the original doc
/// comments are replaced by the docs which are valid in `version`.
pub fn generate_attributes(
original_attributes: &[Attribute],
Expand Down Expand Up @@ -51,10 +51,10 @@ pub enum ItemStatus {
Change {
downgrade_with: Option<Path>,
upgrade_with: Option<Path>,
from_ident: IdentString,
to_ident: IdentString,
from_type: Box<Type>,
to_type: Box<Type>,
previous_ident: IdentString,
current_ident: IdentString,
previous_type: Box<Type>,
current_type: Box<Type>,
},
Deprecation {
previous_ident: IdentString,
Expand All @@ -74,7 +74,8 @@ impl ItemStatus {
match &self {
Self::Addition { ident, .. }
| Self::Change {
to_ident: ident, ..
current_ident: ident,
..
}
| Self::Deprecation { ident, .. }
| Self::NoChange { ident, .. } => ident,
Expand Down
4 changes: 2 additions & 2 deletions crates/stackable-versioned-macros/src/codegen/item/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl VersionedVariant {
#attributes
#ident #fields,
}),
ItemStatus::Change { to_ident, .. } => Some(quote! {
ItemStatus::Change { current_ident, .. } => Some(quote! {
#attributes
#to_ident #fields,
#current_ident #fields,
}),
ItemStatus::Deprecation { ident, note, .. } => {
// FIXME (@Techassi): Emitting the deprecated attribute
Expand Down
Loading
Loading