Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

sp-npos-elections should not depend on itself #6444

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion primitives/npos-elections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ sp-arithmetic = { version = "2.0.0-rc3", default-features = false, path = "../ar
[dev-dependencies]
substrate-test-utils = { version = "2.0.0-rc3", path = "../../test-utils" }
rand = "0.7.3"
sp-npos-elections = { version = "2.0.0-rc3", path = "." }
sp-runtime = { version = "2.0.0-rc3", path = "../../primitives/runtime" }

[features]
Expand Down
4 changes: 2 additions & 2 deletions primitives/npos-elections/compact/src/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//! Code generation for the ratio assignment type.

use crate::field_name_for;
use proc_macro2::{TokenStream as TokenStream2};
use syn::{GenericArgument};
use proc_macro2::TokenStream as TokenStream2;
use syn::GenericArgument;
use quote::quote;

fn from_impl(count: usize) -> TokenStream2 {
Expand Down
22 changes: 12 additions & 10 deletions primitives/npos-elections/compact/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,19 @@ fn struct_def(
}

fn imports() -> Result<TokenStream2> {
let sp_phragmen_imports = match crate_name("sp-npos-elections") {
Ok(sp_npos_elections) => {
let ident = syn::Ident::new(&sp_npos_elections, Span::call_site());
quote!( extern crate #ident as _phragmen; )
if std::env::var("CARGO_PKG_NAME").unwrap() == "sp-npos-elections" {
Ok(quote! {
use crate as _phragmen;
})
} else {
match crate_name("sp-npos-elections") {
Ok(sp_npos_elections) => {
let ident = syn::Ident::new(&sp_npos_elections, Span::call_site());
Ok(quote!( extern crate #ident as _phragmen; ))
},
Err(e) => Err(syn::Error::new(Span::call_site(), &e)),
}
Err(e) => return Err(syn::Error::new(Span::call_site(), &e)),
};

Ok(quote!(
#sp_phragmen_imports
))
}
}

struct CompactSolutionDef {
Expand Down
10 changes: 5 additions & 5 deletions primitives/npos-elections/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

//! Tests for npos-elections.

#![cfg(test)]

use crate::mock::*;
use crate::{
seq_phragmen, balance_solution, build_support_map, is_score_better, helpers::*,
Expand Down Expand Up @@ -772,10 +770,12 @@ fn score_comparison_large_value() {

mod compact {
use codec::{Decode, Encode};
use crate::{generate_compact_solution_type, VoteWeight};
use super::{AccountId};
use super::AccountId;
// these need to come from the same dev-dependency `sp-npos-elections`, not from the crate.
use sp_npos_elections::{Assignment, StakedAssignment, Error as PhragmenError, ExtendedBalance};
use crate::{
generate_compact_solution_type, VoteWeight, Assignment, StakedAssignment,
Error as PhragmenError, ExtendedBalance,
};
use sp_std::{convert::{TryInto, TryFrom}, fmt::Debug};
use sp_arithmetic::Percent;

Expand Down