mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Gate generated registry helpers on dependency suite
This commit is contained in:
@@ -29,3 +29,19 @@ pub mod __private {
|
||||
pub use egui;
|
||||
pub use inventory;
|
||||
}
|
||||
|
||||
/// Emits generated suite-only items when this dependency enables the suite.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(feature = "suite")]
|
||||
macro_rules! __suite_items {
|
||||
($($item:item)*) => { $($item)* };
|
||||
}
|
||||
|
||||
/// Discards generated suite-only items in fixture-only consumers.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "suite"))]
|
||||
macro_rules! __suite_items {
|
||||
($($item:item)*) => {};
|
||||
}
|
||||
|
||||
@@ -236,8 +236,10 @@ fn registrations(k: &TokenStream, types: &[Type], declared: &Declared, shape: Sh
|
||||
let helper = registry_helper(types)?;
|
||||
Ok(quote! {
|
||||
#gate
|
||||
pub(crate) fn #helper(registry: &mut #k::testing::Registry) {
|
||||
#(registry.add_registration(<#types as #k::testing::Registered>::registration());)*
|
||||
#k::__suite_items! {
|
||||
pub(crate) fn #helper(registry: &mut #k::testing::Registry) {
|
||||
#(registry.add_registration(<#types as #k::testing::Registered>::registration());)*
|
||||
}
|
||||
}
|
||||
|
||||
// Outside the gate: the sample exists in every build, so it is never dead code where the registration is absent.
|
||||
@@ -261,8 +263,10 @@ pub(crate) fn pattern_registrations(k: &TokenStream, types: &[Type], purpose: &s
|
||||
};
|
||||
quote! {
|
||||
#gate
|
||||
pub(crate) fn #helper(registry: &mut #k::testing::Registry) {
|
||||
#(registry.add_registration(<#types as #k::testing::Registered>::registration());)*
|
||||
#k::__suite_items! {
|
||||
pub(crate) fn #helper(registry: &mut #k::testing::Registry) {
|
||||
#(registry.add_registration(<#types as #k::testing::Registered>::registration());)*
|
||||
}
|
||||
}
|
||||
#gate
|
||||
const _: () = {
|
||||
|
||||
@@ -266,7 +266,9 @@ pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
#func
|
||||
|
||||
#gate
|
||||
pub(crate) fn #helper() -> #k::testing::StoryRegistration { #registration }
|
||||
#k::__suite_items! {
|
||||
pub(crate) fn #helper() -> #k::testing::StoryRegistration { #registration }
|
||||
}
|
||||
|
||||
}
|
||||
.into()
|
||||
|
||||
@@ -23,7 +23,7 @@ pub use craft_ui_canvas::{canvas, canvas_controls, dialog};
|
||||
#[cfg(feature = "testing")]
|
||||
pub use craft_ui_contract::registry;
|
||||
#[doc(hidden)]
|
||||
pub use craft_ui_contract::{__private, __register_command_set, __register_contract, __register_pattern};
|
||||
pub use craft_ui_contract::{__private, __register_command_set, __register_contract, __register_pattern, __suite_items};
|
||||
pub use craft_ui_contract::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words};
|
||||
pub use craft_ui_panels::{docking, rails, sections};
|
||||
pub use craft_ui_shell::shell;
|
||||
|
||||
Reference in New Issue
Block a user