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

feat(nargo): Support optional directory in git dependencies #2436

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions crates/nargo_toml/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub enum ManifestError {
#[error("{} found in {toml}", if name.is_empty() { "Empty dependency name".into() } else { format!("Invalid dependency name `{name}`") })]
InvalidDependencyName { toml: PathBuf, name: String },

#[error("Invalid directory path {directory} in {toml}: It must point to a subdirectory")]
InvalidDirectory { toml: PathBuf, directory: PathBuf },

/// Encountered error while downloading git repository.
#[error("{0}")]
GitError(String),
Expand Down
18 changes: 15 additions & 3 deletions crates/nargo_toml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,28 @@ struct PackageMetadata {
/// Enum representing the different types of ways to
/// supply a source for the dependency
enum DependencyConfig {
Github { git: String, tag: String },
Github { git: String, tag: String, directory: Option<String> },
Path { path: String },
}

impl DependencyConfig {
fn resolve_to_dependency(&self, pkg_root: &Path) -> Result<Dependency, ManifestError> {
let dep = match self {
Self::Github { git, tag } => {
Self::Github { git, tag, directory } => {
let dir_path = clone_git_repo(git, tag).map_err(ManifestError::GitError)?;
let toml_path = dir_path.join("Nargo.toml");
let project_path = if let Some(directory) = directory {
let internal_path = dir_path.join(directory).normalize();
if !internal_path.starts_with(&dir_path) {
return Err(ManifestError::InvalidDirectory {
toml: pkg_root.join("Nargo.toml"),
directory: directory.into(),
});
}
internal_path
} else {
dir_path
};
let toml_path = project_path.join("Nargo.toml");
let package = resolve_package_from_toml(&toml_path)?;
Dependency::Remote { package }
}
Expand Down