Skip to content

Commit

Permalink
simplify public API snapshots (#1114)
Browse files Browse the repository at this point in the history
- omit auto trait impls.
- omit blanket impls.
  • Loading branch information
OmarTawfik authored Oct 1, 2024
1 parent f764bb4 commit 7989648
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2,746 deletions.
25 changes: 19 additions & 6 deletions crates/infra/utils/src/cargo/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ use crate::paths::PathExtensions;

#[derive(Deserialize)]
pub struct WorkspaceManifest {
pub workspace: Workspace,
workspace: Workspace,
}

#[derive(Deserialize)]
pub struct Workspace {
pub package: WorkspacePackage,
pub dependencies: HashMap<String, Dependency>,
struct Workspace {
package: WorkspacePackage,
dependencies: HashMap<String, Dependency>,
}

#[derive(Deserialize)]
pub struct WorkspacePackage {
pub version: Version,
struct WorkspacePackage {
version: Version,
}

#[derive(Deserialize)]
Expand All @@ -40,4 +40,17 @@ impl WorkspaceManifest {
toml::from_str(&manifest_path.read_to_string()?)
.with_context(|| format!("Failed to deserialize manifest: {manifest_path:?}"))
}

pub fn version(&self) -> &Version {
&self.workspace.package.version
}

pub fn dependency(&self, dependency_name: impl AsRef<str>) -> Result<&Dependency> {
let dependency_name = dependency_name.as_ref();

self.workspace
.dependencies
.get(dependency_name)
.with_context(|| format!("Cannot find dependency '{dependency_name}' in workspace."))
}
}
6 changes: 5 additions & 1 deletion crates/infra/utils/src/cargo/public_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ mod public_api_snapshots {
.toolchain(env!("RUST_NIGHTLY_VERSION"))
.build()?;

let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json).build()?;
let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json)
.omit_auto_derived_impls(false)
.omit_auto_trait_impls(true)
.omit_blanket_impls(true)
.build()?;

let output_path = crate_dir.join("generated/public_api.txt");

Expand Down
19 changes: 4 additions & 15 deletions crates/infra/utils/src/cargo/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ impl CargoWorkspace {

let manifest = WorkspaceManifest::load()?;

let dependency = manifest
.workspace
.dependencies
.get(crate_name)
.with_context(|| format!("Cannot find dependency '{crate_name}' in workspace."))?;

let mut command = Command::new("cargo")
.args(["install", crate_name])
.flag("--locked");

let dependency = manifest.dependency(crate_name)?;

command = match dependency {
Dependency::Local { path, version } => command
.property("--path", path.unwrap_str())
Expand All @@ -54,15 +50,8 @@ impl CargoWorkspace {
}

pub fn locate_source_crate(crate_name: impl AsRef<str>) -> Result<PathBuf> {
let crate_name = crate_name.as_ref();

let manifest = WorkspaceManifest::load()?;

let dependency = manifest
.workspace
.dependencies
.get(crate_name)
.with_context(|| format!("Cannot find dependency '{crate_name}' in workspace."))?;
let dependency = manifest.dependency(crate_name)?;

match dependency {
Dependency::Local { path, version: _ } => Ok(Path::repo_path(path)),
Expand All @@ -76,7 +65,7 @@ impl CargoWorkspace {
}

pub fn local_version() -> Result<Version> {
Ok(WorkspaceManifest::load()?.workspace.package.version)
Ok(WorkspaceManifest::load()?.version().to_owned())
}

pub fn published_version(crate_name: impl AsRef<str>) -> Result<Version> {
Expand Down
151 changes: 0 additions & 151 deletions crates/metaslang/bindings/generated/public_api.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7989648

Please sign in to comment.