Skip to content

Commit

Permalink
fix(blueprint-build-utils): build utils only run when necessary (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjemmmic authored Dec 12, 2024
1 parent 2f9ac54 commit e0cf121
Showing 1 changed file with 18 additions and 7 deletions.
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

0 comments on commit e0cf121

Please sign in to comment.