diff --git a/ethers-contract/ethers-contract-abigen/src/contract.rs b/ethers-contract/ethers-contract-abigen/src/contract.rs index 2d51cc5c..24730e5e 100644 --- a/ethers-contract/ethers-contract-abigen/src/contract.rs +++ b/ethers-contract/ethers-contract-abigen/src/contract.rs @@ -151,7 +151,8 @@ impl Context { /// Create a context from the code generation arguments. pub fn from_abigen(args: Abigen) -> Result { // get the actual ABI string - let abi_str = args.abi_source.get().context("failed to get ABI JSON")?; + let abi_str = + args.abi_source.get().map_err(|e| anyhow!("failed to get ABI JSON: {}", e))?; let mut abi_parser = AbiParser::default(); let (abi, human_readable): (Abi, _) = if let Ok(abi) = abi_parser.parse_str(&abi_str) { diff --git a/ethers-contract/ethers-contract-abigen/src/source.rs b/ethers-contract/ethers-contract-abigen/src/source.rs index 668154c5..01136c43 100644 --- a/ethers-contract/ethers-contract-abigen/src/source.rs +++ b/ethers-contract/ethers-contract-abigen/src/source.rs @@ -60,7 +60,7 @@ impl Source { if matches!(source.chars().next(), Some('[' | '{')) { return Ok(Source::String(source.to_owned())) } - let root = env::current_dir()?.canonicalize()?; + let root = env::var("CARGO_MANIFEST_DIR")?; Source::with_root(root, source) } @@ -72,6 +72,7 @@ impl Source { P: AsRef, S: AsRef, { + let source = source.as_ref(); let root = root.as_ref(); cfg_if! { if #[cfg(target_arch = "wasm32")] { @@ -87,10 +88,10 @@ impl Source { .map_err(|_| anyhow!("root path '{}' is not absolute", root.display()))?; } } - let url = base.join(source.as_ref())?; + let url = base.join(source)?; match url.scheme() { - "file" => Ok(Source::local(url.path().to_string())), + "file" => Ok(Source::local(source.to_string())), "http" | "https" => match url.host_str() { Some("etherscan.io") => Source::etherscan( url.path()