From cf3339066b81076157ebde83551a2b2731f1ec76 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 13 Sep 2021 23:40:59 +0300 Subject: [PATCH] fix(solc): canonicalize custom paths --- ethers-core/src/utils/solc.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index 9c36e1ec..90acf224 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -103,6 +103,9 @@ impl Solc { /// Gets the ABI for the contracts pub fn build_raw(self) -> Result> { let path = self.solc_path.unwrap_or_else(|| PathBuf::from(SOLC)); + let path = std::fs::canonicalize(&path) + .unwrap_or_else(|_| panic!("cannot canonicalize path {:?}", path)); + let mut command = Command::new(&path); let version = Solc::version(Some(path)); @@ -227,12 +230,14 @@ impl Solc { /// /// # Panics /// - /// If `solc` is not in the user's $PATH + /// If `solc` is not found pub fn version(solc_path: Option) -> String { - let command_output = Command::new(solc_path.unwrap_or_else(|| PathBuf::from(SOLC))) + let solc_path = solc_path.unwrap_or_else(|| PathBuf::from(SOLC)); + let solc_path = std::fs::canonicalize(solc_path).unwrap(); + let command_output = Command::new(&solc_path) .arg("--version") .output() - .unwrap_or_else(|_| panic!("`{}` not in user's $PATH", SOLC)); + .unwrap_or_else(|_| panic!("`{:?}` not found", solc_path)); let version = command_output .stdout