fix: use lib for parsing paths correctly in windows (#712)

This commit is contained in:
Georgios Konstantopoulos 2021-12-19 22:03:16 +02:00 committed by GitHub
parent 9c11f6cb7b
commit 8d95f3bf33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

7
Cargo.lock generated
View File

@ -957,6 +957,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "dunce"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
[[package]] [[package]]
name = "ecdsa" name = "ecdsa"
version = "0.12.4" version = "0.12.4"
@ -1341,6 +1347,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"colored", "colored",
"criterion", "criterion",
"dunce",
"ethers-core", "ethers-core",
"fs_extra", "fs_extra",
"futures-util", "futures-util",

View File

@ -34,6 +34,7 @@ tiny-keccak = { version = "2.0.2", default-features = false }
tempdir = { version = "0.3.7", optional = true } tempdir = { version = "0.3.7", optional = true }
fs_extra = { version = "1.2.0", optional = true } fs_extra = { version = "1.2.0", optional = true }
sha2 = { version = "0.9.8", default-features = false } sha2 = { version = "0.9.8", default-features = false }
dunce = "1.0.2"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
home = "0.5.3" home = "0.5.3"

View File

@ -104,7 +104,7 @@ pub enum PathStyle {
impl PathStyle { impl PathStyle {
pub fn paths(&self, root: impl AsRef<Path>) -> Result<ProjectPathsConfig> { pub fn paths(&self, root: impl AsRef<Path>) -> Result<ProjectPathsConfig> {
let root = root.as_ref(); let root = root.as_ref();
let root = std::fs::canonicalize(root).map_err(|err| SolcError::io(err, root))?; let root = dunce::canonicalize(root).map_err(|err| SolcError::io(err, root))?;
Ok(match self { Ok(match self {
PathStyle::Dapptools => ProjectPathsConfig::builder() PathStyle::Dapptools => ProjectPathsConfig::builder()
@ -215,7 +215,7 @@ impl ProjectPathsConfigBuilder {
.map(Ok) .map(Ok)
.unwrap_or_else(std::env::current_dir) .unwrap_or_else(std::env::current_dir)
.map_err(|err| SolcIoError::new(err, "."))?; .map_err(|err| SolcIoError::new(err, "."))?;
let root = std::fs::canonicalize(&root).map_err(|err| SolcIoError::new(err, &root))?; let root = dunce::canonicalize(&root).map_err(|err| SolcIoError::new(err, &root))?;
Ok(self.build_with_root(root)) Ok(self.build_with_root(root))
} }
} }
@ -484,8 +484,7 @@ impl<T: Into<PathBuf>> TryFrom<Vec<T>> for AllowedLibPaths {
.into_iter() .into_iter()
.map(|lib| { .map(|lib| {
let path: PathBuf = lib.into(); let path: PathBuf = lib.into();
let lib = let lib = dunce::canonicalize(&path).map_err(|err| SolcIoError::new(err, path))?;
std::fs::canonicalize(&path).map_err(|err| SolcIoError::new(err, path))?;
Ok(lib) Ok(lib)
}) })
.collect::<std::result::Result<Vec<_>, _>>()?; .collect::<std::result::Result<Vec<_>, _>>()?;

View File

@ -908,7 +908,7 @@ mod tests {
fn test_build_many_libs() { fn test_build_many_libs() {
use super::*; use super::*;
let root = std::fs::canonicalize("./test-data/test-contract-libs").unwrap(); let root = dunce::canonicalize("./test-data/test-contract-libs").unwrap();
let paths = ProjectPathsConfig::builder() let paths = ProjectPathsConfig::builder()
.root(&root) .root(&root)
@ -935,7 +935,7 @@ mod tests {
fn test_build_remappings() { fn test_build_remappings() {
use super::*; use super::*;
let root = std::fs::canonicalize("./test-data/test-contract-remappings").unwrap(); let root = dunce::canonicalize("./test-data/test-contract-remappings").unwrap();
let paths = ProjectPathsConfig::builder() let paths = ProjectPathsConfig::builder()
.root(&root) .root(&root)
.sources(root.join("src")) .sources(root.join("src"))