Skip to content

Commit e03654d

Browse files
committed
use build script instead of git submodule
1 parent abb9f6b commit e03654d

File tree

8 files changed

+100
-18
lines changed

8 files changed

+100
-18
lines changed

.github/workflows/grevm-ethereum.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
1818

19-
- name: Initialize ethereum tests
20-
run: |
21-
git submodule update --init tests/ethereum/tests
22-
2319
# install rust tools
2420
- name: Set up Rust
2521
uses: actions-rs/toolchain@v1
@@ -28,4 +24,4 @@ jobs:
2824
override: true
2925

3026
- name: Run tests
31-
run: cargo test --test ethereum
27+
run: cargo test --features update-submodule-ethereum-tests --test ethereum

.github/workflows/grevm-test.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
1818

19-
- name: Initialize mainnet test_data
20-
run: |
21-
git submodule update --init test_data
22-
2319
# install rust tools
2420
- name: Set up Rust
2521
uses: actions-rs/toolchain@v1
@@ -28,4 +24,4 @@ jobs:
2824
override: true
2925

3026
- name: Run tests
31-
run: cargo test -- --skip ethereum
27+
run: cargo test --features update-submodule-test-data -- --skip ethereum

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ rustc-ice-*
3535

3636
# Rust lock file
3737
Cargo.lock
38+
39+
# test submodules
40+
test_data
41+
tests/ethereum/tests

.gitmodules

-6
This file was deleted.

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "grevm"
33
version = "0.1.0"
44
edition = "2021"
55
description = "Create Parallel EVM"
6+
build = "build.rs"
67

78
[dependencies]
89
revm = { package = "revm", git = "https://github.com/galxe/revm", rev = "20b5883" }
@@ -59,3 +60,8 @@ harness = false
5960
codegen-units = 1
6061
panic = "abort"
6162
lto = "fat"
63+
64+
[features]
65+
update-test-submodule = ["update-submodule-test-data", "update-submodule-ethereum-tests"]
66+
update-submodule-test-data = []
67+
update-submodule-ethereum-tests = []

build.rs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//! This crate contains the build script for the grevm project.
2+
3+
use std::{path::Path, process::Command};
4+
5+
struct TestSubmodule {
6+
path: &'static str,
7+
url: &'static str,
8+
branch: &'static str,
9+
commit: Option<&'static str>,
10+
}
11+
12+
fn git_clone(submodule: &TestSubmodule) -> Command {
13+
let mut command = Command::new("git");
14+
command.args(&["clone", "-b", submodule.branch, submodule.url, submodule.path]);
15+
command
16+
}
17+
18+
fn git_fetch(submodule: &TestSubmodule) -> Command {
19+
let mut command = Command::new("git");
20+
command.args(&["-C", submodule.path, "fetch", "origin", submodule.branch]);
21+
command
22+
}
23+
24+
fn git_checkout(submodule: &TestSubmodule) -> Command {
25+
let mut command = Command::new("git");
26+
if let Some(commit) = submodule.commit {
27+
command.args(&["-C", submodule.path, "checkout", commit]);
28+
} else {
29+
command.args(&["-C", submodule.path, "checkout", &format!("origin/{}", submodule.branch)]);
30+
}
31+
command
32+
}
33+
34+
fn update_submodule(submodule: &TestSubmodule) {
35+
let test_data = Path::new(submodule.path);
36+
if !test_data.exists() && !git_clone(submodule).status().unwrap().success() {
37+
panic!("Failed to clone submodule {}", submodule.path);
38+
}
39+
40+
if submodule.commit.is_some() {
41+
if git_checkout(submodule).status().unwrap().success() {
42+
return;
43+
}
44+
}
45+
46+
if !git_fetch(submodule).status().unwrap().success() {
47+
panic!("Failed to fetch branch {} in submodule {}", submodule.branch, submodule.path);
48+
}
49+
50+
if !git_checkout(submodule).status().unwrap().success() {
51+
panic!("Failed to checkout {} in submodule {}", submodule.branch, submodule.path);
52+
}
53+
}
54+
55+
fn update_submodules(submodules: &[TestSubmodule]) {
56+
std::thread::scope(|s| {
57+
for submodule in submodules {
58+
s.spawn(|| {
59+
println!("Updating submodule {}", submodule.path);
60+
update_submodule(submodule);
61+
println!("Updating submodule {} done", submodule.path);
62+
});
63+
}
64+
});
65+
}
66+
67+
fn main() {
68+
#[allow(unused_mut)]
69+
let mut submodules = vec![];
70+
71+
#[cfg(feature = "update-submodule-test-data")]
72+
submodules.push(TestSubmodule {
73+
path: "test_data",
74+
url: "https://github.com/Galxe/grevm-test-data",
75+
branch: "main",
76+
commit: Some("4264bdf"),
77+
});
78+
79+
#[cfg(feature = "update-submodule-ethereum-tests")]
80+
submodules.push(TestSubmodule {
81+
path: "tests/ethereum/tests",
82+
url: "https://github.com/ethereum/tests",
83+
branch: "develop",
84+
commit: Some("4f65a0a"),
85+
});
86+
87+
update_submodules(&submodules);
88+
}

test_data

-1
This file was deleted.

tests/ethereum/tests

-1
This file was deleted.

0 commit comments

Comments
 (0)