Skip to content

Commit

Permalink
use build script instead of git submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomoto911 committed Nov 28, 2024
1 parent abb9f6b commit 49d4a6b
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 18 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/grevm-ethereum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize ethereum tests
run: |
git submodule update --init tests/ethereum/tests
# install rust tools
- name: Set up Rust
uses: actions-rs/toolchain@v1
Expand All @@ -28,4 +24,4 @@ jobs:
override: true

- name: Run tests
run: cargo test --test ethereum
run: cargo test --features update-submodule-ethereum-tests --test ethereum
6 changes: 1 addition & 5 deletions .github/workflows/grevm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize mainnet test_data
run: |
git submodule update --init test_data
# install rust tools
- name: Set up Rust
uses: actions-rs/toolchain@v1
Expand All @@ -28,4 +24,4 @@ jobs:
override: true

- name: Run tests
run: cargo test -- --skip ethereum
run: cargo test --features update-submodule-test-data -- --skip ethereum
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ rustc-ice-*

# Rust lock file
Cargo.lock

# test submodules
test_data
tests/ethereum/tests
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "grevm"
version = "0.1.0"
edition = "2021"
description = "Create Parallel EVM"
build = "build.rs"

[dependencies]
revm = { package = "revm", git = "https://github.com/galxe/revm", rev = "20b5883" }
Expand Down Expand Up @@ -59,3 +60,8 @@ harness = false
codegen-units = 1
panic = "abort"
lto = "fat"

[features]
update-test-submodule = ["update-submodule-test-data", "update-submodule-ethereum-tests"]
update-submodule-test-data = []
update-submodule-ethereum-tests = []
88 changes: 88 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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", 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);
}
1 change: 0 additions & 1 deletion test_data
Submodule test_data deleted from 4264bd
1 change: 0 additions & 1 deletion tests/ethereum/tests
Submodule tests deleted from 4f65a0

0 comments on commit 49d4a6b

Please sign in to comment.