Skip to content

Commit

Permalink
feat(nargo): Support optional directory in git dependencies (#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Aug 25, 2023
1 parent 054642b commit 84fdc55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit 84fdc55

Please sign in to comment.