-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
executable file
·62 lines (50 loc) · 2.05 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use serde::{Deserialize, Serialize};
use serde_yaml;
use std::fs;
use tonic_build::{compile_protos, configure};
use config::Config;
struct ExchangeMacro {
macro_name: &'static str,
file_location: &'static str,
search_pattern: &'static str,
replacement_value: &'static str,
}
const CONFIG_LOCATION: &'static str = "integrative-testing-config.yaml";
const EXCHANGE_MACROS: [ExchangeMacro; 1] = [ExchangeMacro {
macro_name: "orderbook_levels",
file_location: "orderbook/src/lib.rs",
search_pattern: "new_level!(6)",
replacement_value: "new_level!(N)",
}];
fn main() -> Result<(), Box<dyn std::error::Error>> {
let current_dir = std::env::current_dir().expect("Failed to get current directory");
let config_path = current_dir.join(&CONFIG_LOCATION);
let config_content = fs::read_to_string(config_path)?;
let config: Config = serde_yaml::from_str(&config_content)?;
assert!(config.exchanges.len() == config.orderbook.exchange_count as usize);
let exchange_count = config.orderbook.exchange_count;
for mut replacements in EXCHANGE_MACROS {
if replacements.macro_name == "orderbook_levels" {
replacements
.replacement_value
.replace("N", exchange_count.to_string().clone().as_str());
}
let file_path = current_dir.join(replacements.file_location);
// Read the file contents
let mut file_contents = fs::read_to_string(&file_path).expect("Failed to read file");
// Perform the search and replace
file_contents =
file_contents.replace(replacements.search_pattern, replacements.replacement_value);
// Write the modified contents back to the file
fs::write(&file_path, file_contents).expect("Failed to write file");
println!(
"Search and replace completed in file: {}",
file_path.display()
);
}
tonic_build::configure()
.build_server(true)
.out_dir("proto-source")
.compile(&["proto/quote/streaming.proto"], &["proto/"])?;
Ok(())
}