diff --git a/cargo-nextest/src/cargo_cli.rs b/cargo-nextest/src/cargo_cli.rs index 7a75ab35fdf..f83fb5da51a 100644 --- a/cargo-nextest/src/cargo_cli.rs +++ b/cargo-nextest/src/cargo_cli.rs @@ -6,6 +6,7 @@ use crate::output::OutputContext; use camino::{Utf8Path, Utf8PathBuf}; use clap::Args; +use guppy::graph::PackageGraph; use std::path::PathBuf; /// Options passed down to cargo. @@ -143,6 +144,19 @@ pub(crate) struct CargoOptions { unstable_flags: Vec, } +impl CargoOptions { + fn needs_default_members_warning(&self, graph: &PackageGraph) -> bool { + // If any package-related options are passed in, don't produce a warning. + if !self.packages.is_empty() || self.workspace || self.all { + return false; + } + + // TODO: figure out whether this will cause everything to be built. Factors to consider: + // * symlinks + // * exact behavior with nested directories + } +} + #[derive(Clone, Debug)] pub(crate) struct CargoCli<'a> { cargo_path: Utf8PathBuf, diff --git a/nextest-runner/src/cargo_toml.rs b/nextest-runner/src/cargo_toml.rs new file mode 100644 index 00000000000..57f9cad21a6 --- /dev/null +++ b/nextest-runner/src/cargo_toml.rs @@ -0,0 +1,49 @@ +// Copyright (c) The nextest Contributors +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Support for reading `Cargo.toml` files. +//! +//! This package contains logic to partially read and understand `Cargo.toml` files: just enough for +//! nextest's needs. + +use crate::errors::RootCargoTomlError; +use camino::{Utf8Path, Utf8PathBuf}; +use serde::Deserialize; + +/// Represents a workspace's root Cargo.toml. +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct RootCargoToml { + /// The workspace key. + pub workspace: RootCargoTomlWorkspace, +} + +impl RootCargoToml { + /// Reads the root Cargo.toml into this file. + pub fn read_file(path: &Utf8Path) -> Result { + let contents = + std::fs::read_to_string(&path).map_err(|error| RootCargoTomlError::ReadError { + path: path.to_owned(), + error, + })?; + + toml_edit::easy::from_str(&contents).map_err(|error| RootCargoTomlError::ParseError { + path: path.to_owned(), + error, + }) + } + + /// Returns true if the workspace has default members. + pub fn has_default_members(&self) -> bool { + self.workspace.default_members.is_some() + } +} + +/// The `[workspace]` section of a [`RootCargoToml`]. +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct RootCargoTomlWorkspace { + /// The default members of the workspace. + #[serde(default)] + pub default_members: Option>, +} diff --git a/nextest-runner/src/errors.rs b/nextest-runner/src/errors.rs index 4a52f5b0e53..e82e2c97437 100644 --- a/nextest-runner/src/errors.rs +++ b/nextest-runner/src/errors.rs @@ -863,6 +863,32 @@ pub enum CargoConfigError { }, } +/// An error occurred while parsing a root Cargo.toml. +#[derive(Debug, Error)] +pub enum RootCargoTomlError { + /// Error reading a file from disk. + #[error("failed to read workspace `{path}`")] + ReadError { + /// The path to the file. + path: Utf8PathBuf, + + /// The inner error. + #[source] + error: std::io::Error, + }, + + /// Error parsing the `Cargo.toml` file. + #[error("failed to parse workspace `{path}`")] + ParseError { + /// The path to the file. + path: Utf8PathBuf, + + /// The error that occurred trying to deserialize the file. + #[source] + error: toml_edit::easy::de::Error, + }, +} + /// The reason an invalid CLI config failed. /// /// Part of [`CargoConfigError::InvalidCliConfig`]. diff --git a/nextest-runner/src/lib.rs b/nextest-runner/src/lib.rs index bebe0945307..e72a4e083d3 100644 --- a/nextest-runner/src/lib.rs +++ b/nextest-runner/src/lib.rs @@ -10,6 +10,7 @@ //! post](https://sunshowers.io/posts/nextest-and-tokio/). pub mod cargo_config; +pub mod cargo_toml; pub mod config; #[cfg(feature = "experimental-tokio-console")] pub mod console;