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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[versioned(
version(name = "v1alpha1"),
version(name = "v1beta1"),
options(skip(from))
)]
// ---
pub(crate) mod versioned {
pub struct Foo {
bar: usize,

#[versioned(added(since = "v1beta1"))]
baz: bool,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[versioned(
version(name = "v1alpha1"),
version(name = "v1beta1", skip(from)),
version(name = "v1")
)]
// ---
pub(crate) mod versioned {
pub struct Foo {
bar: usize,

#[versioned(added(since = "v1beta1"))]
baz: bool,
}

pub struct Bar {
foo: usize,

#[versioned(added(since = "v1beta1"))]
faz: bool,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/stackable-versioned-macros/src/codegen/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ impl ChangesetExt for BTreeMap<Version, ItemStatus> {
ty,
..
} => (ident, ty, *previously_deprecated),
// TODO (@NickLarsenNZ): Explain why it is unreachable, as it can be reached during testing.
// To reproduce, use an invalid version, eg: #[versioned(deprecated(since = "v99"))]
_ => unreachable!(),
};

Expand Down
15 changes: 10 additions & 5 deletions crates/stackable-versioned-macros/src/codegen/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) struct Module {
versions: Vec<VersionDefinition>,
containers: Vec<Container>,
preserve_module: bool,
skip_from: bool,
ident: IdentString,
vis: Visibility,
}
Expand All @@ -31,13 +32,15 @@ impl Module {
pub(crate) fn new(
ModuleInput { ident, vis, .. }: ModuleInput,
preserve_module: bool,
skip_from: bool,
versions: Vec<VersionDefinition>,
containers: Vec<Container>,
) -> Self {
Self {
ident: ident.into(),
preserve_module,
containers,
skip_from,
versions,
vis,
}
Expand Down Expand Up @@ -77,11 +80,13 @@ impl Module {
for container in &self.containers {
container_definitions.extend(container.generate_definition(version));

from_impls.extend(container.generate_from_impl(
version,
versions.peek().copied(),
self.preserve_module,
));
if !self.skip_from {
from_impls.extend(container.generate_from_impl(
version,
versions.peek().copied(),
self.preserve_module,
));
}

// Generate Kubernetes specific code which is placed outside of the container
// definition.
Expand Down
15 changes: 14 additions & 1 deletion crates/stackable-versioned-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ fn versioned_impl(attrs: proc_macro2::TokenStream, input: Item) -> proc_macro2::

let versions: Vec<VersionDefinition> = (&module_attributes).into();
let preserve_modules = module_attributes.preserve_module.is_present();
let skip_from = module_attributes
.common_root_arguments
.options
.skip
.as_ref()
.map_or(false, |opts| opts.from.is_present());

let module_span = item_mod.span();
let module_input = ModuleInput {
Expand Down Expand Up @@ -541,7 +547,14 @@ fn versioned_impl(attrs: proc_macro2::TokenStream, input: Item) -> proc_macro2::
containers.push(container);
}

Module::new(module_input, preserve_modules, versions, containers).generate_tokens()
Module::new(
module_input,
preserve_modules,
skip_from,
versions,
containers,
)
.generate_tokens()
}
Item::Enum(item_enum) => {
let container_attributes: StandaloneContainerAttributes =
Expand Down
2 changes: 2 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file.
- Correctly emit Kubernetes code when macro is used on modules ([#912]).
- Use `.into()` on all field conversions ([#925]).
- Remove invalid type comparison on field conversion because the semantics are unknown ([#925]).
- Check whether to skip all from impls when versioning a module ([#926]).

[#891]: https://github.com/stackabletech/operator-rs/pull/891
[#912]: https://github.com/stackabletech/operator-rs/pull/912
Expand All @@ -42,6 +43,7 @@ All notable changes to this project will be documented in this file.
[#923]: https://github.com/stackabletech/operator-rs/pull/923
[#924]: https://github.com/stackabletech/operator-rs/pull/924
[#925]: https://github.com/stackabletech/operator-rs/pull/925
[#926]: https://github.com/stackabletech/operator-rs/pull/926

## [0.4.1] - 2024-10-23

Expand Down
Loading