Skip to content

Commit

Permalink
clean dependencies on update, clean remappings at update
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-eth committed Aug 8, 2023
1 parent 1568d8e commit ca8616a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 53 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ The full list of dependencies is available [here](./all_dependencies.toml).
- Error handling.
- Tests. (I know, I know...)
- Refactor the code. (lots of duplicated code).
- enable dependencies in the foundry toml file.
- skip downloading if dependency already downloaded
7 changes: 3 additions & 4 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
openzeppelin=dependencies/openzeppelin-v4.9.2
solady=dependencies/solady-v0.0.107
solady=dependencies/solady-v0.0.49
uniswap-v3-periphery=dependencies/uniswap-v3-periphery-v1.0.0
@openzeppelin=dependencies/@openzeppelin-v1.0.5
@openzeppelin=dependencies/@openzeppelin-v4.9.2
@solady=dependencies/@solady-v0.0.41
6 changes: 3 additions & 3 deletions soldeer.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


[dependencies]
"openzeppelin~v4.9.2" = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.9.2.zip"
"openzeppelin~v1.0.5" = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v1.0.5.zip"
"openzeppelin~v2.0.0-rc.4" = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v2.0.0-rc.4.zip"
"@openzeppelin~v4.9.2" = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.9.2.zip"
"@openzeppelin~v1.0.5" = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v1.0.5.zip"
"@solady~v0.0.41" = "https://github.com/Vectorized/solady/archive/refs/tags/v0.0.41.zip"

[remappings]
enabled = true
38 changes: 12 additions & 26 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,19 @@ fn update_foundry() {
File::create("remappings.txt").unwrap();
}
println!("Updating foundry...");
let contents = read_file_to_string(String::from("remappings.txt"));

let existing_remappings: Vec<String> = contents
.split("\n")
.map(|s| s.to_string())
.collect();
let mut new_remappings: String = String::new();
let dependencies: Vec<Dependency> = read_config(String::new());

let mut existing_remap: Vec<String> = Vec::new();
existing_remappings.iter().for_each(|remapping| {
let split: Vec<&str> = remapping.split("=").collect::<Vec<&str>>();
existing_remap.push(String::from(split[0]));
});

dependencies.iter().for_each(|dependency| {
let index = existing_remap.iter().position(|r| r == &dependency.name);
if index.is_none() {
println!("Adding a new remap {}", &dependency.name);
new_remappings.push_str(
&format!(
"{}=dependencies/{}-{}\n",
&dependency.name,
&dependency.name,
&dependency.version
)
);
}
println!("Adding a new remap {}", &dependency.name);
new_remappings.push_str(
&format!(
"{}=dependencies/{}-{}\n",
&dependency.name,
&dependency.name,
&dependency.version
)
);
});

if new_remappings.len() == 0 {
Expand All @@ -152,10 +137,11 @@ fn update_foundry() {
let mut file: std::fs::File = fs::OpenOptions
::new()
.write(true)
.append(true)
.truncate(true)
.append(false)
.open(Path::new("remappings.txt"))
.unwrap();

println!("New remappings: {}", &new_remappings);
match write!(file, "{}", &new_remappings) {
Ok(_) => {}
Err(e) => {
Expand Down
11 changes: 10 additions & 1 deletion src/dependency_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ use crate::utils::get_current_working_dir;

// TODOs:
// - needs to be downloaded in parallel
pub async fn download_dependencies(dependencies: &Vec<Dependency>) -> Result<(), DownloadError> {
pub async fn download_dependencies(
dependencies: &Vec<Dependency>,
clean: bool
) -> Result<(), DownloadError> {
if clean {
let dep_path = get_current_working_dir().unwrap().join("dependencies");
fs::remove_dir_all(&dep_path).unwrap();
fs::create_dir(&dep_path).unwrap();
}
for dependency in dependencies.iter() {
let file_name: String = format!("{}-{}.zip", dependency.name, dependency.version);
match download_dependency(&file_name, &dependency.url).await {
Expand Down Expand Up @@ -54,6 +62,7 @@ pub async fn download_dependency_remote(
let dependencies: Vec<Dependency> = read_config((&tmp_path).to_str().unwrap().to_string());
for dependency in dependencies.iter() {
if dependency.name == *dependency_name && dependency.version == *dependency_version {
println!("dependency url: {}", dependency.url);
match
download_dependency(
&format!("{}-{}.zip", &dependency_name, &dependency_version),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn main() {
remappings();
} else if command.0 == "update" || (command.0 == "install" && command.1 == "") {
let dependencies: Vec<Dependency> = read_config(String::new());
if download_dependencies(&dependencies).await.is_err() {
if download_dependencies(&dependencies, true).await.is_err() {
eprintln!("Error downloading dependencies");
exit(500);
}
Expand Down

0 comments on commit ca8616a

Please sign in to comment.