Derive IPC interface only when ipc feature is on (#2463)
* derive -> ipc * accident repair * conditional ipc deriving * fix test
This commit is contained in:
		
							parent
							
								
									eae2466107
								
							
						
					
					
						commit
						7526b1d44b
					
				@ -18,7 +18,7 @@ extern crate ethcore_ipc_codegen;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
	ethcore_ipc_codegen::derive_binary("src/types/mod.rs.in").unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc("src/client/traits.rs").unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc("src/snapshot/snapshot_service_trait.rs").unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc("src/client/chain_notify.rs").unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc_cond("src/client/traits.rs", cfg!(feature="ipc")).unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc_cond("src/snapshot/snapshot_service_trait.rs", cfg!(feature="ipc")).unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc_cond("src/client/chain_notify.rs", cfg!(feature="ipc")).unwrap();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -30,13 +30,20 @@ pub use self::test_client::{TestBlockChainClient, EachBlockWith};
 | 
			
		||||
pub use types::trace_filter::Filter as TraceFilter;
 | 
			
		||||
pub use executive::{Executed, Executive, TransactOptions};
 | 
			
		||||
pub use env_info::{LastHashes, EnvInfo};
 | 
			
		||||
pub use self::chain_notify::{ChainNotify, ChainNotifyClient};
 | 
			
		||||
pub use self::chain_notify::ChainNotify;
 | 
			
		||||
 | 
			
		||||
pub use types::call_analytics::CallAnalytics;
 | 
			
		||||
pub use block_import_error::BlockImportError;
 | 
			
		||||
pub use transaction_import::TransactionImportResult;
 | 
			
		||||
pub use transaction_import::TransactionImportError;
 | 
			
		||||
pub use self::traits::{BlockChainClient, MiningBlockChainClient, RemoteClient};
 | 
			
		||||
pub use self::traits::{BlockChainClient, MiningBlockChainClient};
 | 
			
		||||
 | 
			
		||||
/// IPC interfaces
 | 
			
		||||
#[cfg(feature="ipc")]
 | 
			
		||||
pub mod remote {
 | 
			
		||||
	pub use super::traits::RemoteClient;
 | 
			
		||||
	pub use super::chain_notify::ChainNotifyClient;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod traits {
 | 
			
		||||
	#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
 | 
			
		||||
 | 
			
		||||
@ -51,7 +51,7 @@ use rand::{Rng, OsRng};
 | 
			
		||||
pub use self::error::Error;
 | 
			
		||||
 | 
			
		||||
pub use self::service::{Service, DatabaseRestore};
 | 
			
		||||
pub use self::traits::{SnapshotService, RemoteSnapshotService};
 | 
			
		||||
pub use self::traits::SnapshotService;
 | 
			
		||||
pub use self::watcher::Watcher;
 | 
			
		||||
pub use types::snapshot_manifest::ManifestData;
 | 
			
		||||
pub use types::restoration_status::RestorationStatus;
 | 
			
		||||
@ -67,6 +67,12 @@ mod watcher;
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod tests;
 | 
			
		||||
 | 
			
		||||
/// IPC interfaces
 | 
			
		||||
#[cfg(feature="ipc")]
 | 
			
		||||
pub mod remote {
 | 
			
		||||
	pub use super::traits::RemoteSnapshotService;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod traits {
 | 
			
		||||
	#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
 | 
			
		||||
	include!(concat!(env!("OUT_DIR"), "/snapshot_service_trait.rs"));
 | 
			
		||||
 | 
			
		||||
@ -16,4 +16,5 @@
 | 
			
		||||
 | 
			
		||||
pub mod helpers;
 | 
			
		||||
mod client;
 | 
			
		||||
#[cfg(feature="ipc")]
 | 
			
		||||
mod rpc;
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,8 @@
 | 
			
		||||
use nanoipc;
 | 
			
		||||
use std::sync::Arc;
 | 
			
		||||
use std::sync::atomic::{Ordering, AtomicBool};
 | 
			
		||||
use client::{Client, BlockChainClient, ClientConfig, RemoteClient, BlockID};
 | 
			
		||||
use client::{Client, BlockChainClient, ClientConfig, BlockID};
 | 
			
		||||
use client::remote::RemoteClient;
 | 
			
		||||
use tests::helpers::*;
 | 
			
		||||
use devtools::*;
 | 
			
		||||
use miner::Miner;
 | 
			
		||||
 | 
			
		||||
@ -56,7 +56,7 @@ pub fn expand(src: &std::path::Path, dst: &std::path::Path) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "with-syntex")]
 | 
			
		||||
pub fn register(reg: &mut syntex::Registry) {
 | 
			
		||||
pub fn register_cleaner(reg: &mut syntex::Registry) {
 | 
			
		||||
	use syntax::{ast, fold};
 | 
			
		||||
 | 
			
		||||
	#[cfg(feature = "with-syntex")]
 | 
			
		||||
@ -66,6 +66,7 @@ pub fn register(reg: &mut syntex::Registry) {
 | 
			
		||||
			fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
 | 
			
		||||
				match attr.node.value.node {
 | 
			
		||||
					ast::MetaItemKind::List(ref n, _) if n == &"ipc" => { return None; }
 | 
			
		||||
					ast::MetaItemKind::Word(ref n) if n == &"ipc" => { return None; }
 | 
			
		||||
					_ => {}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@ -80,13 +81,18 @@ pub fn register(reg: &mut syntex::Registry) {
 | 
			
		||||
		fold::Folder::fold_crate(&mut StripAttributeFolder, krate)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	reg.add_post_expansion_pass(strip_attributes);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "with-syntex")]
 | 
			
		||||
pub fn register(reg: &mut syntex::Registry) {
 | 
			
		||||
	reg.add_attr("feature(custom_derive)");
 | 
			
		||||
	reg.add_attr("feature(custom_attribute)");
 | 
			
		||||
 | 
			
		||||
	reg.add_decorator("ipc", codegen::expand_ipc_implementation);
 | 
			
		||||
	reg.add_decorator("derive_Binary", serialization::expand_serialization_implementation);
 | 
			
		||||
 | 
			
		||||
	reg.add_post_expansion_pass(strip_attributes);
 | 
			
		||||
	register_cleaner(reg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(not(feature = "with-syntex"))]
 | 
			
		||||
@ -104,7 +110,34 @@ pub fn register(reg: &mut rustc_plugin::Registry) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
pub enum Error { InvalidFileName, ExpandFailure }
 | 
			
		||||
pub enum Error { InvalidFileName, ExpandFailure, Io(std::io::Error) }
 | 
			
		||||
 | 
			
		||||
impl std::convert::From<std::io::Error> for Error {
 | 
			
		||||
	fn from(err: std::io::Error) -> Self {
 | 
			
		||||
		Error::Io(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn derive_ipc_cond(src_path: &str, has_feature: bool) -> Result<(), Error> {
 | 
			
		||||
	if has_feature { derive_ipc(src_path) }
 | 
			
		||||
	else { cleanup_ipc(src_path) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn cleanup_ipc(src_path: &str) -> Result<(), Error> {
 | 
			
		||||
	use std::env;
 | 
			
		||||
	use std::path::{Path, PathBuf};
 | 
			
		||||
 | 
			
		||||
	let out_dir = env::var_os("OUT_DIR").unwrap();
 | 
			
		||||
	let file_name = try!(PathBuf::from(src_path).file_name().ok_or(Error::InvalidFileName).map(|val| val.to_str().unwrap().to_owned()));
 | 
			
		||||
	let mut registry = syntex::Registry::new();
 | 
			
		||||
	register_cleaner(&mut registry);
 | 
			
		||||
	if let Err(_) = registry.expand("", &Path::new(src_path), &Path::new(&out_dir).join(&file_name))
 | 
			
		||||
	{
 | 
			
		||||
		// will be reported by compiler
 | 
			
		||||
		return Err(Error::ExpandFailure)
 | 
			
		||||
	}
 | 
			
		||||
	Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn derive_ipc(src_path: &str) -> Result<(), Error> {
 | 
			
		||||
	use std::env;
 | 
			
		||||
@ -113,11 +146,11 @@ pub fn derive_ipc(src_path: &str) -> Result<(), Error> {
 | 
			
		||||
	let out_dir = env::var_os("OUT_DIR").unwrap();
 | 
			
		||||
	let file_name = try!(PathBuf::from(src_path).file_name().ok_or(Error::InvalidFileName).map(|val| val.to_str().unwrap().to_owned()));
 | 
			
		||||
 | 
			
		||||
	let final_path = Path::new(&out_dir).join(&file_name);
 | 
			
		||||
 | 
			
		||||
	let mut intermediate_file_name = file_name.clone();
 | 
			
		||||
	intermediate_file_name.push_str(".rpc.in");
 | 
			
		||||
 | 
			
		||||
	let intermediate_path = Path::new(&out_dir).join(&intermediate_file_name);
 | 
			
		||||
	let final_path = Path::new(&out_dir).join(&file_name);
 | 
			
		||||
 | 
			
		||||
	{
 | 
			
		||||
		let mut registry = syntex::Registry::new();
 | 
			
		||||
 | 
			
		||||
@ -68,8 +68,9 @@ pub type SyncModules = (Arc<SyncProvider>, Arc<ManageNetwork>, Arc<ChainNotify>)
 | 
			
		||||
 | 
			
		||||
#[cfg(feature="ipc")]
 | 
			
		||||
mod ipc_deps {
 | 
			
		||||
	pub use ethsync::{SyncClient, NetworkManagerClient, ServiceConfiguration};
 | 
			
		||||
	pub use ethcore::client::ChainNotifyClient;
 | 
			
		||||
	pub use ethsync::remote::{SyncClient, NetworkManagerClient};
 | 
			
		||||
	pub use ethsync::ServiceConfiguration;
 | 
			
		||||
	pub use ethcore::client::remote::ChainNotifyClient;
 | 
			
		||||
	pub use hypervisor::{SYNC_MODULE_ID, BootArgs, HYPERVISOR_IPC_URL};
 | 
			
		||||
	pub use nanoipc::{GuardedSocket, NanoSocket, generic_client, fast_client};
 | 
			
		||||
	pub use ipc::IpcSocket;
 | 
			
		||||
 | 
			
		||||
@ -19,8 +19,9 @@
 | 
			
		||||
use std::sync::Arc;
 | 
			
		||||
use std::sync::atomic::AtomicBool;
 | 
			
		||||
use hypervisor::{SYNC_MODULE_ID, HYPERVISOR_IPC_URL, ControlService};
 | 
			
		||||
use ethcore::client::{RemoteClient, ChainNotify};
 | 
			
		||||
use ethcore::snapshot::{RemoteSnapshotService};
 | 
			
		||||
use ethcore::client::ChainNotify;
 | 
			
		||||
use ethcore::client::remote::RemoteClient;
 | 
			
		||||
use ethcore::snapshot::remote::RemoteSnapshotService;
 | 
			
		||||
use ethsync::{SyncProvider, EthSync, ManageNetwork, ServiceConfiguration};
 | 
			
		||||
use modules::service_urls;
 | 
			
		||||
use boot;
 | 
			
		||||
 | 
			
		||||
@ -17,5 +17,5 @@
 | 
			
		||||
extern crate ethcore_ipc_codegen;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc("src/api.rs").unwrap();
 | 
			
		||||
	ethcore_ipc_codegen::derive_ipc_cond("src/api.rs", cfg!(feature="ipc")).unwrap();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -63,3 +63,9 @@ pub use api::{EthSync, SyncProvider, SyncClient, NetworkManagerClient, ManageNet
 | 
			
		||||
	ServiceConfiguration, NetworkConfiguration};
 | 
			
		||||
pub use chain::{SyncStatus, SyncState};
 | 
			
		||||
pub use network::{is_valid_node_url, NonReservedPeerMode, NetworkError};
 | 
			
		||||
 | 
			
		||||
/// IPC interfaces
 | 
			
		||||
#[cfg(feature="ipc")]
 | 
			
		||||
pub mod remote {
 | 
			
		||||
	pub use api::{SyncClient, NetworkManagerClient};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user