Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

DRYing build scripts #1795

Merged
merged 8 commits into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 0 additions & 3 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ authors = ["Ethcore <[email protected]>"]
build = "build.rs"

[build-dependencies]
syntex = "*"
"ethcore-ipc-codegen" = { path = "../ipc/codegen" }

[dependencies]
Expand All @@ -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
Expand Down
46 changes: 4 additions & 42 deletions ethcore/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 2 additions & 2 deletions ethcore/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

2 changes: 1 addition & 1 deletion ethcore/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
55 changes: 55 additions & 0 deletions ipc/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.rpc.in? (will result in traits.rs.rpc.in for instance)


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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth nesting original error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think syntex now prints diagnostics in the stderr, so this error does not matter
like this

--- stderr
with_attrs.rs.in:32:41: 32:41 error: this file contains an un-closed delimiter
with_attrs.rs.in:32 impl IpcConfig for BadlyNamedService {}
                                                            ^
with_attrs.rs.in:26:24: 26:25 help: did you mean to close this delimiter?
with_attrs.rs.in:26 impl BadlyNamedService {

}
}

{
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(())
}
1 change: 0 additions & 1 deletion ipc/hypervisor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ semver = "0.2"
log = "0.3"

[build-dependencies]
syntex = "*"
ethcore-ipc-codegen = { path = "../codegen" }
26 changes: 2 additions & 24 deletions ipc/hypervisor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion ipc/hypervisor/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
2 changes: 1 addition & 1 deletion ipc/nano/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ mod service_tests {
}
}

impl IpcInterface<DummyService> for DummyService {
impl IpcInterface for DummyService {
fn dispatch<R>(&self, _r: &mut R) -> Vec<u8> where R: Read {
vec![]
}
Expand Down
2 changes: 1 addition & 1 deletion ipc/tests/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
73 changes: 4 additions & 69 deletions ipc/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion ipc/tests/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
2 changes: 1 addition & 1 deletion ipc/tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
2 changes: 1 addition & 1 deletion ipc/tests/with_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
1 change: 1 addition & 0 deletions scripts/targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export TARGETS="
-p ethsync \
-p ethcore-ipc \
-p ethcore-ipc-tests \
-p ethcore-ipc-nano \
-p parity"
1 change: 0 additions & 1 deletion sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ build = "build.rs"
[lib]

[build-dependencies]
syntex = "0.33"
ethcore-ipc-codegen = { path = "../ipc/codegen" }

[dependencies]
Expand Down
22 changes: 2 additions & 20 deletions sync/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down