Skip to content

Commit

Permalink
Handle case of Rust 1.79 behavior of stringify! on crate path (#1821)
Browse files Browse the repository at this point in the history
* Handle case of Rust 1.79 behavior of `stringify!` on crate path

* Update changelog

* Simplify code following Andrew's suggestion

* Update crates/cargo-contract/src/cmd/config.rs

Co-authored-by: Andrew Jones <[email protected]>

---------

Co-authored-by: Andrew Jones <[email protected]>
  • Loading branch information
cmichi and ascjones authored Nov 19, 2024
1 parent 87d57f4 commit 1e0b4ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fix "chain configuration not found" error - [#1786](https://github.com/paritytech/cargo-contract/pull/1786)
- Fix "chain configuration not found" error (Rust 1.79) - [#1821](https://github.com/paritytech/cargo-contract/pull/1821)

## [5.0.0-alpha]

Expand Down
30 changes: 8 additions & 22 deletions crates/cargo-contract/src/cmd/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,14 @@ where

#[macro_export]
macro_rules! call_with_config_internal {
($obj:tt ,$function:tt, $config_name:expr, $($config:ty),*) => {
($obj:tt ,$function:tt, $config_name:expr, $( ($config_str:literal, $config_obj:ty) ),*) => {
match $config_name {
$(
stringify!($config) => $obj.$function::<$config>().await,
$config_str => $obj.$function::<$config_obj>().await,
)*
_ => {
let configs = vec![$(stringify!($config)),*].iter()
.map(|s| s.replace(" ", ""))
.map(|s| s.trim_start_matches("$crate::cmd::config::").to_string())
let configs = vec![$($config_str),*].iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(", ");
Err(ErrorVariant::Generic(
Expand Down Expand Up @@ -254,27 +253,14 @@ macro_rules! call_with_config {
$config_name
);

let res_nonspaced = $crate::call_with_config_internal!(
$obj,
$function,
format!("$crate::cmd::config::{}", $config_name).as_str(),
// All available chain configs need to be specified here
$crate::cmd::config::Polkadot,
$crate::cmd::config::Substrate,
$crate::cmd::config::Ecdsachain
);
if !res_nonspaced.is_err() {
return res_nonspaced
}

$crate::call_with_config_internal!(
$obj,
$function,
format!("$crate :: cmd :: config :: {}", $config_name).as_str(),
$config_name,
// All available chain configs need to be specified here
$crate::cmd::config::Polkadot,
$crate::cmd::config::Substrate,
$crate::cmd::config::Ecdsachain
("Polkadot", $crate::cmd::config::Polkadot),
("Substrate", $crate::cmd::config::Substrate),
("Ecdsachain", $crate::cmd::config::Ecdsachain)
)
}};
}

0 comments on commit 1e0b4ea

Please sign in to comment.