Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(blueprint-build-utils): build utils only run when necessary #544

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions blueprint-build-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ use std::env;
use std::path::PathBuf;
use std::process::Command;

/// Build the Smart contracts at the specified directories, automatically rerunning if changes are
/// detected in this crate's Smart Contracts (`./contracts/lib` or `./contracts/src`).
/// Build the Smart contracts at the specified directories.
///
/// This function will automatically rerun the build if changes are detected in the `src`
/// directory within any of the directories specified. Due to this, it is recommended to
/// ensure that you only pass in directories that contain the `src` directory and won't be
/// modified by anything else in the build script (otherwise, the build will always rerun).
///
/// # Panics
/// - If the Cargo Manifest directory is not found.
/// - If the `forge` executable is not found.
pub fn build_contracts(contract_dirs: Vec<&str>) {
println!("cargo::rerun-if-changed=contracts/lib/*");
println!("cargo::rerun-if-changed=contracts/src/*");
for dir in contract_dirs.clone() {
let dir = format!("{}/src", dir);
println!("cargo::rerun-if-changed={dir}");
}

// Get the project root directory
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
Expand All @@ -28,8 +34,6 @@ pub fn build_contracts(contract_dirs: Vec<&str>) {
});

if full_path.exists() {
println!("cargo:rerun-if-changed={}", full_path.display());

let status = Command::new(&forge_executable)
.current_dir(&full_path)
.arg("build")
Expand Down Expand Up @@ -64,14 +68,21 @@ pub fn soldeer_update() {
let forge_executable = find_forge_executable();

println!("Populating dependencies directory");
let status = Command::new(&forge_executable)
.current_dir(&root)
.args(["soldeer", "install"])
.status()
.expect("Failed to execute 'forge soldeer update'");

assert!(status.success(), "'forge soldeer install' failed");

let status = Command::new(&forge_executable)
.current_dir(&root)
.args(["soldeer", "update", "-d"])
.status()
.expect("Failed to execute 'forge soldeer update'");

assert!(status.success(), "'forge soldeer update' failed",);
assert!(status.success(), "'forge soldeer update' failed");
}

/// Returns a string with the path to the `forge` executable.
Expand Down
Loading