mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 17:15:41 +00:00
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:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,15 +54,19 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream {
|
||||
///
|
||||
/// This will usually check the output of [`generate_access_from_frame_or_crate`].
|
||||
/// We want to know if whatever the `path` takes us to, is exported from `frame` or not. In that
|
||||
/// case `path` would start with `frame`, something like `frame::x::y:z`.
|
||||
/// case `path` would start with `frame`, something like `polkadot_sdk_frame::x::y:z` or
|
||||
/// frame::x::y:z.
|
||||
pub fn is_using_frame_crate(path: &syn::Path) -> bool {
|
||||
path.segments.first().map(|s| s.ident == "frame").unwrap_or(false)
|
||||
path.segments
|
||||
.first()
|
||||
.map(|s| s.ident == "polkadot_sdk_frame" || s.ident == "frame")
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Generate the crate access for the crate using 2018 syntax.
|
||||
///
|
||||
/// If `frame` is in scope, it will use `frame::deps::<def_crate>`. Else, it will try and find
|
||||
/// `<def_crate>` directly.
|
||||
/// If `frame` is in scope, it will use `polkadot_sdk_frame::deps::<def_crate>`. Else, it will try
|
||||
/// and find `<def_crate>` directly.
|
||||
pub fn generate_access_from_frame_or_crate(def_crate: &str) -> Result<syn::Path, Error> {
|
||||
if let Some(path) = get_frame_crate_path(def_crate) {
|
||||
Ok(path)
|
||||
@@ -114,7 +118,9 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream
|
||||
/// Generates the path to the frame crate deps.
|
||||
fn get_frame_crate_path(def_crate: &str) -> Option<syn::Path> {
|
||||
// This does not work if the frame crate is renamed.
|
||||
if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") {
|
||||
if let Ok(FoundCrate::Name(name)) =
|
||||
crate_name(&"polkadot-sdk-frame").or_else(|_| crate_name(&"frame"))
|
||||
{
|
||||
let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_"));
|
||||
Some(syn::parse_str::<syn::Path>(&path).expect("is a valid path; qed"))
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
|
||||
frame = { path = "../../..", default-features = false, features = ["experimental", "runtime"] }
|
||||
frame = { package = "polkadot-sdk-frame", path = "../../..", default-features = false, features = ["experimental", "runtime"] }
|
||||
scale-info = { version = "2.11.1", default-features = false, features = ["derive"] }
|
||||
|
||||
[features]
|
||||
|
||||
+3
-3
@@ -17,13 +17,13 @@
|
||||
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame::deps::frame_system::pallet_prelude::BlockNumberFor;
|
||||
use polkadot_sdk_frame::deps::frame_system::pallet_prelude::BlockNumberFor;
|
||||
use frame_support::pallet_prelude::{Hooks, IsType};
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame::deps::frame_system::Config {
|
||||
pub trait Config: polkadot_sdk_frame::deps::frame_system::Config {
|
||||
type Bar: Clone + std::fmt::Debug + Eq;
|
||||
type RuntimeEvent: IsType<<Self as frame::deps::frame_system::Config>::RuntimeEvent>
|
||||
type RuntimeEvent: IsType<<Self as polkadot_sdk_frame::deps::frame_system::Config>::RuntimeEvent>
|
||||
+ From<Event<Self>>;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error: Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must bound: `IsType<<Self as frame_system::Config>::RuntimeEvent>`
|
||||
--> tests/pallet_ui/event_type_invalid_bound_no_frame_crate.rs:26:3
|
||||
|
|
||||
26 | type RuntimeEvent: IsType<<Self as frame::deps::frame_system::Config>::RuntimeEvent>
|
||||
26 | type RuntimeEvent: IsType<<Self as polkadot_sdk_frame::deps::frame_system::Config>::RuntimeEvent>
|
||||
| ^^^^
|
||||
|
||||
Reference in New Issue
Block a user