fix: docs.rs build (#2221)

* fix: docs.rs build

* fix: test
This commit is contained in:
DaniPopes 2023-03-05 21:16:40 +01:00 committed by GitHub
parent 69eb21da67
commit 86a9e7c3af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 30 deletions

View File

@ -1,4 +1,4 @@
# ethers-core
# ethers-contract
Type-safe abstractions for interacting with Ethereum smart contracts.

View File

@ -1,12 +1,10 @@
use crate::contract::ContractInstance;
use crate::ContractInstance;
pub use ethers_core::abi::AbiError;
use ethers_core::{
abi::{Abi, Detokenize, Error, Event, Function, FunctionExt, RawLog, Token, Tokenize},
types::{Address, Bytes, Selector, H256},
};
use ethers_providers::Middleware;
use std::{
borrow::Borrow,
collections::{BTreeMap, HashMap},

View File

@ -3,8 +3,9 @@
#![deny(unsafe_code)]
#![warn(missing_docs)]
mod contract;
pub use contract::{Contract, ContractInstance};
#[path = "contract.rs"]
mod _contract;
pub use _contract::{Contract, ContractInstance};
mod base;
pub use base::{decode_function_data, encode_function_data, AbiError, BaseContract};
@ -67,3 +68,32 @@ pub use once_cell::sync::Lazy;
#[cfg(feature = "eip712")]
pub use ethers_derive_eip712::*;
// For Abigen expansions in docs.rs builds.
#[doc(hidden)]
#[allow(unused_extern_crates)]
extern crate self as ethers_contract;
#[doc(hidden)]
#[allow(unused_extern_crates)]
#[cfg(docsrs)]
extern crate self as ethers;
#[doc(hidden)]
#[cfg(docsrs)]
pub mod core {
pub use ethers_core::*;
}
#[doc(hidden)]
#[cfg(docsrs)]
pub mod contract {
pub use crate::*;
}
#[doc(hidden)]
#[cfg(docsrs)]
pub mod providers {
pub use ethers_providers::*;
}

View File

@ -56,10 +56,13 @@ pub struct ProjectEnvironment {
}
impl ProjectEnvironment {
/// Creates a new instance using the given manifest dir and crate name.
pub fn new<T: Into<PathBuf>, U: Into<String>>(manifest_dir: T, crate_name: U) -> Self {
Self { manifest_dir: manifest_dir.into(), crate_name: Some(crate_name.into()) }
}
/// Creates a new instance using the the `CARGO_MANIFEST_DIR` and `CARGO_CRATE_NAME` environment
/// variables.
pub fn new_from_env() -> Option<Self> {
Some(Self {
manifest_dir: env::var_os("CARGO_MANIFEST_DIR")?.into(),
@ -90,29 +93,15 @@ impl ProjectEnvironment {
}
#[inline]
pub fn crate_names_from_metadata(&self) -> Option<CrateNames> {
fn crate_names_from_metadata(&self) -> Option<CrateNames> {
let metadata = MetadataCommand::new().current_dir(&self.manifest_dir).exec().ok()?;
let pkg = metadata.root_package()?;
// return ethers_* if the root package is an internal ethers crate since `ethers` is not
// available
let crate_is_root = self.is_crate_root();
if let Ok(current_pkg) = pkg.name.parse::<EthersCrate>() {
// replace `current_pkg`'s name with "crate"
let names =
EthersCrate::path_names()
.map(|(pkg, name)| {
if crate_is_root && pkg == current_pkg {
(pkg, "crate")
} else {
(pkg, name)
}
})
.collect();
return Some(names)
} /* else if pkg.name == "ethers" {
// should not happen (the root package the `ethers` workspace package itself)
} */
if pkg.name.parse::<EthersCrate>().is_ok() || pkg.name == "ethers" {
return Some(EthersCrate::path_names().collect())
}
let mut names: CrateNames = EthersCrate::ethers_path_names().collect();
for dep in pkg.dependencies.iter() {
@ -293,7 +282,7 @@ impl EthersCrate {
pub const fn ethers_path_name(self) -> &'static str {
match self {
// re-exported in ethers::contract
Self::EthersContractAbigen => "::ethers::contract", // partly
Self::EthersContractAbigen => "::ethers::contract", // partially
Self::EthersContractDerive => "::ethers::contract",
Self::EthersDeriveEip712 => "::ethers::contract",
@ -386,7 +375,7 @@ mod tests {
let krate = s.crate_name.as_ref().and_then(|x| x.parse::<EthersCrate>().ok());
let is_internal = krate.is_some();
let mut expected: CrateNames = match (is_internal, ethers) {
let expected: CrateNames = match (is_internal, ethers) {
// internal
(true, _) => EthersCrate::path_names().collect(),
@ -403,10 +392,6 @@ mod tests {
}
};
if is_internal {
expected.insert(krate.unwrap(), "crate");
}
// don't use assert for a better custom message
if names != expected {
// BTreeMap sorts the keys

View File

@ -83,6 +83,11 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms), allow(dead_code, unused_variables))))]
// For macro expansion
#[doc(hidden)]
#[allow(unused_extern_crates)]
extern crate self as ethers;
#[doc(inline)]
pub use ethers_addressbook as addressbook;
#[doc(inline)]