Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros to use path instead of ident #1474

Merged
merged 34 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7102f28
use path instead of ident
juangirini Sep 8, 2023
933fd3f
fix clippy
juangirini Sep 8, 2023
dc43fa5
add path changes to frame_support
juangirini Sep 11, 2023
16668ca
add frame conditional
juangirini Sep 11, 2023
ebd13e3
remove references to the frame-crate
juangirini Sep 11, 2023
270a6b7
update fn description
juangirini Sep 11, 2023
8be65aa
update fn description
juangirini Sep 11, 2023
850a77e
make benchmarks to use generate_crate_access_2018
juangirini Sep 11, 2023
5ae6e07
undo unrelated changes
juangirini Sep 12, 2023
04dc503
undo unrelated changes
juangirini Sep 12, 2023
95444ae
update macro description
juangirini Sep 12, 2023
6a773d0
refactor `generate_crate_access`
juangirini Sep 12, 2023
bc17557
unhardcode codec import
juangirini Sep 13, 2023
6d9887b
bring in hypotetical frame crate
juangirini Sep 14, 2023
35747a1
refactor expected_system_config and add tests
juangirini Sep 15, 2023
330af4a
".git/.scripts/commands/fmt/fmt.sh"
Sep 15, 2023
10bf65c
make zepter happy
juangirini Sep 15, 2023
97bfec4
improve comment
juangirini Sep 21, 2023
6a07bb3
add event_type_bound_system_config_assoc_type test
juangirini Sep 22, 2023
f303276
implement review suggestions
juangirini Oct 2, 2023
963be94
implement review suggestions
juangirini Oct 2, 2023
76de90d
add dummy frame crate for testing
juangirini Oct 3, 2023
32f2f1e
add pallet test example with frame crate
juangirini Oct 4, 2023
877fdc3
wip
juangirini Oct 4, 2023
c89c0c7
make dummy pallet work with frame crate
juangirini Oct 4, 2023
8184085
add dummy pallet with frame crate
juangirini Oct 4, 2023
1ee920b
add min runtime ui test
juangirini Oct 6, 2023
5050625
simplify example pallet
juangirini Oct 12, 2023
55daf79
update comment
juangirini Oct 12, 2023
43ca2c2
zepter improvement
juangirini Oct 12, 2023
2a2b45f
Merge branch 'master' into jg/frame-crate-path
juangirini Oct 12, 2023
b55615b
fix broken test
juangirini Oct 12, 2023
d253b66
update compile test
juangirini Oct 13, 2023
d2009d3
fix todo
juangirini Oct 13, 2023
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
Prev Previous commit
Next Next commit
add min runtime ui test
  • Loading branch information
juangirini committed Oct 6, 2023
commit 1ee920b69525929769c9105b67c5a949485b760b
6 changes: 4 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ members = [
"substrate/frame/support/test",
"substrate/frame/support/test/compile_pass",
"substrate/frame/support/test/pallet",
"substrate/frame/support/test/pallet_frame_crate",
"substrate/frame/support/test/pallet_frame_crate/frame",
"substrate/frame/support/test/pallet_frame_crate",
"substrate/frame/system",
"substrate/frame/system/benchmarking",
"substrate/frame/system/rpc/runtime-api",
Expand Down
12 changes: 12 additions & 0 deletions substrate/frame/support/procedural/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ pub fn generate_crate_access_from_frame_or_deps(def_crate: &str) -> Result<syn::
pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream {
let mod_name = generate_hidden_includes_mod_name(unique_id);

// TODO: improve this to avoid code duplication with `generate_crate_access_from_frame_or_deps`.
if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") {
let path = format!("{}::deps::{}", name, def_crate.to_string().replace("-", "_"));
let path = syn::parse_str::<syn::Path>(&path).expect("is a valid path; qed");
return quote::quote!(
#[doc(hidden)]
mod #mod_name {
pub use #path as hidden_include;
}
)
}

match crate_name(def_crate) {
Ok(FoundCrate::Itself) => quote!(),
Ok(FoundCrate::Name(name)) => {
Expand Down
8 changes: 5 additions & 3 deletions substrate/frame/support/test/pallet_frame_crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frame-support-test-pallet-frame-crate"
version = "4.0.0-dev"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
Expand All @@ -13,10 +13,12 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
frame = { path = "frame", default-features = false}
rustversion = "1.0.6"
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
sp-runtime = { path = "../../../../primitives/runtime", default-features = false}
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
trybuild = { version = "1.0.74", features = [ "diff" ] }

[features]
default = [ "std" ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frame"
version = "4.0.0-dev"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
Expand Down
11 changes: 7 additions & 4 deletions substrate/frame/support/test/pallet_frame_crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@

pub use pallet::*;

#[frame::deps::frame_support::pallet]
use frame::deps::{frame_support, frame_system};

#[frame_support::pallet]
pub mod pallet {
use frame::deps::frame_support::pallet_prelude::*;
use super::*;
use frame_support::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand All @@ -36,13 +39,13 @@ pub mod pallet {
// pub trait Config: frame_system::Config {}
// ```
// if `frame_system` is brought into scope.
pub trait Config: frame::deps::frame_system::Config {}
pub trait Config: frame_system::Config {}

#[pallet::storage]
pub type Value<T> = StorageValue<_, u32>;

#[pallet::genesis_config]
#[derive(frame::deps::frame_support::DefaultNoBound)]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
#[serde(skip)]
_config: core::marker::PhantomData<T>,
Expand Down
35 changes: 35 additions & 0 deletions substrate/frame/support/test/pallet_frame_crate/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[rustversion::attr(not(stable), ignore)]
#[cfg(not(feature = "disable-ui-tests"))]
#[test]
fn frame_crate_ui() {
// Only run the ui tests when `RUN_UI_TESTS` is set.
if std::env::var("RUN_UI_TESTS").is_err() {
return
}

// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");

// Deny all warnings since we emit warnings as part of a Pallet's UI.
std::env::set_var("RUSTFLAGS", "--deny warnings");

let t = trybuild::TestCases::new();
t.pass("tests/ui/*.rs");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use frame::deps::{
frame_support::{construct_runtime, derive_impl},
frame_system,
};

type Block = frame_system::mocking::MockBlock<Runtime>;

impl frame_support_test_pallet_frame_crate::pallet::Config for Runtime {}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type Block = Block;
}

construct_runtime! {
pub struct Runtime
{
System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
Pallet: frame_support_test_pallet_frame_crate::pallet::{Pallet, Config<T>},
}
}

fn main() {}