xtask: Add command for checking packages conform to certain standards (#15236)

This PR adds a new `xtask` command for checking that packages conform to
certain standards.

Still a work-in-progress, but right now it checks:

- If `[lints] workspace = true` is set
- If packages are using non-workspace dependencies

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-07-25 19:20:08 -04:00
committed by GitHub
parent 13693ff80f
commit f2060ccbe0
8 changed files with 136 additions and 22 deletions
+6 -14
View File
@@ -1,17 +1,9 @@
use std::fs;
use anyhow::{anyhow, Result};
use cargo_toml::{Manifest, Workspace};
use toml;
use anyhow::{Context, Result};
use cargo_metadata::{Metadata, MetadataCommand};
/// Returns the Cargo workspace.
pub fn load_workspace() -> Result<Workspace> {
let workspace_cargo_toml = fs::read_to_string("Cargo.toml")?;
let workspace_cargo_toml: Manifest = toml::from_str(&workspace_cargo_toml)?;
let workspace = workspace_cargo_toml
.workspace
.ok_or_else(|| anyhow!("top-level Cargo.toml is not a Cargo workspace"))?;
Ok(workspace)
pub fn load_workspace() -> Result<Metadata> {
MetadataCommand::new()
.exec()
.context("failed to load cargo metadata")
}