Renames frame crate to polkadot-sdk-frame (#3813)

Step in https://github.com/paritytech/polkadot-sdk/issues/3155

Needed for https://github.com/paritytech/eng-automation/issues/6

This PR renames `frame` crate to `polkadot-sdk-frame` as `frame` is not
available on crates.io

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
gupnik
2024-04-04 07:50:15 +05:30
committed by GitHub
parent 0f4e849e0a
commit 3836376965
19 changed files with 130 additions and 78 deletions
@@ -665,9 +665,9 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream
"{}::macro_magic",
match generate_access_from_frame_or_crate("frame-support") {
Ok(path) => Ok(path),
Err(_) => generate_access_from_frame_or_crate("frame"),
Err(_) => generate_access_from_frame_or_crate("polkadot-sdk-frame"),
}
.expect("Failed to find either `frame-support` or `frame` in `Cargo.toml` dependencies.")
.expect("Failed to find either `frame-support` or `polkadot-sdk-frame` in `Cargo.toml` dependencies.")
.to_token_stream()
.to_string()
)
@@ -1181,9 +1181,9 @@ pub fn pallet_section(attr: TokenStream, tokens: TokenStream) -> TokenStream {
"{}::macro_magic",
match generate_access_from_frame_or_crate("frame-support") {
Ok(path) => Ok(path),
Err(_) => generate_access_from_frame_or_crate("frame"),
Err(_) => generate_access_from_frame_or_crate("polkadot-sdk-frame"),
}
.expect("Failed to find either `frame-support` or `frame` in `Cargo.toml` dependencies.")
.expect("Failed to find either `frame-support` or `polkadot-sdk-frame` in `Cargo.toml` dependencies.")
.to_token_stream()
.to_string()
)
@@ -275,7 +275,8 @@ fn check_event_type(
}
/// Check that the path to `frame_system::Config` is valid, this is that the path is just
/// `frame_system::Config` or when using the `frame` crate it is `frame::xyz::frame_system::Config`.
/// `frame_system::Config` or when using the `frame` crate it is
/// `polkadot_sdk_frame::xyz::frame_system::Config`.
fn has_expected_system_config(path: syn::Path, frame_system: &syn::Path) -> bool {
// Check if `frame_system` is actually 'frame_system'.
if path.segments.iter().all(|s| s.ident != "frame_system") {
@@ -293,7 +294,7 @@ fn has_expected_system_config(path: syn::Path, frame_system: &syn::Path) -> bool
// `frame` re-exports it as such.
syn::parse2::<syn::Path>(quote::quote!(frame_system)).expect("is a valid path; qed"),
(_, _) =>
// They are either both `frame_system` or both `frame::xyz::frame_system`.
// They are either both `frame_system` or both `polkadot_sdk_frame::xyz::frame_system`.
frame_system.clone(),
};
@@ -516,14 +517,28 @@ mod tests {
#[test]
fn has_expected_system_config_works_with_frame() {
let path = syn::parse2::<syn::Path>(quote::quote!(frame_system::Config)).unwrap();
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::deps::frame_system))
.unwrap();
assert!(has_expected_system_config(path.clone(), &frame_system));
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(frame::deps::frame_system)).unwrap();
let path = syn::parse2::<syn::Path>(quote::quote!(frame_system::Config)).unwrap();
assert!(has_expected_system_config(path, &frame_system));
}
#[test]
fn has_expected_system_config_works_with_frame_full_path() {
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::deps::frame_system))
.unwrap();
let path =
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config))
.unwrap();
assert!(has_expected_system_config(path, &frame_system));
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(frame::deps::frame_system)).unwrap();
let path =
@@ -533,6 +548,13 @@ mod tests {
#[test]
fn has_expected_system_config_works_with_other_frame_full_path() {
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap();
let path =
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config))
.unwrap();
assert!(has_expected_system_config(path, &frame_system));
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(frame::xyz::frame_system)).unwrap();
let path =
@@ -543,18 +565,21 @@ mod tests {
#[test]
fn has_expected_system_config_does_not_works_with_mixed_frame_full_path() {
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(frame::xyz::frame_system)).unwrap();
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap();
let path =
syn::parse2::<syn::Path>(quote::quote!(frame::deps::frame_system::Config)).unwrap();
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config))
.unwrap();
assert!(!has_expected_system_config(path, &frame_system));
}
#[test]
fn has_expected_system_config_does_not_works_with_other_mixed_frame_full_path() {
let frame_system =
syn::parse2::<syn::Path>(quote::quote!(frame::deps::frame_system)).unwrap();
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::deps::frame_system))
.unwrap();
let path =
syn::parse2::<syn::Path>(quote::quote!(frame::xyz::frame_system::Config)).unwrap();
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config))
.unwrap();
assert!(!has_expected_system_config(path, &frame_system));
}
@@ -562,7 +587,8 @@ mod tests {
fn has_expected_system_config_does_not_work_with_frame_full_path_if_not_frame_crate() {
let frame_system = syn::parse2::<syn::Path>(quote::quote!(frame_system)).unwrap();
let path =
syn::parse2::<syn::Path>(quote::quote!(frame::deps::frame_system::Config)).unwrap();
syn::parse2::<syn::Path>(quote::quote!(polkadot_sdk_frame::deps::frame_system::Config))
.unwrap();
assert!(!has_expected_system_config(path, &frame_system));
}