-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
88 lines (74 loc) · 2.58 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! This crate contains the build script for the grevm project.
use std::{path::Path, process::Command};
struct TestSubmodule {
path: &'static str,
url: &'static str,
branch: &'static str,
commit: Option<&'static str>,
}
fn git_clone(submodule: &TestSubmodule) -> Command {
let mut command = Command::new("git");
command.args(&["clone", "-b", submodule.branch, submodule.url, submodule.path]);
command
}
fn git_fetch(submodule: &TestSubmodule) -> Command {
let mut command = Command::new("git");
command.args(&["-C", submodule.path, "fetch", "origin", submodule.branch]);
command
}
fn git_checkout(submodule: &TestSubmodule) -> Command {
let mut command = Command::new("git");
if let Some(commit) = submodule.commit {
command.args(&["-C", submodule.path, "checkout", commit]);
} else {
command.args(&["-C", submodule.path, "checkout", &format!("origin/{}", submodule.branch)]);
}
command
}
fn update_submodule(submodule: &TestSubmodule) {
let test_data = Path::new(submodule.path);
if !test_data.exists() && !git_clone(submodule).status().unwrap().success() {
panic!("Failed to clone submodule {}", submodule.path);
}
if submodule.commit.is_some() {
if git_checkout(submodule).status().unwrap().success() {
return;
}
}
if !git_fetch(submodule).status().unwrap().success() {
panic!("Failed to fetch branch {} in submodule {}", submodule.branch, submodule.path);
}
if !git_checkout(submodule).status().unwrap().success() {
panic!("Failed to checkout {} in submodule {}", submodule.branch, submodule.path);
}
}
fn update_submodules(submodules: &[TestSubmodule]) {
std::thread::scope(|s| {
for submodule in submodules {
s.spawn(|| {
println!("Updating submodule {}", submodule.path);
update_submodule(submodule);
println!("Updating submodule {} done", submodule.path);
});
}
});
}
fn main() {
#[allow(unused_mut)]
let mut submodules = vec![];
#[cfg(feature = "update-submodule-test-data")]
submodules.push(TestSubmodule {
path: "test_data",
url: "https://github.com/Galxe/grevm-test-data",
branch: "main",
commit: Some("4264bdf"),
});
#[cfg(feature = "update-submodule-ethereum-tests")]
submodules.push(TestSubmodule {
path: "tests/ethereum/tests",
url: "https://github.com/ethereum/tests",
branch: "develop",
commit: Some("4f65a0a"),
});
update_submodules(&submodules);
}