Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Change output location of smallbank_workload protobuf generation
Browse files Browse the repository at this point in the history
Signed-off-by: Bridger Herman <[email protected]>
  • Loading branch information
Bridger Herman committed Aug 22, 2018
1 parent c3c0b74 commit 062b5a4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
/perf/sawtooth_perf/target/
/perf/sawtooth_workload/Cargo.lock
/perf/sawtooth_workload/target/
/perf/smallbank_workload/src/smallbank.rs
/perf/smallbank_workload/Cargo.lock
/perf/smallbank_workload/target/
/perf/smallbank_workload/bin/
Expand Down
36 changes: 34 additions & 2 deletions perf/smallbank_workload/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,53 @@ extern crate protoc_rust;

use protoc_rust::Customize;

use std::env;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::Path;

fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("protos");
fs::create_dir_all(&dest_path).unwrap();

let proto_src_files = glob_simple("../../families/smallbank/protos/*.proto");
println!("{:?}", proto_src_files);

protoc_rust::run(protoc_rust::Args {
out_dir: "./src",
out_dir: &dest_path.to_str().unwrap(),
input: &proto_src_files
.iter()
.map(|a| a.as_ref())
.map(|proto_file| proto_file.as_ref())
.collect::<Vec<&str>>(),
includes: &["../../families/smallbank/protos"],
customize: Customize {
..Default::default()
},
}).expect("Error generating rust files from smallbank protos");

// Create mod.rs accordingly
let mod_file_content = proto_src_files
.iter()
.map(|proto_file| {
let proto_path = Path::new(proto_file);
format!(
"pub mod {};",
proto_path
.file_stem()
.expect("Unable to extract stem")
.to_str()
.expect("Unable to extract filename")
)
})
.collect::<Vec<_>>()
.join("\n");

let mut mod_file = File::create(dest_path.join("mod.rs")).unwrap();
mod_file
.write_all(mod_file_content.as_bytes())
.expect("Unable to write mod file");
}

fn glob_simple(pattern: &str) -> Vec<String> {
Expand Down
2 changes: 1 addition & 1 deletion perf/smallbank_workload/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern crate sawtooth_perf;
extern crate sawtooth_sdk;

mod playlist;
mod smallbank;
mod protos;
mod smallbank_transformer;

use std::error::Error;
Expand Down
6 changes: 3 additions & 3 deletions perf/smallbank_workload/src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ use self::yaml_rust::Yaml;
use self::yaml_rust::YamlEmitter;
use self::yaml_rust::YamlLoader;

use smallbank;
use smallbank::SmallbankTransactionPayload;
use smallbank::SmallbankTransactionPayload_PayloadType as SBPayloadType;
use protos::smallbank;
use protos::smallbank::SmallbankTransactionPayload;
use protos::smallbank::SmallbankTransactionPayload_PayloadType as SBPayloadType;

use protobuf;
use protobuf::Message;
Expand Down
19 changes: 19 additions & 0 deletions perf/smallbank_workload/src/protos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2018 Bitwise IO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -----------------------------------------------------------------------------
*/

// Includes the autogenerated protobuf messages
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
2 changes: 1 addition & 1 deletion perf/smallbank_workload/src/smallbank_transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sawtooth_sdk::signing;

use playlist::bytes_to_hex_str;
use playlist::make_addresses;
use smallbank::{SmallbankTransactionPayload, SmallbankTransactionPayload_PayloadType};
use protos::smallbank::{SmallbankTransactionPayload, SmallbankTransactionPayload_PayloadType};

/// Transforms SmallbankTransactionPayloads into Sawtooth Transactions.
pub struct SBPayloadTransformer<'a> {
Expand Down

0 comments on commit 062b5a4

Please sign in to comment.