-
Notifications
You must be signed in to change notification settings - Fork 22
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
Hotfixes and extra tests before 0.3.0 #139
Conversation
…d if only the version was specified in the config. Resolved the fact that git revision was not always saved in the config, extra remappings tests
src/config.rs
Outdated
} else if value.is_inline_table() && // TODO: Hacky way of doing this, might need rewritten | ||
!value.as_inline_table().unwrap().contains_key("url") && | ||
!value.as_inline_table().unwrap().contains_key("git") | ||
{ | ||
// this function does not retrieve the url, only version | ||
return Ok(HttpDependency { | ||
name: name.clone(), | ||
version: match value.as_inline_table() { | ||
// we normalize to inline table | ||
Some(table) => { | ||
let version = table.get("version").unwrap().to_string(); | ||
version.replace("\"", "").trim().to_string() | ||
} | ||
None => { | ||
return Err(ConfigError::InvalidDependency(name)); | ||
} | ||
}, | ||
url: None, | ||
checksum: None, | ||
} | ||
.into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this and instead handle this case in the None
case of the last match statement line 537
match table.get("url").map(|v| v.as_str()) {
Some(None) => Err(ConfigError::InvalidField { field: "url".to_string(), dep: name }),
None => Ok(Dependency::Http(HttpDependency {
name: name.to_string(),
version,
url: None,
checksum: None,
})),
Some(Some(url)) => Ok(Dependency::Http(HttpDependency {
name: name.to_string(),
version,
url: Some(url.to_string()),
checksum: None,
})),
}
src/config.rs
Outdated
@@ -348,7 +355,7 @@ pub async fn remappings_txt( | |||
) -> Result<()> { | |||
let remappings_path = get_current_working_dir().join("remappings.txt"); | |||
if soldeer_config.remappings_regenerate { | |||
remove_file(&remappings_path).map_err(ConfigError::RemappingsError)?; | |||
let _ = remove_file(&remappings_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm interested to know why you ignore any error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because if the remapping does not exists then this should not revert. E.g. i set the regenerate = true first time, this will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this is not ideal, a check should be made to check whether the file exists prior to trying to remove it, and any error in removing it if it exists (e.g. if permissions don't allow the removal) should be raised appropriately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wanted to add the check here to see if the file exists but i think i moved to other stuff :D will do it before release.
src/lib.rs
Outdated
if !custom_url { | ||
let new_dep = match get_url_type(dependency.url().unwrap()) { | ||
UrlType::Git => Dependency::Git(GitDependency { | ||
name: dependency.name().to_string(), | ||
version: dependency.version().to_string(), | ||
git: "".to_string(), | ||
rev: Some(dependency.rev().unwrap().clone()), | ||
}), | ||
UrlType::Http => Dependency::Http(HttpDependency { | ||
name: dependency.name().to_string(), | ||
version: dependency.version().to_string(), | ||
url: None, | ||
checksum: None, | ||
}), | ||
}; | ||
add_to_config(&new_dep, &config_path).expect("add to config failed"); | ||
} else { | ||
add_to_config(&dependency, &config_path).expect("add to config failed"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit clunky. I would simply do the following (posting full function to avoid confusion):
async fn install_dependency(
mut dependency: Dependency,
regenerate_remappings: bool,
recursive_deps: bool,
) -> Result<(), SoldeerError> {
lock_check(&dependency, true)?;
let config_path = match get_config_path() {
Ok(file) => file,
Err(e) => {
cleanup_dependency(&dependency, true)?;
return Err(e.into());
}
};
let mut config = read_soldeer_config(Some(config_path.clone()))?;
if regenerate_remappings {
config.remappings_regenerate = regenerate_remappings;
}
if recursive_deps {
config.recursive_deps = recursive_deps;
}
let result = download_dependency(&dependency, false)
.await
.map_err(|e| SoldeerError::DownloadError { dep: dependency.to_string(), source: e })?;
match dependency {
Dependency::Http(ref mut dep) => {
add_to_config(&dep.clone().into(), &config_path)?;
dep.checksum = Some(result.hash);
dep.url = Some(result.url);
}
Dependency::Git(ref mut dep) => {
dep.rev = Some(result.hash);
add_to_config(&dependency, &config_path)?;
}
}
write_lock(&[dependency.clone()], LockWriteMode::Append)?;
if let Dependency::Http(dep) = &dependency {
if let Err(e) = unzip_dependency(dep) {
cleanup_dependency(&dependency, true)?;
return Err(SoldeerError::DownloadError { dep: dependency.to_string(), source: e });
}
}
janitor::healthcheck_dependency(&dependency)?;
janitor::cleanup_dependency(&dependency, false)?;
if config.recursive_deps {
if let Err(e) = install_subdependencies(&dependency) {
return Err(SoldeerError::DownloadError { dep: dependency.to_string(), source: e });
};
}
if config.remappings_generate {
if config_path.to_string_lossy().contains("foundry.toml") {
match config.remappings_location {
RemappingsLocation::Txt => {
remappings_txt(&RemappingsAction::Add(dependency), &config_path, &config)
.await?
}
RemappingsLocation::Config => {
remappings_foundry(&RemappingsAction::Add(dependency), &config_path, &config)
.await?
}
}
} else {
remappings_txt(&RemappingsAction::Add(dependency), &config_path, &config).await?;
}
}
Ok(())
}
Solved some hot fixes regarding the way the dependencies where handled if only the version was specified in the config. Resolved the fact that git revision was not always saved in the config, extra remappings tests