Merge pull request #1795 from ethcore/ipc-codegen-dry

DRYing build scripts
This commit is contained in:
Nikolay Volf 2016-08-02 15:25:54 +03:00 committed by GitHub
commit 93b4b15c15
17 changed files with 76 additions and 171 deletions

3
Cargo.lock generated
View File

@ -279,7 +279,6 @@ dependencies = [
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -346,7 +345,6 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"nanomsg 0.5.1 (git+https://github.com/ethcore/nanomsg.rs.git)",
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -521,7 +519,6 @@ dependencies = [
"parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -8,7 +8,6 @@ authors = ["Ethcore <admin@ethcore.io>"]
build = "build.rs"
[build-dependencies]
syntex = "*"
"ethcore-ipc-codegen" = { path = "../ipc/codegen" }
[dependencies]
@ -35,7 +34,6 @@ ethcore-ipc = { path = "../ipc/rpc" }
ethstore = { path = "../ethstore" }
ethcore-ipc-nano = { path = "../ipc/nano" }
[dependencies.hyper]
git = "https://github.com/ethcore/hyper"
default-features = false

View File

@ -14,48 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
extern crate syntex;
extern crate ethcore_ipc_codegen as codegen;
use std::env;
use std::path::Path;
extern crate ethcore_ipc_codegen;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
// serialization pass
{
let src = Path::new("src/types/mod.rs.in");
let dst = Path::new(&out_dir).join("types.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
// blockchain client interface
{
let src = Path::new("src/client/traits.rs");
let intermediate = Path::new(&out_dir).join("traits.intermediate.rs.in");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &intermediate).unwrap();
let dst = Path::new(&out_dir).join("traits.ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &intermediate, &dst).unwrap();
}
// chain notify interface
{
let src = Path::new("src/client/chain_notify.rs");
let intermediate = Path::new(&out_dir).join("chain_notify.intermediate.rs.in");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &intermediate).unwrap();
let dst = Path::new(&out_dir).join("chain_notify.ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &intermediate, &dst).unwrap();
}
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/client/chain_notify.rs").unwrap();
}

View File

@ -40,13 +40,13 @@ pub use self::traits::{BlockChainClient, MiningBlockChainClient, RemoteClient};
mod traits {
#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/traits.ipc.rs"));
include!(concat!(env!("OUT_DIR"), "/traits.rs"));
}
pub mod chain_notify {
//! Chain notify interface
#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/chain_notify.ipc.rs"));
include!(concat!(env!("OUT_DIR"), "/chain_notify.rs"));
}

View File

@ -17,4 +17,4 @@
//! Types used in the public api
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/types.rs"));
include!(concat!(env!("OUT_DIR"), "/mod.rs.in"));

View File

@ -95,3 +95,58 @@ pub fn register(reg: &mut rustc_plugin::Registry) {
reg.register_attribute("ipc".to_owned(), AttributeType::Normal);
}
#[derive(Debug)]
pub enum Error { InvalidFileName, ExpandFailure }
pub fn derive_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 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();
register(&mut registry);
if let Err(_) = registry.expand("", &Path::new(src_path), &intermediate_path) {
// will be reported by compiler
return Err(Error::ExpandFailure)
}
}
{
let mut registry = syntex::Registry::new();
register(&mut registry);
if let Err(_) = registry.expand("", &intermediate_path, &final_path) {
// will be reported by compiler
return Err(Error::ExpandFailure)
}
}
Ok(())
}
pub fn derive_binary(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 final_path = Path::new(&out_dir).join(&file_name);
let mut registry = syntex::Registry::new();
register(&mut registry);
if let Err(_) = registry.expand("", &Path::new(src_path), &final_path) {
// will be reported by compiler
return Err(Error::ExpandFailure)
}
Ok(())
}

View File

@ -15,5 +15,4 @@ semver = "0.2"
log = "0.3"
[build-dependencies]
syntex = "*"
ethcore-ipc-codegen = { path = "../codegen" }

View File

@ -14,30 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
extern crate syntex;
extern crate ethcore_ipc_codegen as codegen;
use std::env;
use std::path::Path;
extern crate ethcore_ipc_codegen;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
// ipc pass
{
let src = Path::new("src/service.rs.in");
let dst = Path::new(&out_dir).join("hypervisor_service_ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
// serialization pass
{
let src = Path::new(&out_dir).join("hypervisor_service_ipc.rs");
let dst = Path::new(&out_dir).join("hypervisor_service_cg.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
ethcore_ipc_codegen::derive_ipc("src/service.rs.in").unwrap();
}

View File

@ -17,4 +17,4 @@
//! Parity interprocess hypervisor IPC service
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/hypervisor_service_cg.rs"));
include!(concat!(env!("OUT_DIR"), "/service.rs.in"));

View File

@ -16,4 +16,4 @@
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/binary.rs"));
include!(concat!(env!("OUT_DIR"), "/binary.rs.in"));

View File

@ -14,76 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
extern crate syntex;
extern crate ethcore_ipc_codegen as codegen;
use std::env;
use std::path::Path;
use std::process::exit;
pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
// rpc pass
if {
let src = Path::new("nested.rs.in");
let dst = Path::new(&out_dir).join("nested_ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).is_ok()
}
// serialization pass
{
let src = Path::new(&out_dir).join("nested_ipc.rs");
let dst = Path::new(&out_dir).join("nested_cg.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
// rpc pass
if {
let src = Path::new("service.rs.in");
let dst = Path::new(&out_dir).join("service_ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).is_ok()
}
// serialization pass
{
let src = Path::new(&out_dir).join("service_ipc.rs");
let dst = Path::new(&out_dir).join("service_cg.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
// rpc pass
if {
let src = Path::new("with_attrs.rs.in");
let dst = Path::new(&out_dir).join("with_attrs_ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).is_ok()
}
// serialization pass
{
let src = Path::new(&out_dir).join("with_attrs_ipc.rs");
let dst = Path::new(&out_dir).join("with_attrs_cg.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
// rpc pass
{
let src = Path::new("binary.rs.in");
let dst = Path::new(&out_dir).join("binary.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
if let Err(err_msg) = registry.expand("", &src, &dst) {
println!("error: {}", err_msg);
exit(1);
}
}
codegen::derive_ipc("nested.rs.in").unwrap();
codegen::derive_ipc("service.rs.in").unwrap();
codegen::derive_ipc("with_attrs.rs.in").unwrap();
codegen::derive_binary("binary.rs.in").unwrap();
}

View File

@ -15,4 +15,4 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/nested_cg.rs"));
include!(concat!(env!("OUT_DIR"), "/nested.rs.in"));

View File

@ -15,4 +15,4 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/service_cg.rs"));
include!(concat!(env!("OUT_DIR"), "/service.rs.in"));

View File

@ -15,4 +15,4 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/with_attrs_cg.rs"));
include!(concat!(env!("OUT_DIR"), "/with_attrs.rs.in"));

View File

@ -9,7 +9,6 @@ build = "build.rs"
[lib]
[build-dependencies]
syntex = "0.33"
ethcore-ipc-codegen = { path = "../ipc/codegen" }
[dependencies]

View File

@ -14,26 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
extern crate syntex;
extern crate ethcore_ipc_codegen as codegen;
use std::env;
use std::path::Path;
extern crate ethcore_ipc_codegen;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
// sync interface
{
let src = Path::new("src/api.rs");
let intermediate = Path::new(&out_dir).join("api.intermediate.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &intermediate).unwrap();
let dst = Path::new(&out_dir).join("api.ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &intermediate, &dst).unwrap();
}
ethcore_ipc_codegen::derive_ipc("src/api.rs").unwrap();
}

View File

@ -84,7 +84,7 @@ mod tests;
mod api {
#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/api.ipc.rs"));
include!(concat!(env!("OUT_DIR"), "/api.rs"));
}
pub use api::{EthSync, SyncProvider, SyncClient, NetworkManagerClient, ManageNetwork, SyncConfig,