feat(solc): add helper to checkout temp projects (#1581)
Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
parent
64ac7d01ab
commit
2f0dbad1fd
|
@ -16,6 +16,8 @@ use fs_extra::{dir, file};
|
|||
use std::{
|
||||
fmt,
|
||||
path::{Path, PathBuf},
|
||||
process,
|
||||
process::Command,
|
||||
};
|
||||
use tempfile::TempDir;
|
||||
|
||||
|
@ -407,6 +409,26 @@ impl TempProject<ConfigurableArtifacts> {
|
|||
Ok(project)
|
||||
}
|
||||
|
||||
/// Clones the given repo into a temp dir, initializes it recursively and configures it.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use ethers_solc::project_util::TempProject;
|
||||
/// # fn t() {
|
||||
/// let project = TempProject::checkout("transmissions11/solmate").unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn checkout(repo: impl AsRef<str>) -> Result<Self> {
|
||||
let tmp_dir = tempdir("tmp_checkout")?;
|
||||
clone_remote(&format!("https://github.com/{}", repo.as_ref()), tmp_dir.path())
|
||||
.map_err(|err| SolcIoError::new(err, tmp_dir.path()))?;
|
||||
let paths = ProjectPathsConfig::dapptools(tmp_dir.path())?;
|
||||
|
||||
let inner = Project::builder().paths(paths).build()?;
|
||||
Ok(Self::create_new(tmp_dir, inner)?)
|
||||
}
|
||||
|
||||
/// Create a new temporary project and populate it with mock files
|
||||
///
|
||||
/// ```no_run
|
||||
|
@ -507,6 +529,17 @@ pub fn copy_dir(source: impl AsRef<Path>, target_dir: impl AsRef<Path>) -> Resul
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Clones a remote repository into the specified directory.
|
||||
pub fn clone_remote(
|
||||
repo_url: &str,
|
||||
target_dir: impl AsRef<Path>,
|
||||
) -> std::io::Result<process::Output> {
|
||||
Command::new("git")
|
||||
.args(["clone", "--depth", "1", "--recursive", repo_url])
|
||||
.arg(target_dir.as_ref())
|
||||
.output()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -2129,6 +2129,15 @@ fn can_handle_conflicting_files() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_checkout_repo() {
|
||||
let project = TempProject::checkout("transmissions11/solmate").unwrap();
|
||||
|
||||
let compiled = project.compile().unwrap();
|
||||
assert!(!compiled.has_compiler_errors());
|
||||
let _artifacts = project.artifacts_snapshot().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_add_basic_contract_and_library() {
|
||||
let mut project = TempProject::<ConfigurableArtifacts>::dapptools().unwrap();
|
||||
|
|
Loading…
Reference in New Issue