Skip to content

Commit a0e1fcd

Browse files
committed
fix(stackable-versioned): Only emit tracking_into if opted in
1 parent 968a52c commit a0e1fcd

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

crates/stackable-versioned-macros/src/codegen/container/struct/conversion.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ impl Struct {
144144
self.fields
145145
.iter()
146146
.filter_map(|f| {
147-
f.generate_for_from_impl(direction, version, next_version, from_struct_ident)
147+
f.generate_for_from_impl(
148+
direction,
149+
version,
150+
next_version,
151+
from_struct_ident,
152+
mod_gen_ctx,
153+
)
148154
})
149155
.collect()
150156
};

crates/stackable-versioned-macros/src/codegen/container/struct/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,13 @@ impl Struct {
469469
self.fields
470470
.iter()
471471
.filter_map(|f| {
472-
f.generate_for_from_impl(direction, version, next_version, from_struct_ident)
472+
f.generate_for_from_impl(
473+
direction,
474+
version,
475+
next_version,
476+
from_struct_ident,
477+
mod_gen_ctx,
478+
)
473479
})
474480
.collect()
475481
};

crates/stackable-versioned-macros/src/codegen/item/field.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ impl VersionedField {
151151
version: &VersionDefinition,
152152
next_version: &VersionDefinition,
153153
from_struct_ident: &IdentString,
154+
mod_gen_ctx: ModuleGenerationContext<'_>,
154155
) -> Option<TokenStream> {
156+
let experimental_conversion_tracking = mod_gen_ctx
157+
.kubernetes_options
158+
.experimental_conversion_tracking
159+
.is_present();
160+
155161
match &self.changes {
156162
Some(changes) => {
157163
let next_change = changes.get_expect(&next_version.inner);
@@ -190,10 +196,12 @@ impl VersionedField {
190196
}),
191197
// Default .into() call using From impls.
192198
None => {
193-
let json_path_ident =
194-
format_ident!("__sv_{ident}_path", ident = to_ident.as_ident());
199+
if self.nested && experimental_conversion_tracking {
200+
let json_path_ident = format_ident!(
201+
"__sv_{ident}_path",
202+
ident = to_ident.as_ident()
203+
);
195204

196-
if self.nested {
197205
Some(quote! {
198206
#to_ident: #from_struct_ident.#from_ident.tracking_into(status, #json_path_ident),
199207
})
@@ -209,12 +217,12 @@ impl VersionedField {
209217
#from_ident: #downgrade_fn(#from_struct_ident.#to_ident),
210218
}),
211219
None => {
212-
let json_path_ident = format_ident!(
213-
"__sv_{ident}_path",
214-
ident = from_ident.as_ident()
215-
);
220+
if self.nested && experimental_conversion_tracking {
221+
let json_path_ident = format_ident!(
222+
"__sv_{ident}_path",
223+
ident = from_ident.as_ident()
224+
);
216225

217-
if self.nested {
218226
Some(quote! {
219227
#from_ident: #from_struct_ident.#to_ident.tracking_into(status, #json_path_ident),
220228
})
@@ -235,12 +243,12 @@ impl VersionedField {
235243
// in some edge cases.
236244
match direction {
237245
Direction::Upgrade => {
238-
let json_path_ident = format_ident!(
239-
"__sv_{ident}_path",
240-
ident = next_field_ident.as_ident()
241-
);
246+
if self.nested && experimental_conversion_tracking {
247+
let json_path_ident = format_ident!(
248+
"__sv_{ident}_path",
249+
ident = next_field_ident.as_ident()
250+
);
242251

243-
if self.nested {
244252
Some(quote! {
245253
#next_field_ident: #from_struct_ident.#old_field_ident.tracking_into(status, #json_path_ident),
246254
})
@@ -259,10 +267,11 @@ impl VersionedField {
259267
}
260268
None => {
261269
let field_ident = &*self.ident;
262-
let json_path_ident =
263-
format_ident!("__sv_{ident}_path", ident = field_ident.as_ident());
264270

265-
if self.nested {
271+
if self.nested && experimental_conversion_tracking {
272+
let json_path_ident =
273+
format_ident!("__sv_{ident}_path", ident = field_ident.as_ident());
274+
266275
Some(quote! {
267276
#field_ident: #from_struct_ident.#field_ident.tracking_into(status, &#json_path_ident),
268277
})

0 commit comments

Comments
 (0)