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: lock git dependencies folder when resolving workspace #7327

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tooling/nargo_toml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ toml.workspace = true
url.workspace = true
noirc_driver.workspace = true
semver = "1.0.20"
fs2 = "0.4.3"

[dev-dependencies]
tempfile.workspace = true
Expand Down
19 changes: 18 additions & 1 deletion tooling/nargo_toml/src/git.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::path::PathBuf;
use fs2::FileExt;
use std::{
fs::{File, OpenOptions},
path::PathBuf,
};

/// Creates a unique folder name for a GitHub repo
/// by using its URL and tag
Expand All @@ -23,6 +27,19 @@ fn git_dep_location(base: &url::Url, tag: &str) -> PathBuf {
nargo_crates().join(folder_name)
}

pub(crate) fn lock_git_deps() -> std::io::Result<File> {
std::fs::create_dir_all(nargo_crates())?;
let file_path = nargo_crates().join(".package-cache");
let file = OpenOptions::new().create(true).truncate(true).write(true).open(file_path)?;
if file.try_lock_exclusive().is_err() {
eprintln!("Waiting for lock on git dependencies cache...");
}

file.lock_exclusive()?;

Ok(file)
}

/// XXX: I'd prefer to use a GitHub library however, there
/// does not seem to be an easy way to download a repo at a specific
/// tag
Expand Down
6 changes: 5 additions & 1 deletion tooling/nargo_toml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{

use errors::SemverError;
use fm::{NormalizePath, FILE_EXTENSION};
use fs2::FileExt;
use nargo::{
package::{Dependency, Package, PackageType},
workspace::Workspace,
Expand All @@ -23,7 +24,7 @@ mod git;
mod semver;

pub use errors::ManifestError;
use git::clone_git_repo;
use git::{clone_git_repo, lock_git_deps};

/// Searches for a `Nargo.toml` file in the current directory and all parent directories.
/// For example, if the current directory is `/workspace/package/src`, then this function
Expand Down Expand Up @@ -518,7 +519,10 @@ pub fn resolve_workspace_from_toml(
current_compiler_version: Option<String>,
) -> Result<Workspace, ManifestError> {
let nargo_toml = read_toml(toml_path)?;
let lock = lock_git_deps().expect("Failed to lock git dependencies cache");
aakoshh marked this conversation as resolved.
Show resolved Hide resolved
let workspace = toml_to_workspace(nargo_toml, package_selection)?;
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
lock.unlock().expect("Failed to unlock git dependencies cache");
aakoshh marked this conversation as resolved.
Show resolved Hide resolved

if let Some(current_compiler_version) = current_compiler_version {
semver::semver_check_workspace(&workspace, current_compiler_version)?;
}
Expand Down
Loading